Re: How to use OIDs on tables......OR....a better solution?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: "Lenorovitz, Joel" <Joel(dot)Lenorovitz(at)usap(dot)gov>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to use OIDs on tables......OR....a better solution?
Date: 2007-02-27 20:23:12
Message-ID: 20070227202312.GB12245@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2007-02-27 21:08:41 Re: grant on sequence and pg_restore/pg_dump problem
Previous Message Jimmy Zhang 2007-02-27 20:13:21 [ANN]VTD-XML 2.0