pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joshua D. Drake <jd@commandprompt.com>
To: josh@segrestfarms.com <josh@segrestfarms.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: SQL Help - Obtaining ID of record INSERTED
Date: Tue, 16 Aug 2005 15:08:47 -0700
Message-ID: <430263EF.6000302@commandprompt.com> (raw)
In-Reply-To: <430255F0.7060500@segrestfarms.com>
References: <430255F0.7060500@segrestfarms.com>

josh@segrestfarms.com wrote:
> Greetings.
> 
> INSERT INTO
>    orderstemp (customerid,datecreated)
> VALUES
>    ('5443','8/16/2005 12:00PM')
> 
> The table orderstemp has a unique identifier field, orderid (of type 
> SERIAL).
> 
> How can I obtain the orderid of the record inserted in the INSERT INTO 
> statement in postgresql?
> 
> MSSQL does it like this:
> 
> INSERT INTO
>    orderstemp (customerid,datecreated)
> VALUES
>    ('5443','8/16/2005 12:00PM')
> SELECT @@identity as orderid

If you are in the same session you can do:

select currval('sequencename_of_orderid');

> 
> but this doens't work in postgresql.
> 
> Any ideas?  Thanks in advance.
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that your
>       message can get through to the mailing list cleanly


-- 
Your PostgreSQL solutions company - Command Prompt, Inc. 1.800.492.2240
PostgreSQL Replication, Consulting, Custom Programming, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, plPerlNG - http://www.commandprompt.com/



view thread (9+ messages)  latest in thread

Message-ID: <430263EF.6000302@commandprompt.com>
Permalink:  ../430263EF.6000302@commandprompt.com/
Also on:    postgresql.org/message-id/430263EF.6000302@commandprompt.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: jd@commandprompt.com, josh@segrestfarms.com
  Subject: Re: SQL Help - Obtaining ID of record INSERTED
  In-Reply-To: <430263EF.6000302@commandprompt.com>
  References: <430255F0.7060500@segrestfarms.com> <430263EF.6000302@commandprompt.com>

* 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