Re: OID's - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: OID's
Date
Msg-id 20050121170438.GA56550@winnie.fuhr.org
Whole thread Raw
In response to Re: OID's  (Mihail Nasedkin <m.nasedkin.perm@mail.ru>)
Responses Re: OID's
List pgsql-sql
On Fri, Jan 21, 2005 at 11:17:34AM +0500, Mihail Nasedkin wrote:

> I have already read about "System Columns" of the PostgreSQL documentation.
> In the table "pg_catalog.pg_attribute" column "attrelid" contain
> only "system OID's" but not OID's from records of the user tables.
> 
> But I would like to use OID's of all records of the all my tables.
>                                  ^^^                ^^^

If you want to do that then you'll need to know which tables have
OIDs.  If you just want rows then you could query pg_class and
filter on the relhasoids column, but if you also want things like
large objects then you might need to query pg_attribute and look
for all columns having an "oid" type.  It sounds like you're not
interested in the latter, however.

> I try to use rules on INSERT action of my tables to store last insert
> oid, but at the moment of the INSERT row into table OID value
> inaccessible (unknown).

A row's OID should be visible in an AFTER trigger.

> >> I would like use some SQL queries with the all OID's.
> 
> MF> To what end?  Are you aware that PostgreSQL allows tables to be
> MF> created without OIDs?
>
> Yes, of course, but in my case I create tables with OID and then want use
> OID of all records of the all tables as one column in some query.

Are you aware that OIDs aren't guaranteed to be unique due to
wraparound?  If you have a UNIQUE constraint on each table's oid
column then the combination of (tableoid, oid) might serve your
needs.

> I think what system of OID's is very useful for application!

Assigning row IDs from a common sequence could serve the same
purpose, and since sequences are 64 bits you wouldn't be as subject
to a wraparound problem (OIDs are 32 bits).

> MF> What problem are you trying to solve?
>
> For example, I want to fetching all rows of the several tables in one
> query by means of LEFT JOIN, but not use UNION operator.

Again, what problem are you trying to solve?  Using OIDs might not
be the best solution, and if we knew what you're trying to do then
we might be able to suggest alternatives.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


pgsql-sql by date:

Previous
From: "Joel Fradkin"
Date:
Subject: Re: still having pg_user error
Next
From: Richard Huxton
Date:
Subject: Re: OID's