Return-Path: owner-postman
Received: from localhost (localhost [127.0.0.1]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id QAA25105 for postgres-dist; Mon, 28 Mar 1994 16:25:05 -0800
Resent-From: POSTGRES mailing list <postman@postgres.Berkeley.EDU>
Resent-Message-Id: <199403290025.QAA25105@nobozo.CS.Berkeley.EDU>
Sender: owner-postman@postgres.Berkeley.EDU
X-Return-Path: owner-postman
Received: from faerie.CS.Berkeley.EDU (faerie.CS.Berkeley.EDU [128.32.149.14]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with ESMTP id QAA25096 for <postgres@postgres.Berkeley.EDU>; Mon, 28 Mar 1994 16:25:05 -0800
Received: from localhost (localhost [127.0.0.1]) by faerie.CS.Berkeley.EDU (8.6.4/8.1B) with SMTP id QAA28189; Mon, 28 Mar 1994 16:24:59 -0800
Message-Id: <199403290024.QAA28189@faerie.CS.Berkeley.EDU>
X-Authentication-Warning: faerie.CS.Berkeley.EDU: Host localhost didn't use HELO protocol
From: aoki@postgres.Berkeley.EDU (Paul M. Aoki)
To: Vivek Shivpuri <vivek@tis.telos.com>
Cc: postgres@postgres.Berkeley.EDU
Subject: Re: Inherited Attributes Question 
Reply-To: aoki@postgres.Berkeley.EDU (Paul M. Aoki)
In-reply-to: Your message of Mon, 28 Mar 1994 18:22:48 -0500 (EST) 
	     <199403282322.SAA07059@ozone.telos.com> 
Date: Mon, 28 Mar 94 16:24:59 -0800
X-Sender: aoki@postgres.Berkeley.EDU
Resent-To: postgres-dist@postgres.Berkeley.EDU
X-Mts: smtp
Resent-Date: Mon, 28 Mar 94 16:25:05 -0800
Resent-XMts: smtp

Vivek Shivpuri <vivek@tis.telos.com> writes:
>  create a(t=text)
>  create b(k=int4) inherits (a)
>  What is the query to find out which attribute belongs to which class?

the 4.2 reference manual contains a description of the system catalog 
attributes.

pg_inherits.inhrel (oid of child) and pg_inherits.inhparent (oid of 
parent) give you the edges in the inheritance hierarchy.  inhseqno
records the order that classes were specified in the "create" command 
(of interest in multiple inheritance cases).

offhand i can't think of a single-line query that, given only the 
classname of the child, tells you the "highest" parent that contains
a given attribute.  on the other hand, traversing the hierarchy 
yourself seems relatively straightforward.

if all you want is "is this attribute inherited from ANYBODY", then
the following query seems to work.  may not be the simplest possible
query (oh, the joys of normalization), but.. oh yeah, if you have
multiple inheritance you may want to make this "retrieve unique".

i don't think you're allowed to override an inherited attribute -- if
you can, this won't work.

Go 
* create a(t=text)
\g
Go
* create b(k=int4) inherits (a)
\g
Go
* retrieve (ca.attname)
from ca in pg_attribute, pa in pg_attribute, i in pg_inherits,
c in pg_class, p in pg_class
where
c.oid = i.inhrel and
p.oid = i.inhparent and
c.oid = ca.attrelid and
p.oid = pa.attrelid and
ca.attname = pa.attname and
ca.attnum > 0 and
c.relname = "b"
\g
---------------
| attname     |
---------------
| t           |
---------------
Go
*

--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  aoki@postgres.Berkeley.EDU
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki
