| From: | "Brett W(dot) McCoy" <bmccoy(at)chapelperilous(dot)net> |
|---|---|
| To: | Sipos Andras <s-andras(at)freemail(dot)hu> |
| Cc: | <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: INSERT ... RETURNING as Oracle |
| Date: | 2001-03-06 16:02:42 |
| Message-ID: | Pine.LNX.4.30.0103061052470.4095-100000@chapelperilous.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | clayton cottingham | 2001-03-06 16:03:41 | Re: [SQL] MySQLs Describe emulator! |
| Previous Message | Michael Fork | 2001-03-06 15:38:43 | Re: [SQL] Re: MySQLs Describe emulator! |