Re: INSERT ... RETURNING as Oracle - Mailing list pgsql-general

From Brett W. McCoy
Subject Re: INSERT ... RETURNING as Oracle
Date
Msg-id Pine.LNX.4.30.0103061052470.4095-100000@chapelperilous.net
Whole thread Raw
In response to INSERT ... RETURNING as Oracle  ("Sipos Andras" <s-andras@freemail.hu>)
List pgsql-general
On Sat, 3 Mar 2001, Sipos Andras wrote:

> create table basket (
>   id   serial  NOT NULL PRIMARY KEY,
>   timestamp  timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
> );
>
> Can I how to make in one step insert into the table and get values of 'ID' ?
> I find similar solution then oracle's INSERT ... RETURNING.
>
> If first make INSERT, and after SELECT MAX(ID), then result is uncertain.

The serial type will implicitly create a sequence called basket_id_seq.
This row in your table has a default value of nextval('basket_id_seq').
If you call currval('basket_id_seq'), you will get the last value
generated by the sequence.  This is similar to using <sequence>.CURRVAL in
Oracle.

-- Brett
                http://www.chapelperilous.net/~bmccoy/
------------------------------------------------------------------------
I will always love the false image I had of you.


pgsql-general by date:

Previous
From: Michael Fork
Date:
Subject: Re: [SQL] Re: MySQLs Describe emulator!
Next
From: "Ian deSouza"
Date:
Subject: Inserting values into a SERIAL field