Re: returning inserted id

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: "Matt A(dot)" <survivedsushi(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: returning inserted id
Date: 2005-08-27 06:14:55
Message-ID: 20050827061455.GA27248@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sun, Aug 21, 2005 at 12:56:27 -0700,
"Matt A." <survivedsushi(at)yahoo(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Chris Travers 2005-08-27 06:38:09 Re: booleans and nulls
Previous Message Chris Mungall 2005-08-27 00:08:25 Common patterns for 'store' functions