Skip site navigation (1) Skip section navigation (2)

Re: using oids as primary keys and foreign keys

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: David Bear <David(dot)Bear(at)asu(dot)edu>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: using oids as primary keys and foreign keys
Date: 2004-11-08 23:29:43
Message-ID: 20041108232943.GA70895@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-admin
On Mon, Nov 08, 2004 at 03:36:26PM -0700, David Bear wrote:
> I've looked in the archives searching on oid and 'access' (microsoft)
> to see how others have handled migration from data bases in ms-access
> to postgresql. MS access has an auto-inc field that is used frequently
> as a uniq id.  Seems the OID has the same function. Yet, I've seem
> parts of messages that say not to use the OID in that manner, but
> nothing seems 'definitive'.

The PostgreSQL documentation recommends against using OIDs as
primary keys:

http://www.postgresql.org/docs/7.4/static/datatype-oid.html

> Can I use an OID as a foreign key in another table? 
> 
> If not, what is the prefered method for replicating the auto-inc field
> that ms-access users are so fond of... a 'sequence'?

Yes, usually by creating a field of type SERIAL:

http://www.postgresql.org/docs/7.4/static/datatype.html#DATATYPE-SERIAL

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

pgsql-admin by date

Next:From: David BearDate: 2004-11-08 23:44:34
Subject: using psql copy command
Previous:From: Tom LaneDate: 2004-11-08 23:19:21
Subject: Re: Large transaction problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group