From: | Matt Clark <mclark(at)rushe(dot)aero(dot)org> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Use of nextval, currval |
Date: | 2002-11-07 23:15:56 |
Message-ID: | 200211072315.gA7NFuF15378@rushe.aero.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
I'm attempting to convert a code which uses Oracle to Postgres.
I am concerned about a couple of points in the SQL, which I should be able to do
in Postgres.
Say I have defined a sequence DataId;
The Oracle uses the sequence as follows:
insert into TABLE (id1,.......,id2)
values (DataId.NextVal,......,DataId.Currval);
I believe that I can replace this in Postgres with:
insert into TABLE (id1,.......,id2)
values (nextval('DataId'),.....,currval('DataId');
What I think is expected is that the values of id1 and id2 will be equal.
I have been told that Oracle will guarantee this; will that be assumption be
true for Postgres, also? (My concern is that, with multiple/many users of the
same database, there may be instances where DataId increments before the currval
happens, such that it's possible that id1 != id2, above.)
Is there a simple way to write the SQL such that I can only use nextval once,
keeping its value for both id1 and id2? (I have no idea why the values are
duplicated.....)
For that matter, is that a realistic assumption for Oracle's treatment of
sequences?
Thanks,
Matt
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2002-11-08 00:53:32 | Re: Use of nextval, currval |
Previous Message | Michael Paesold | 2002-11-07 18:15:40 | Re: enforcing alphabetic/numeric content in "char" column |