Re: How to use OIDs on tables......OR....a better solution? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: How to use OIDs on tables......OR....a better solution?
Date
Msg-id 20070227202312.GB12245@svana.org
Whole thread Raw
In response to How to use OIDs on tables......OR....a better solution?  ("Lenorovitz, Joel" <Joel.Lenorovitz@usap.gov>)
List pgsql-general
On Tue, Feb 27, 2007 at 12:57:51PM -0700, Lenorovitz, Joel wrote:
> The notes are attached to the records via a separate associative table
> that contains the 'note_id', the 'record_id' (both generated by a
> sequence), and the 'table_name' in which the record resides.  It's
> managable now, but my gut tells me that the association to the table
> should be handled by something besides just 'table_name' because if that
> were to be changed it would break things or potentially cause a lot of
> maintenance issues.  Is the OID a good bet for something to use as a
> unique and reliable table identifier?

It's possible the "regclass" type would be better. It is an OID but it
dumps and reads as the table name. And when you rename the table, it
gives the new name.

> If so, is there an elegant way to dereference the OID instead of using
> the alias (i.e. table name) to run a query against that table?
>    I want to do this:
>    > SELECT * FROM inventory_item;
>    But, the following does not work (where 16675 is the OID of tabled
> inventory_item):
>    > SELECT * FROM 16675;

No. You'll have to build the query dynamically. At I said, you can use
"::regclass::text" to get the table name, but you'll have the issue the
query seperately.

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

pgsql-general by date:

Previous
From: "Jimmy Zhang"
Date:
Subject: [ANN]VTD-XML 2.0
Next
From: Bruce Momjian
Date:
Subject: Re: grant on sequence and pg_restore/pg_dump problem