Using oid column in PostgreSQL as primary key is correct?

2

PostgreSQL creates by default the OIDs (object identifiers) column, you can get it done.

 select oid, * from table

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

Is it better to use oid as the primary key or create a composite key?

    
asked by anonymous 18.11.2016 / 12:58

1 answer

4

oid is a primary key. The question is whether to leave it or use another one that makes it stop being used.

It's not simple to push this. You obviously can do it. It has some conditions that indicate its use. But not all. There are situations that have no problem using it, you may just need a primary key for a technical issue, that is, your application does not care about it.

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

  • Does not have referential integrity,
  • transferring values externally can be a huge complication, it is not GUID,
  • is non-standard, even PostgreSQL-specific tools ignore it,
  • You have no control over it,
  • The question already shows that * does not include it.

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

    
18.11.2016 / 13:26