Re: create view ... select fld,'constant',fld ... - Mailing list pgsql-general

From Tom Lane
Subject Re: create view ... select fld,'constant',fld ...
Date
Msg-id 4173.1044073265@sss.pgh.pa.us
Whole thread Raw
In response to create view ... select fld,'constant',fld ...  (will trillich <will@serensoft.com>)
Responses Re: create view ... select fld,'constant',fld ...  (will trillich <will@serensoft.com>)
List pgsql-general
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

pgsql-general by date:

Previous
From: "Andrew J. Kopciuch"
Date:
Subject: Re: [SQL] For each record in SELECT
Next
From: will trillich
Date:
Subject: paradigm sanity check needed [long]