Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux