unique ID across all columns

Started by fkater@googlemail.comalmost 19 years ago3 messagesgeneral
Jump to latest
#1fkater@googlemail.com
fkater@googlemail.com

Hi,

I need a unique ID across all columns I create. Is it o.k. to
achive this by combining pg_attribute.attnum of a column together with
the OID of the table the column is in?

While the table's OID should be unique according to the manual, I have
found no hints about the uniqueness of attnum -- I removed and added
some columns and it seems that already used values are not used again.

Felix

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: fkater@googlemail.com (#1)
Re: unique ID across all columns

Felix Kater wrote:

Hi,

I need a unique ID across all columns I create. Is it o.k. to
achive this by combining pg_attribute.attnum of a column together with
the OID of the table the column is in?

While the table's OID should be unique according to the manual, I have
found no hints about the uniqueness of attnum -- I removed and added
some columns and it seems that already used values are not used again.

Yes, the table OID is unique, and pg_attribute.attnum is unique as well.
They are not reused, not even when columns are dropped.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#2)
Re: unique ID across all columns

Alvaro Herrera <alvherre@commandprompt.com> writes:

Felix Kater wrote:

I need a unique ID across all columns I create. Is it o.k. to
achive this by combining pg_attribute.attnum of a column together with
the OID of the table the column is in?

Yes, the table OID is unique, and pg_attribute.attnum is unique as well.
They are not reused, not even when columns are dropped.

The OID could be re-used after the table is dropped, though. It's not
clear whether Felix needs uniqueness across time or just at any one
instant.

regards, tom lane