Is using the oid column in Postgresql as the primary key correct?

Asked

Viewed 236 times

2

Postgresql creates by default the Oids column (object identifiers), you can get it by doing.

 select oid, * from table

Problem that I have a table that has no primary key, and I want to map it in Fluent nhibernate (C#).

You better use the oid as a primary key or create a composite key?

1 answer

4


oid is a primary key. The question is whether to leave it as PK or use another one that stops it being used as PK.

It’s not simple to nail this, but you can obviously do it. It has some conditions that indicate its use, but not all. There are situations that do not have any problem in using it, it may be that you only need a primary key for a technical issue, ie your application does not care about it.

My opinion is the same one I found on the product mailing list, avoid using it, and if using make sure you understand all the implications of its use. I prefer to have full control over the primary key. I have never used oid. They have some disadvantages and few advantages, nothing serious, but I think it is enough for me. I prefer to use a serial even.

  • Has no referential integrity,
  • Transferring values externally can be a huge complication, it is not GUID,
  • is out of the standard, even specific Postgresql tools ignore it,
  • you have no control over it,
  • the question already shows that the use of * does not include her.

If you need a composite key then you have to use it, oid is no alternative to this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.