Re: returning inserted id

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: returning inserted id
Дата
Msg-id 20050827061455.GA27248@wolff.to
обсуждение исходный текст
Ответ на returning inserted id  ("Matt A." <survivedsushi@yahoo.com>)
Список pgsql-sql
On Sun, Aug 21, 2005 at 12:56:27 -0700, "Matt A." <survivedsushi@yahoo.com> wrote:
> this may have been asked a thousand times but i
> haven't found a standard answer...
> 
> 
> MSSQL
> set nocount on
> insert into (column) values (value)
> select identityid = @@identity
> set nocount off
> 
> 
> POSTGRESQL
> *cricket cricket* :)
> 
> 
> How is this done? By a trigger function? Or is it
> natively supported? Could I get an example on how to
> do it too? 

Use a serial type for the column and use currval to get the last value
assign to the corresponding sequence in the current session.
You probably want to read the documentation section on sequences.
http://candle.pha.pa.us/main/writings/pgsql/sgml/functions-sequence.html
http://candle.pha.pa.us/main/writings/pgsql/sgml/datatype.html#DATATYPE-INT


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

Предыдущее
От: Bernard Henry Voynet
Дата:
Сообщение: Unwanted nested dollar-quoted constants
Следующее
От: Chris Travers
Дата:
Сообщение: Re: booleans and nulls