Re: OID Usage

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bo Lorentsen <bl(at)netgroup(dot)dk>
Cc: "pgsql-general postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: OID Usage
Date: 2005-01-14 15:21:33
Message-ID: 23604.1105716093@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bo Lorentsen <bl(at)netgroup(dot)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

In response to

  • OID Usage at 2005-01-14 07:03:24 from Bo Lorentsen

Responses

Browse pgsql-general by date

  From Date Subject
Next Message laurie.burrow 2005-01-14 15:42:05 Re: Problem running native windows Postgres 8 pg_dump etc on
Previous Message Magnus Hagander 2005-01-14 14:51:16 Re: Problem running native windows Postgres 8 pg_dump etc on cygwin from bash