Allow child table to be missing nullable column from parent.
Allow child table to be missing nullable column from parent.
От:
Jeff Janes <jeff.janes@gmail.com>
Дата:
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
Re: Allow child table to be missing nullable column from parent.
От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Jeff Janes writes: > 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. TBH this doesn't seem like a very good idea. It suggests strongly that you messed up the inheritance, and even if it was intentional, what did you save by not having the child column? To point out just one practical problem, what is supposed to happen when you do "UPDATE foo1 SET z = true WHERE ..." with a condition that selects some rows in foo2? regards, tom lane