INHERIT
If I try to get the columns from pg_attribute using the oid of a child
table created with INHERIT I get its columns AND all of its inherited
columns.
How do I just get the columns added by the child table?
I figure I could check each column to see if they also exist in
pg_attribute under a parent table but I figure there must be an
easier/faster way? Another pg_* table perhaps? Besides; I am not certian
this would work if there is a common column between a child and one of
its parents (if that is even allowed)?
As usual, any help would be greatly appreciated.
Peter
BTW: I checked pg_dump source and did not see an answer.
--
+---------------------------
| Data Architect
| your data; how you want it
| http://www.codebydesign.com
+---------------------------
Oliver Elphick wrote:
Peter Harvey wrote:
If I try to get the columns from pg_attribute using the oid of a child
table created with INHERIT I get its columns AND all of its inherited
columns.How do I just get the columns added by the child table?
I figure I could check each column to see if they also exist in
pg_attribute under a parent table but I figure there must be an
easier/faster way? Another pg_* table perhaps? Besides; I am not certian
this would work if there is a common column between a child and one of
its parents (if that is even allowed)?
hannu=# \d parent
Table "parent"
Attribute | Type | Modifier
-----------+---------+----------
parid | integer | not null
Index: parent_pkey
hannu=# create table badchild (parid text) inherits (parent);
NOTICE: CREATE TABLE: merging attribute "parid" with inherited
definition
ERROR: CREATE TABLE: attribute "parid" type conflict (int4 and text)
hannu=#
And anyway, in the current state I would advise you not to put too much
hope in postgreSQL's OO features, especially inheritance ;)
-------------
Hannu
Import Notes
Reference msg id not found: 200109091916.f89JG18s025520@linda.lfix.co.uk | Resolved by subject fallback
Peter Harvey wrote:
If I try to get the columns from pg_attribute using the oid of a child
table created with INHERIT I get its columns AND all of its inherited
columns.How do I just get the columns added by the child table?
I figure I could check each column to see if they also exist in
pg_attribute under a parent table but I figure there must be an
easier/faster way? Another pg_* table perhaps? Besides; I am not certian
this would work if there is a common column between a child and one of
its parents (if that is even allowed)?As usual, any help would be greatly appreciated.
SELECT a.attname
FROM pg_attribute AS a,
pg_class AS c,
pg_inherits AS i
WHERE a.attrelid = c.oid AND
i.inhrelid = c.oid AND
c.relname = 'child_table'
AND a.attname NOT IN (
SELECT a.attname
FROM pg_attribute AS a,
pg_class AS c,
pg_inherits AS i
WHERE i.inhrelid = c.oid AND
a.attrelid = i.inhparent AND
c.relname = 'child_table'
)
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"Submit yourselves therefore to God. Resist the devil,
and he will flee from you." James 4:7
Import Notes
Reply to msg id not found: MessagefromPeterHarveypharvey@codebydesign.comofSun09Sep2001080856PDT.3B9B8608.D3E11D1E@codebydesign.com | Resolved by subject fallback