sequence and stored procedure

Started by Renaud Tthonnartabout 25 years ago3 messagesgeneral
Jump to latest
#1Renaud Tthonnart
thonnart@amwdb.u-strasbg.fr

How can I use sequences in a stored procedure written with pl/pgsql?

Thanks in advance!
Renaud THONNART

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Renaud Tthonnart (#1)
Re: sequence and stored procedure

On Wed, 21 Feb 2001, Renaud Tthonnart wrote:

How can I use sequences in a stored procedure written with pl/pgsql?

What exactly are you trying to do? Pretty much you can call the
sequence functions you want to use on the sequence name you
want (you have to double the quotes around the name since it's
inside the quoted text of the function.

create function foo() returns opaque as
'
begin
NEW.y:=nextval(''seqseq'');
return NEW;
end;' language 'plpgsql';

create trigger footrig before insert or update on testfoo for
each row execute procedure foo();

#3Renaud Tthonnart
thonnart@amwdb.u-strasbg.fr
In reply to: Stephan Szabo (#2)
Re: sequence and stored procedure

Stephan Szabo wrote:

On Wed, 21 Feb 2001, Renaud Tthonnart wrote:

How can I use sequences in a stored procedure written with pl/pgsql?

What exactly are you trying to do? Pretty much you can call the
sequence functions you want to use on the sequence name you
want (you have to double the quotes around the name since it's
inside the quoted text of the function.

create function foo() returns opaque as
'
begin
NEW.y:=nextval(''seqseq'');
return NEW;
end;' language 'plpgsql';

create trigger footrig before insert or update on testfoo for
each row execute procedure foo();

Thank for your answer! That will help me !
Renaud THONNART