From: Julio Leyva <jcleyva@hotmail.com>
To: pgsql-admin@postgresql.org
Subject: alter sequence in a function
Date: Tue, 3 Jul 2007 22:48:30 +0000
Message-ID: <BAY120-W180EC0773E6E0BC38E448DA10C0@phx.gbl> (raw)
Hi allI'm trying to create a function that alters a sequenceThis what I'm doingcreate or replace function updatesafe() returns integer AS $$DECLAREmaxseq integer;alterseq varchar(256);thumb integer;newvalue integer;BEGINnewvalue := 10010; maxseq := (select max(safeoperationid) from safeopencloseoperation); if (maxseq < 500) then return 3000; else execute 'ALTER sequence safeopencloseoperation_id_seq restart with ' || 'newvalue ' ; return 10000; END IF;END;$$ language plpgsqlIt compiles ok but when I call the functionit gives me this error ALTER sequence safeopencloseoperation_id_seq restart with newvalueCONTEXT: PL/pgSQL function "updatesafe" line 17 at execute statementLINE 1: ...equence safeopencloseoperation_id_seq restart with newvalueHowever when I change the alter sequence for thisALTER sequence safeopencloseoperation_id_seq restart with 10000 ;The function is ok,It means that we can't use such a utility inside a function? I mean replacing a value for a variable?Thanks for any suggestion=
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: jcleyva@hotmail.com
Subject: Re: alter sequence in a function
In-Reply-To: <BAY120-W180EC0773E6E0BC38E448DA10C0@phx.gbl>
References: <BAY120-W180EC0773E6E0BC38E448DA10C0@phx.gbl>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox