From: | Marc SCHAEFER <schaefer(at)alphanet(dot)ch> |
---|---|
To: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: libpq-fe: how to determine unique collision ? |
Date: | 2001-01-04 16:10:55 |
Message-ID: | Pine.LNX.3.96.1010104170552.8208A-100000@defian.alphanet.ch |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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!).
From | Date | Subject | |
---|---|---|---|
Next Message | Blake Crosby | 2001-01-04 16:23:44 | Time Zone Query |
Previous Message | Peter Eisentraut | 2001-01-04 16:10:09 | Re: libpq-fe: how to determine unique collision ? |