Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / Ingres Topics / July 2005

Tip: Looking for answers? Try searching our database.

sequence .nextval evaluating twice when used inside an INSERT cmd

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
morgan brickley - 22 Jul 2005 14:39 GMT
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.
Betty & Karl Schendel - 22 Jul 2005 14:46 GMT
>Call anyone spot the difference in the newsessionid value in these
>two examples ?
[quoted text clipped - 5 lines]
>if you use a sequence directly as a parameter it gets stepped twice.
>Not using it as a paramter directly solves the issue.

I think I saw an R3 bug-fix for something like this very recently.
It wouldn't be in the current posted builds yet.

Karl
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.