August 15th, 2000, 07:46 AM
Join Date: Aug 2000
Location: Zhitomir, Ukraine
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks a lot for your advice.
But OID is not exactly what I need. I need to get the value of a "serial" field. It is used to link tables on insert.
I have another idea about it. I think it's possible to use a single sequence for all serial fields in all tables (defining the default value "nextval(seq)" for these fields explicitly). Then it must be possible to get the last sequence value with a single "select":
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
CREATE SEQUENCE only_seq;
CREATE TABLE table1
(table1_id INT4 DEFAULT nextval('only_seq') PRIMARY KEY,
table1_data INTEGER DEFAULT 0);
CREATE TABLE table2
(table2_id INT4 DEFAULT nextval('only_seq') PRIMARY KEY,
table2_data INTEGER DEFAULT 0);
-- ... here go some inserts or anything else ...
-- Now, to get the latest sequence number:
-- Looks quite easy!
I haven't checked this code yet, but I think it should work. I'm not sure it is good to use a single sequence for all tables, but it seems to be better than using OID for linking or "selecting smth where OID=last_oid".
If someone else is interested in this problem, please tell me what solution is better. Or, maybe, you can invent something completely different?
[This message has been edited by valichek (edited August 15, 2000).]