will trillich <will@serensoft.com> writes:
> is this a stupid idea?
> [create view such that]
> then we can do things like
> ->execute("select parent_table from $table")
Uh, do you really want to impose overhead on *every* query to make
that one operation faster?
I'd go with a query on the system catalogs, for example
regression=# create table p (f1 int);
CREATE TABLE
regression=# create table c (f2 int) inherits(p);
CREATE TABLE
regression=# select relname from pg_class where
regression-# oid = (select inhparent from pg_inherits where
regression(# inhrelid = (select oid from pg_class where relname = 'c'));
relname
---------
p
(1 row)
Note this example will provoke a failure if 'c' inherits from multiple
parents --- you could add a condition on pg_inherits.inhseqno to deal
with that.
Also, as of 7.3 you'd need to think about schema issues leading
to ambiguities of relnames. In 7.3 I'd be inclined to write
regression=# select inhparent::regclass from pg_inherits where inhrelid = 'c'::regclass;
inhparent
-----------
p
(1 row)
since the regclass I/O converters do the right thing with schemas.
regards, tom lane