Re: Use of nextval, currval - Mailing list pgsql-novice

From Josh Berkus
Subject Re: Use of nextval, currval
Date
Msg-id web-1817015@davinci.ethosmedia.com
Whole thread Raw
In response to Use of nextval, currval  (Matt Clark <mclark@rushe.aero.org>)
Responses Re: Use of nextval, currval
List pgsql-novice
Matt,

> 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.

This is correct.   Please post if you for some reason find them not
equal.

-Josh Berkus

pgsql-novice by date:

Previous
From: Matt Clark
Date:
Subject: Use of nextval, currval
Next
From: Ludwig Lim
Date:
Subject: Some questions on KEYS