Re: libpq-fe: how to determine unique collision ?
От | Marc SCHAEFER |
---|---|
Тема | Re: libpq-fe: how to determine unique collision ? |
Дата | |
Msg-id | Pine.LNX.3.96.1010104170552.8208A-100000@defian.alphanet.ch обсуждение исходный текст |
Ответ на | Re: libpq-fe: how to determine unique collision ? (Peter Eisentraut <peter_e@gmx.net>) |
Ответы |
Re: libpq-fe: how to determine unique collision ?
|
Список | 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!).
В списке pgsql-general по дате отправления: