| From: | "Nacef LABIDI" <nacef(dot)l(at)gmail(dot)com> |
|---|---|
| To: | "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Get the last inserted id |
| Date: | 2008-04-11 17:43:56 |
| Message-ID: | f16f7ea00804111043t67ddf4b8gc18a9780ecaa47eb@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
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(dot)marlowe(at)gmail(dot)com>
wrote:
> On Fri, Apr 11, 2008 at 11:23 AM, Nacef LABIDI <nacef(dot)l(at)gmail(dot)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.
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | A. Kretschmer | 2008-04-11 17:48:06 | Re: Get the last inserted id |
| Previous Message | Scott Marlowe | 2008-04-11 17:41:41 | Re: Get the last inserted id |