"""hockey_function Revision ID: 6dbc7ce2fd71 Revises: bffb600877ea Create Date: 2019-05-02 13:19:50.328349 """ # revision identifiers, used by Alembic. revision = '6dbc7ce2fd71' down_revision = 'bffb600877ea' branch_labels = None depends_on = None from alembic import op import sqlalchemy as sa def upgrade(): op.execute(''' create or replace function hockey(vals double precision[], t1 integer, t2 integer, t3 integer DEFAULT '-1'::integer, t0 integer DEFAULT 1) returns double precision[] immutable strict language sql as $$ -- arr [ p ] - arr [ p - s ] f2, -- arr [ p - s ] - arr [ 1 ] f1, select array[ ((t1 - t0)::float*(vals[t2] - vals[t0]) - (t2 - t0)::float*(vals[t1] - vals[t0])) / nullif(vals[t0], 0), ((t1 - t0)::float*(vals[coalesce(nullif(t3, -1), array_length(vals, 1))] - vals[t0]) - (coalesce(nullif(t3, -1), array_length(vals, 1)) - t0)::float*(vals[t1] - vals[t0])) / nullif(vals[t0], 0), vals [ t0 ], vals [ t1 ], vals [ t2 ], vals [ coalesce(nullif(t3, -1), array_length(vals, 1)) ], t0::float, t1::float, t2::float, coalesce(nullif(t3, -1), array_length(vals, 1))::float ] $$; ''') def downgrade(): op.execute('''drop function hockey(double precision[], integer, integer, integer, integer)''')