On Thu, 4 Jan 2001, Peter Eisentraut wrote:
> > - how do you get the OID of an insertion
>
> PQoidValue()
Thanks.
> > (the goal being to get
> > the value for the SERIAL type, in order to do something with it) ?
>
> Serial values and oids are not related.
No, that right, but do you have a better way of doing the following ? :)
INSERT INTO some_table(name, surname) VALUES('marc', 'moua');
-> creates OID 37492374
SELECT id FROM some_table WHERE oid = 37492374;
assuming
CREATE TABLE some_table(id SERIAL,
name VARCHAR(8),
surname VARCHAR(8),
UNIQUE(id), PRIMARY KEY(id));
What the above does is basically retrieving the id that was created.
Of course you could do:
BEGIN TRANSACTION
SELECT next_val('some_table_id_sequence');
INSERT INTO some_table(id, name, surname)
VALUES(current_val('some_table_id_sequence'), 'marc', 'moua');
END TRANSACTION
Which one do you recommend, are they really equivalent, and do you have a
better way ? (hint: name and surname are not unique).
thank you (and, PostgreSQL is great!).