Re: libpq-fe: how to determine unique collision ? - Mailing list pgsql-general

From Marc SCHAEFER
Subject Re: libpq-fe: how to determine unique collision ?
Date
Msg-id Pine.LNX.3.96.1010104170552.8208A-100000@defian.alphanet.ch
Whole thread Raw
In response to Re: libpq-fe: how to determine unique collision ?  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: libpq-fe: how to determine unique collision ?  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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 by date:

Previous
From: Marco Catunda
Date:
Subject: Doesn't use index, why?
Next
From: Blake Crosby
Date:
Subject: Time Zone Query