From: | "Gregory Wood" <gregw(at)com-stock(dot)com> |
---|---|
To: | "HYip" <hualinyip(at)earthlink(dot)net> |
Cc: | "PostgreSQL-General" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: set transaction question |
Date: | 2001-05-18 14:23:19 |
Message-ID: | 006401c0dfa6$168d7b70$7889ffcc@comstock.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> Inside a transaction,
>
> I insert a row into the table, with an autonumber id.
> Now I want to return the id of the newly inserted row. How can I do
> that?
>
> It seems that the first insert statement is not committed, and so the
> second statement couldn't return the newly id.
SELECT currval('table_field_seq'); should work fine from inside a
transaction. The reason is that it retrieves the last value of the sequence
that was used by that backend, *not* the last value inserted into the table.
Therefore, it doesn't matter whether that value was committed or not.
Greg
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2001-05-18 14:34:40 | Re: CVS, initdb and catalog version |
Previous Message | J.H.M. Dassen Ray | 2001-05-18 14:15:19 | Re: Which OS to Use for Postgresql |