Allow child table to be missing nullable column from parent.

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Allow child table to be missing nullable column from parent.
Date: 2013-08-22 17:32:29
Message-ID: CAMkU=1wJGUnaaksTn7t3cekArVv4LkCfL4RaVkhJbiMb-dTHzQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Currently a child table has to have all the columns the parent table has:

create table foo1 (x integer, y text, z bool);
create table foo2 (x integer, y text, q text);
alter table foo2 inherit foo1 ;
ERROR: child table is missing column "z"

In theory it seems like this could be allowed as long as the parent
column is nullable, then the column is just deemed to be all null in
the child. You can emulate such a situation using views rather than
inheritance:

create view foo4 as (select * from foo1 union all select x,y,
NULL::bool as z from foo2);

I would have found the ability to do this via inheritance to be
convenient a couple times, as a temporary measure while doing some
refactoring. Or at least I think I would found it convenient,
perhaps I would have actually just shot myself in the foot with it for
reasons I don't understand yet.

Is this something we don't want, or something we do want provided it
can be implemented in a reasonable way? I have not mapped out how
easy it would be to implement.

I didn't find a discussion of this possibility in the archives, but it
is not the easiest thing to search for.

Cheers,

Jeff

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2013-08-22 17:47:49 Re: Allow child table to be missing nullable column from parent.
Previous Message Andres Freund 2013-08-22 16:49:07 Re: pg_system_identifier()