Re: Get the last inserted id

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: Get the last inserted id
Дата
Msg-id dcc563d10804111041r42de8f4ftc64ac13ec709d273@mail.gmail.com
обсуждение исходный текст
Ответ на Get the last inserted id  ("Nacef LABIDI" <nacef.l@gmail.com>)
Ответы Re: Get the last inserted id  ("Nacef LABIDI" <nacef.l@gmail.com>)
Список pgsql-sql
On Fri, Apr 11, 2008 at 11:23 AM, Nacef LABIDI <nacef.l@gmail.com> wrote:
> Hi all,
>
> I was wondering if postgres can return the last ID inserted for a table
> which the primary key is autoincremented. I need to retrieve this ID in my
> code to continue processing on that inserted row.

smarlowe=# create table test (a serial primary key, b text);
NOTICE:  CREATE TABLE will create implicit sequence "test_a_seq" for
serial column "test.a"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"test_pkey" for table "test"
CREATE TABLE
smarlowe=# insert into test (a,b) values (DEFAULT,'test') returning a;a
---1
(1 row)

INSERT 0 1

Note that there are other ways of doing it, but I really like the
returning clause.


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Nacef LABIDI"
Дата:
Сообщение: Get the last inserted id
Следующее
От: "Nacef LABIDI"
Дата:
Сообщение: Re: Get the last inserted id