Re: how to create a sequence in a stored proc? - Mailing list pgsql-general

From J.V.
Subject Re: how to create a sequence in a stored proc?
Date
Msg-id 4F9ACAB5.1060900@gmail.com
Whole thread Raw
In response to Re: how to create a sequence in a stored proc?  (Merlin Moncure <mmoncure@gmail.com>)
Responses Re: how to create a sequence in a stored proc?
Re: how to create a sequence in a stored proc?
Re: how to create a sequence in a stored proc?
List pgsql-general
Right, I understand that fully, and have used SQL inside a stored proc
before, but in this case as I mentioned, I need to first do a select
from a table to get a max value, store that in a variable and then use
that variable in a create sequence sql statement.

so I need to construct a string that contains the create sequence
statement and execute that string, at least this is the way it is done
in Oracle.

I do not know how to use a variable in a create sequence statement in
PostgreSQL.

J.V.

On 4/27/2012 9:51 AM, Merlin Moncure wrote:
> On Fri, Apr 27, 2012 at 10:37 AM, J.V.<jvsrvcs@gmail.com>  wrote:
>> I need to create a sequence in a stored procedure.
>>
>> First I need to select a value from a table and set the sequence start value
>> to that value.
>>
>> We have a table that does not have a sequence on it, so I want to select the
>> max value, increment by one
>> and then start the sequence there.
>>
>> We have to do this on three databases, I have figured out how to do this in
>> Oracle (build a string and the EXECUTE IMMEDIATE<myString>, but have not
>> figured out how to do this with PostgreSQL.
> just about any sql is allowed from within a function, including CREATE
> SEQUENCE.  functions can even create functions and execute them.
>
> merlin
>

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: how to create a sequence in a stored proc?
Next
From: Filip Rembiałkowski
Date:
Subject: Re: empty role names in pg_dumpall output