pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nacef LABIDI <nacef.l@gmail.com>
To: Scott Marlowe <scott.marlowe@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Get the last inserted id
Date: Fri, 11 Apr 2008 19:43:56 +0200
Message-ID: <f16f7ea00804111043t67ddf4b8gc18a9780ecaa47eb@mail.gmail.com> (raw)
In-Reply-To: <dcc563d10804111041r42de8f4ftc64ac13ec709d273@mail.gmail.com>
References: <f16f7ea00804111023xc2072ddk796b1e0336c14aac@mail.gmail.com>
	<dcc563d10804111041r42de8f4ftc64ac13ec709d273@mail.gmail.com>

Nice idea but how can I use this in a frontend that I am developing using
Delphi and ADO objects ?

On Fri, Apr 11, 2008 at 7:41 PM, Scott Marlowe <scott.marlowe@gmail.com>
wrote:

>  On Fri, Apr 11, 2008 at 11:23 AM, Nacef LABIDI <nacef.l@gmail.com> wrote:
> > Hi all,
> >
> > I was wondering if postgres can return the last ID inserted for a table
> > which the primary key is autoincremented. I need to retrieve this ID in
> my
> > code to continue processing on that inserted row.
>
> smarlowe=# create table test (a serial primary key, b text);
> NOTICE:  CREATE TABLE will create implicit sequence "test_a_seq" for
> serial column "test.a"
> NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
> "test_pkey" for table "test"
> CREATE TABLE
> smarlowe=# insert into test (a,b) values (DEFAULT,'test') returning a;
>  a
> ---
>  1
> (1 row)
>
> INSERT 0 1
>
> Note that there are other ways of doing it, but I really like the
> returning clause.
>

view thread (5+ messages)  latest in thread

Message-ID: <f16f7ea00804111043t67ddf4b8gc18a9780ecaa47eb@mail.gmail.com>
Permalink:  ../f16f7ea00804111043t67ddf4b8gc18a9780ecaa47eb@mail.gmail.com/
Also on:    postgresql.org/message-id/f16f7ea00804111043t67ddf4b8gc18a9780ecaa47eb@mail.gmail.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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: nacef.l@gmail.com, scott.marlowe@gmail.com
  Subject: Re: Get the last inserted id
  In-Reply-To: <f16f7ea00804111043t67ddf4b8gc18a9780ecaa47eb@mail.gmail.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