Re: create view ... select fld,'constant',fld ...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: will trillich <will(at)serensoft(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: create view ... select fld,'constant',fld ...
Date: 2003-02-01 04:21:05
Message-ID: 4173.1044073265@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

will trillich <will(at)serensoft(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message will trillich 2003-02-01 04:28:24 paradigm sanity check needed [long]
Previous Message Michelle Konzack 2003-02-01 04:17:16 Re: passwords and 7.3