4

I'm tring to create or update postgresql sequence with variable

If I put exact value when I create or update sequence, It works

like create sequence test minvalue 5 maxvalue 10 start 5;

but If I create some function which set min and maxvalue of sequence like

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;

It makes errors

I'm searching to find the way to put the variable when I create sequence

who knows the way? please help.

I just want to create sequence range

1 Answer 1

5

You might need to use dynamic SQL, for that kind if statement.

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

Don't forget to quote_ident() and quote_literal() as needed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.