Re: INSERT ... RETURNING as Oracle

Поиск
Список
Период
Сортировка
От Brett W. McCoy
Тема Re: INSERT ... RETURNING as Oracle
Дата
Msg-id Pine.LNX.4.30.0103061052470.4095-100000@chapelperilous.net
обсуждение исходный текст
Ответ на INSERT ... RETURNING as Oracle  ("Sipos Andras" <s-andras@freemail.hu>)
Список 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 по дате отправления:

Предыдущее
От: Michael Fork
Дата:
Сообщение: Re: [SQL] Re: MySQLs Describe emulator!
Следующее
От: "Ian deSouza"
Дата:
Сообщение: Inserting values into a SERIAL field