pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Matt A. <survivedsushi@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: returning inserted id
Date: Sat, 27 Aug 2005 01:14:55 -0500
Message-ID: <20050827061455.GA27248@wolff.to> (raw)
In-Reply-To: <20050821195627.8524.qmail@web35209.mail.mud.yahoo.com>
References: <20050821195627.8524.qmail@web35209.mail.mud.yahoo.com>

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



view thread (3+ messages)  latest in thread

Message-ID: <20050827061455.GA27248@wolff.to>
Permalink:  ../20050827061455.GA27248@wolff.to/
Also on:    postgresql.org/message-id/20050827061455.GA27248@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, survivedsushi@yahoo.com
  Subject: Re: returning inserted id
  In-Reply-To: <20050827061455.GA27248@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox