REFERENCES ignored when there is inheritance?

From: Stephane Bortzmeyer <bortzmeyer(at)nic(dot)fr>
To: pgsql-general(at)postgresql(dot)org
Subject: REFERENCES ignored when there is inheritance?
Date: 2005-05-13 09:57:08
Message-ID: 20050513095708.GA4628@generic-nic.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table to store localization information:

CREATE TABLE Localization (
...
zipcode TEXT NOT NULL,
...
country INTEGER REFERENCES Countries (id) NOT NULL

The table Countries is like:

CREATE TABLE Countries (
id SERIAL UNIQUE,
name TEXT UNIQUE NOT NULL,
code CHAR(2) UNIQUE NOT NULL);

And a table Contacts_short which inherits from it so all the Contacts
have localization information:

CREATE TABLE Contacts_short (
...
INHERITS (Localization, Objects) WITHOUT OIDS;

I have 240 countries in the database. Because of a programming error,
contacts were entered with a country > 240. I thought that the
"REFERENCES Countries (id)" should have prevented it. Is it because of
inheritance?

PostgreSQL 7.4.7

Example:

registry=> SELECT max(id) FROM Countries;
max
-----
240
(1 row)

registry=> SELECT count(*) FROM Contacts_short WHERE country > 240;
count
-------
84
(1 row)

To me, the last figure should have been zero.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Victor Spång Arthursson 2005-05-13 10:29:10 How many rows if limit wasn't present?
Previous Message Wolfgang Keller 2005-05-13 09:14:51 Re: Please Recommend a Front End App