pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
using oids as primary keys and foreign keys
2+ messages / 2 participants
[nested] [flat]

* using oids as primary keys and foreign keys
@ 2004-11-08 22:36 David Bear <David.Bear@asu.edu>
  2004-11-08 23:29 ` Re: using oids as primary keys and foreign keys Michael Fuhr <mike@fuhr.org>
  0 siblings, 1 reply; 2+ messages in thread

From: David Bear @ 2004-11-08 22:36 UTC (permalink / raw)
  To: pgsql-admin

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'.

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'?


-- 
David Bear
phone: 	480-965-8257
fax: 	480-965-9189
College of Public Programs/ASU
Wilson Hall 232
Tempe, AZ 85287-0803
 "Beware the IP portfolio, everyone will be suspect of trespassing"



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: using oids as primary keys and foreign keys
  2004-11-08 22:36 using oids as primary keys and foreign keys David Bear <David.Bear@asu.edu>
@ 2004-11-08 23:29 ` Michael Fuhr <mike@fuhr.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Michael Fuhr @ 2004-11-08 23:29 UTC (permalink / raw)
  To: David Bear <David.Bear@asu.edu>; +Cc: 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/



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2004-11-08 23:29 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-11-08 22:36 using oids as primary keys and foreign keys David Bear <David.Bear@asu.edu>
2004-11-08 23:29 ` Michael Fuhr <mike@fuhr.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox