From: Pham, Thinh <tpham@mail.priority.net>
To: 'pgsql-sql@postgresql.org' <pgsql-sql@postgresql.org>
Subject: Getting primary key from insert statement
Date: Wed, 2 Jun 1999 16:46:28 -0500
Message-ID: <551413BBBB03D111BF880060B01AACCE0B38FA@home.priority.net> (raw)
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
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tpham@mail.priority.net
Subject: Re: Getting primary key from insert statement
In-Reply-To: <551413BBBB03D111BF880060B01AACCE0B38FA@home.priority.net>
References: <551413BBBB03D111BF880060B01AACCE0B38FA@home.priority.net>
* 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