Re: OID Usage - Mailing list pgsql-general

From Tom Lane
Subject Re: OID Usage
Date
Msg-id 23604.1105716093@sss.pgh.pa.us
Whole thread Raw
In response to OID Usage  (Bo Lorentsen <bl@netgroup.dk>)
Responses Re: OID Usage  (Bo Lorentsen <bl@netgroup.dk>)
List pgsql-general
Bo Lorentsen <bl@netgroup.dk> writes:
> I use normal tabel ID (SERIAL and BIGSERIAL) all over the place for FK
> constaints, but I use OID in one special situation. When I insert a
> single row into a table, I like my low level code to be kompatible with
> mysql ( mysql_insert_id ), and fetch the row that I just inserted. This
> I do by using the PGoidValue function, and then select the row by the
> oid. This works quite nice .... but when a table get large, it become a
> big search (seq scan)  so I have added an index on oid's on the table
> where I use this trick, and this have helper :-)

The thing you have to worry about is the possibility of duplicate OIDs
once your DB has been running long enough for the OID counter to wrap
around (2^32 OIDs).  You should make sure that index is specifically
declared as UNIQUE, so that any attempt to insert a duplicate OID will
fail.  That might be enough for you, or you might want to add logic to
your application to retry automatically after such a failure.

            regards, tom lane

pgsql-general by date:

Previous
From: "Magnus Hagander"
Date:
Subject: Re: Problem running native windows Postgres 8 pg_dump etc on cygwin from bash
Next
From: laurie.burrow@powerconv.alstom.com
Date:
Subject: Re: Problem running native windows Postgres 8 pg_dump etc on