From: | "Pham, Thinh" <tpham(at)mail(dot)priority(dot)net> |
---|---|
To: | "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Getting primary key from insert statement |
Date: | 1999-06-02 21:46:28 |
Message-ID: | 551413BBBB03D111BF880060B01AACCE0B38FA@home.priority.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi, is there a way you can get back the primary key (serialized) from an
insert you just do on a table. For example i have a table called "order" and
i want to get the pid of that record so i can use it in the "orderdetail"
table. It would be nice if that same insert statement could also return the
pid.
Table structure:
create table order (pid serial, orddate date);
create table orderdetail (pid serial, orderpid int, name varchar(50));
Insert statement:
insert into order (date) values ('6/2/1999')
order table
pid | orddate
----------------
1 | 6/2/1999
orderdetail table
pid | orderpid | name
--------------------------
1 | 1 | pencil
2 | 1 | pen
I know there must be a way, but i just couldn't find it in either the pgsql
docs or faq. Thanks in advance,
Thinh
From | Date | Subject | |
---|---|---|---|
Next Message | Mark Wright | 1999-06-02 22:18:19 | Are PL/pgSQL calls atomic? |
Previous Message | Jason Earl | 1999-06-02 21:08:33 | Re: [SQL] OUTER JOINs in PostgreSQL |