Skip site navigation (1) Skip section navigation (2)

possible bug with inheritance?

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: possible bug with inheritance?
Date: 2010-02-12 12:40:34
Message-ID: 20100212124034.GC25282@a-kretschmer.de (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-generalpgsql-hackers
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

Responses

pgsql-hackers by date

Next:From: Simon RiggsDate: 2010-02-12 12:51:20
Subject: Re: Re: [COMMITTERS] pgsql: Make standby server continuously retry restoring the next WAL
Previous:From: Tim BunceDate: 2010-02-12 10:40:13
Subject: Re: Add on_trusted_init and on_untrusted_init to plperl UPDATED [PATCH]

pgsql-general by date

Next:From: Richard HuxtonDate: 2010-02-12 12:47:24
Subject: Re: Weeding out unused user created database objects, could I use pg_catalog?
Previous:From: Allan KamauDate: 2010-02-12 12:32:03
Subject: Weeding out unused user created database objects, could I use pg_catalog?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group