Re: Getting Primary Key Value After Insert

Поиск
Список
Период
Сортировка
От Adam
Тема Re: Getting Primary Key Value After Insert
Дата
Msg-id 004301c6a314$9ad98d60$0200a8c0@PANASONIULSWMR
обсуждение исходный текст
Ответ на Re: Long term database archival  (Richard Broersma Jr <rabroersma@yahoo.com>)
Ответы Re: Getting Primary Key Value After Insert  (Richard Broersma Jr <rabroersma@yahoo.com>)
Список pgsql-general
I think I found the answer, you use the CURRVAL() function.

Just to cover all the bases, consider this scenario in chronological order:
1.  You insert data and the primary key is set to 20.
2.  Someone else inserts data and the next key is set to 21.
3.  If you call currval() will it return 20?  I would think it does.


----- Original Message -----
To: "Postgres general mailing list" <pgsql-general@postgresql.org>
Sent: Saturday, July 08, 2006 11:28 PM
Subject: [GENERAL] Getting Primary Key Value After Insert


> I'm inserting data into two tables, the second table has a forigen key
> that points to the primary key of the first table.
>
> After I insert a row into the first table, I need to take the primary key
> value created in "SERIAL" column and store it so I can insert it as the
> forigen key value on the second table.
>
> What is the best way to get the value of the primary key ( SERIAL data
> type ) of the row I inserted?
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>


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

Предыдущее
От: "Adam"
Дата:
Сообщение: Getting Primary Key Value After Insert
Следующее
От: Richard Broersma Jr
Дата:
Сообщение: Re: Getting Primary Key Value After Insert