Re: CREATE SEQUENCE fails in plpgsql function - Mailing list pgsql-sql

From Tom Lane
Subject Re: CREATE SEQUENCE fails in plpgsql function
Date
Msg-id 2454.1057066433@sss.pgh.pa.us
Whole thread Raw
In response to CREATE SEQUENCE fails in plpgsql function  (Erik Erkelens <erik_erkelens@yahoo.com>)
Responses Re: CREATE SEQUENCE fails in plpgsql function  (Rod Taylor <rbt@rbt.ca>)
List pgsql-sql
Erik Erkelens <erik_erkelens@yahoo.com> writes:
>     DECLARE 
>         new_max_records ALIAS FOR $1;
>     BEGIN
>         CREATE SEQUENCE my_sequence MAXVALUE new_max_records CYCLE;

> ERROR:  parser: parse error at or near "$1" at character 39

You'll need to use EXECUTE to construct and execute that CREATE
SEQUENCE.  Utility statements generally don't accept runtime parameters,
which is what the plpgsql variable looks like to the main parser.

> Also, if there is a better mechanism to implement
> this, I'm all ears...

There's an ALTER SEQUENCE command in CVS tip, though I'm not sure
I trust it in concurrent-usage scenarios :-(
        regards, tom lane


pgsql-sql by date:

Previous
From: Rado Petrik
Date:
Subject: Failed to initialize lc_messages to ''
Next
From: Robert Treat
Date:
Subject: Re: help with "delete joins"