Re: returning inserted id - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: returning inserted id
Date
Msg-id 20050827061455.GA27248@wolff.to
Whole thread Raw
In response to returning inserted id  ("Matt A." <survivedsushi@yahoo.com>)
List 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 by date:

Previous
From: Bernard Henry Voynet
Date:
Subject: Unwanted nested dollar-quoted constants
Next
From: Chris Travers
Date:
Subject: Re: booleans and nulls