From: | Ernest Kim <krazykid(at)cs(dot)bu(dot)edu> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Value of serial data type after insert. |
Date: | 2004-11-10 19:34:22 |
Message-ID: | 20041110193422.GA1531@cs.bu.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I was wondering if there was a way to get the value of serial data
type after an insert. For example, you have the following table:
create table my_names (
id serial unique,
name varchar(10)
);
And then you do the following:
insert into my_names values ('Ernie');
How do I get the value of the "id" column after the insert command? I
want to make sure that I avoid race conditions, for example:
User A: insert into my_names values ('Ernie');
User B: insert into my_names values ('Bob');
User A: select last_value from my_names_id_seq;
User B: select last_value from my_names_id_seq;
Both user A and B end up with the same returned value after the select
command.
Note this would be coded through PHP if this helps at all. Thanks.
-Ernie
From | Date | Subject | |
---|---|---|---|
Next Message | Sídar LC | 2004-11-10 20:48:02 | Re: [ADMIN] Where is postgresql?? |
Previous Message | William Yu | 2004-11-10 19:32:32 | Re: Important Info on comp.databases.postgresql.general |