Re: Use of OIDS as primary keys

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Alan Wayne <alanjwayne(at)yahoo(dot)com>
Cc: Jean-Michel POURE <jm(dot)poure(at)freesurf(dot)fr>, pgsql-general(at)postgresql(dot)org
Subject: Re: Use of OIDS as primary keys
Date: 2002-05-13 14:24:25
Message-ID: 20020514002425.A7052@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, May 11, 2002 at 10:56:00PM -0700, Alan Wayne wrote:
> Hi!
>
> I'm wondering how I can use the system generated OIDS
> as primary keys. Does postgre automatically fill in
> the system generated oid when a field of type oid is
> created as the primary key? And if so, how do I read
> it back on a record just created so I can use it as a
> secondary key in another table? And lastly, is it even
> a good idea to use the oid as keys at all when I'm
> going to eventually migrate the data from one machine
> to another?

I'm sure this is mentioned in the FAQ somewhere but in postgres every tuple
has an OID (except in 7.2 where you can specify that you don't want them for
certain tables). It's not output by default but you can show it using
"select *,oid from table;".

Cons of using it as primary key:
- It's not guarenteed to be unique
- Forget the -o switch on your dump and your DB is hosed
- Moving to another machine can become a pain

Pros of using it as a primary key:
- INSERT tells you the oid it just inserted

Just use a sequence/serial. It's far clearer and more reliable.

HTH,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Canada, Mexico, and Australia form the Axis of Nations That
> Are Actually Quite Nice But Secretly Have Nasty Thoughts About America

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Lockhart 2002-05-13 14:42:35 Re: Why is ALLOW_ABSOLUTE_DBPATHS unsafe?
Previous Message Jan Wieck 2002-05-13 13:37:53 Re: Trigger performance