Hi,
Our documentation says:
"All check constraints and not-null constraints on a parent table are
automatically inherited by its children."
Okay, this works as expected:
test=# create table parent (name text primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "parent_pkey" for table "parent"
CREATE TABLE
test=*# create table child (age int) inherits (parent) ;
CREATE TABLE
test=*# \d child
Table "public.child"
Column | Type | Modifiers
--------+---------+-----------
name | text | not null
age | integer |
Inherits: parent
Nice, the 'not null' constraint is in the child-table.
test=*# rollback;
ROLLBACK
test=# create table parent (name text);
CREATE TABLE
test=*# create table child (age int) inherits (parent) ;
CREATE TABLE
test=*# alter table parent add primary key (name);
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "parent_pkey" for table "parent"
ALTER TABLE
test=*# \d child
Table "public.child"
Column | Type | Modifiers
--------+---------+-----------
name | text |
age | integer |
Inherits: parent
Doh, there isn't the 'not null' - modifier. The parent-table contains
this modifier as part of the primary key - definition.
Other test:
test=# create table parent (name text);
CREATE TABLE
test=*# create table child (age int) inherits (parent) ;
CREATE TABLE
test=*# alter table parent alter column name set not null;
ALTER TABLE
test=*# \d child
Table "public.child"
Column | Type | Modifiers
--------+---------+-----------
name | text | not null
age | integer |
Inherits: parent
Okay, we have again the 'not null'.
I think, that's not really clearly. In some case the 'not null' -
constraint are in the child-table, in other case they are not.
Version 8.4.2.
Bug, feature? What have i overlooked?
Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99