Primary Key Constraint on inheritance table not getting route to child tables

From: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Rushabh Lathia <rushabh(dot)lathia(at)enterprisedb(dot)com>
Subject: Primary Key Constraint on inheritance table not getting route to child tables
Date: 2012-08-20 06:50:52
Message-ID: CAGPqQf2Mx-B0kwejftWckzCEpAfzfkCNhvd+qp3nZ0hbwEMFdA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

ALTER TABLE ADD Constraints PRIMARY KEY on inheritance table not getting
route to child table.

But when we do ALTER TABLE DROP Constraint on the same, it complains about
constraint does not
exists on child table.

Consider the following example

psql=# CREATE TABLE measurement (
psql(# city_id int not null,
psql(# logdate date not null,
psql(# peaktemp int,
psql(# unitsales int
psql(# );
CREATE TABLE
psql=# CREATE TABLE measurement_y2006m02 (
psql(# CHECK ( logdate >= DATE '2006-02-01' AND logdate < DATE
'2006-03-01' )
psql(# ) INHERITS (measurement);
CREATE TABLE
psql=# CREATE TABLE measurement_y2006m03 (
psql(# CHECK ( logdate >= DATE '2006-03-01' AND logdate < DATE
'2006-04-01' )
psql(# ) INHERITS (measurement);
CREATE TABLE
psql=#
psql=#
psql=# ALTER TABLE measurement
ADD CONSTRAINT con1 PRIMARY KEY (city_id);
ALTER TABLE
psql=#
psql=#

-- Don't have primary key on child table
psql=# desc measurement_y2006m02
Table "public.measurement_y2006m02"
Column | Type | Modifiers
-----------+-----------------------------+-----------
city_id | integer | not null
logdate | timestamp without time zone | not null
peaktemp | integer |
unitsales | integer |
Check constraints:
"measurement_y2006m02_logdate_check" CHECK (logdate >= '01-FEB-06
00:00:00'::timestamp without time zone AND logdate < '01-MAR-06
00:00:00'::timestamp without time zone)
Inherits: measurement

-- Primary key on parent table
psql=# desc measurement
Table "public.measurement"
Column | Type | Modifiers
-----------+-----------------------------+-----------
city_id | integer | not null
logdate | timestamp without time zone | not null
peaktemp | integer |
unitsales | integer |
Indexes:
"con1" PRIMARY KEY, btree (city_id)
Number of child tables: 2 (Use \d+ to list them.)

*psql=# ALTER TABLE measurement*
*DROP CONSTRAINT con1;*
*ERROR: constraint "con1" of relation "measurement_y2006m02" does not exist
*

I am not sure whether PRIMARY KEY not getting route is a
expected behavior or not, but if its expected behavior
then obviously DROP CONSTRAINT should not complain about constraint doesn't
exists on child table.

Inputs/Comments ?

Thanks,
Rushabh Lathia
www.EnterpriseDB.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Albe Laurenz 2012-08-20 07:40:19 Re: State of the on-disk bitmap index
Previous Message Heikki Linnakangas 2012-08-20 06:39:35 Re: New WAL code dumps core trivially on replay of bad data