Re: using oids as primary keys and foreign keys

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: using oids as primary keys and foreign keys
Дата
Msg-id 20041108232943.GA70895@winnie.fuhr.org
обсуждение исходный текст
Ответ на using oids as primary keys and foreign keys  (David Bear <David.Bear@asu.edu>)
Список 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/

В списке pgsql-admin по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Large transaction problem
Следующее
От: David Bear
Дата:
Сообщение: using psql copy command