How to create or update a postgresql sequence with a variable

I am trying to create or update a postgresql sequence with a variable

If I set the exact value when creating or updating a sequence, it works

like create sequence test minvalue 5 maxvalue 10 start 5;

but if I create some function that sets the min and maxvalue sequences, for example

CREATE OR REPLACE FUNCTION test(bigint, bigint)
RETURNS void AS
$BODY$
BEGIN
    create sequence test minvalue $1 maxvalue $2 start $1;
END;
$BODY$
    LANGUAGE plpgsql VOLATILE
    COST 100;

Makes mistakes

I am looking to find a way to put a variable when creating a sequence

who knows the way? please, help.

I just want to create a range of sequence

+4
source share
1 answer

You may need to use dynamic SQL for this kind of if.

http://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

quote_ident() quote_literal() .

+5

All Articles