Re: CREATE SEQUENCE fails in plpgsql function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Erik Erkelens <erik_erkelens(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: CREATE SEQUENCE fails in plpgsql function
Date: 2003-07-01 13:33:53
Message-ID: 2454.1057066433@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Erik Erkelens <erik_erkelens(at)yahoo(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Robert Treat 2003-07-01 13:43:07 Re: help with "delete joins"
Previous Message Rado Petrik 2003-07-01 13:11:21 Failed to initialize lc_messages to ''