sequence .nextval evaluating twice when used inside an INSERT cmd
- From: morgan brickley <morgan@xxxxxxxxxxxxx>
- Date: Fri, 22 Jul 2005 14:42:13 +0100
Call anyone spot the difference in the newsessionid value in these two examples ?
#1 : create procedure MM_createSessionEntry ( ... ) as declare newsessionid bigint not null not default ; begin INSERT INTO my_table (entryID, ... ) VALUES (entryidkey.nextval, ...;
newsessionid = entryidkey.currval; return newsessionid;
#2 :
create procedure MM_createSessionEntry ( ... ) as declare newsessionid bigint not null not default ; begin newsessionid = entryidkey.nextval; INSERT INTO my_table (entryID, ... ) VALUES (newsessionid , ...;
return newsessionid;
Ok, here's the spoiler -
In the first the newsessionid being called twice whereas in the second it gets called once (the expected behaviour). It seems that if you use a sequence directly as a parameter it gets stepped twice. Not using it as a paramter directly solves the issue. Coming from a pure programming background (ie. non-DB) I can't see why this is.
Morgan. .
- Follow-Ups:
- Re: [Info-ingres] sequence .nextval evaluating twice when used inside an INSERT cmd
- From: Betty & Karl Schendel
- Re: [Info-ingres] sequence .nextval evaluating twice when used inside an INSERT cmd
- Prev by Date: Re: [Info-ingres] session tenporary tables and STAR ddbs
- Next by Date: Re: [Info-ingres] sequence .nextval evaluating twice when used inside an INSERT cmd
- Previous by thread: [Info-ingres] iiudadt_register examples required
- Next by thread: Re: [Info-ingres] sequence .nextval evaluating twice when used inside an INSERT cmd
- Index(es):