Thus spake Pham, Thinh
> 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);
You realize that order is a keyword, right?
> Insert statement:
> insert into order (date) values ('6/2/1999')
Assuming you change order to something else, the insert returns the OID
of the record just added. In psql this appears as something like this.
INSERT 36448 1
So, just read back the record.
SELECT pid FROM table WHERE OID = 36448;
The various interfaces give you methods to get this value back. Read the
docs for whichever interface you are using.
--
D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.