How to identify the class of a record

Started by Andre Fortinover 25 years ago2 messagesgeneral
Jump to latest
#1Andre Fortin
andrefor@axionet.com

Hi!,

Here is a scenario. The database contains 3 tables: the parent table is
Equipment with tables Computers and Monitors inheriting from it.

CREATE TABLE Equipment (...);
CREATE TABLE Computers (...) INHERITS (Equipment);
CREATE TABLE Monitors (...) INHERITS (Equipment);

When doing a SELECT on the parent with the asterisk suffix syntax, we
get rows from Computer and Monitor.

SELECT * from Equipment*;

Is there a way to know from which table each row in the returned record
set belongs to, as you can do with OO languages. If this is possible,
could you point where more information could be located on this type of
design when working with Postgres.

Thanks,

-- Andre

#2Peter Eisentraut
peter_e@gmx.net
In reply to: Andre Fortin (#1)
Re: How to identify the class of a record

Andre Fortin writes:

SELECT * from Equipment*;

Is there a way to know from which table each row in the returned record
set belongs to, as you can do with OO languages.

In 7.1 there will be an implicit column TABLEOID. In 7.0 and earlier
there's no good way short of maintaining such a column manually.

--
Peter Eisentraut peter_e@gmx.net http://yi.org/peter-e/