pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Beatrice Yueksel <beatrice@msys.ch>
To: pgsql-admin@postgresql.org
Subject: question regarding REFERENCES and INHERITS
Date: Mon, 31 Mar 2003 12:06:26 +0200
Message-ID: <3E881322.7050403@msys.ch> (raw)

Hi,
I made some test with REFERENCES and INHERITS.
I know from the mailing list that :
"Referential integrity only applies to the named table and not
any child tables..."

I have 3 tables:
art,
schiff_admin (for administration with rules, view, etc...)
schiff (inherits schiff_admin)

There is one reference from schiff_admin to art.
The reference doesn't work in schiff.

If I add a constraint:

ALTER TABLE schiff_admin
ADD CONSTRAINT schiff_admin_fk_art
FOREIGN KEY(art)
REFERENCES
schiff_art (art) ON DELETE NO ACTION ;

the reference works also in schiff.

Why the reference is inherited after the "alter table" and not before?
Thank you in advance,
Beatrice




____________________
First step.
____________________

Create sequence schiff_id_seq;

Create table schiff_art (
   art		VARCHAR(4) PRIMARY KEY NOT NULL,
   bezeichnung	VARCHAR(50) NOT NULL
);


Create table schiff_admin (
   schiff_id  	INTEGER
                 DEFAULT nextval('schiff_id_seq') PRIMARY KEY NOT NULL,
   art	  	VARCHAR(4) REFERENCES schiff_art,
   schiffsname	VARCHAR(255) NOT NULL
)  ;

Create table schiff () INHERITS (schiff_admin);



\d schiff_admin;
                               Table "public.schiff_admin"
    Column    |          Type          |                    Modifiers
-------------+------------------------+-------------------------------------------------
  schiff_id   | integer                | not null default 
nextval('schiff_id_seq'::text)
  art         | character varying(4)   |
  schiffsname | character varying(255) | not null
Indexes: schiff_admin_pkey primary key btree (schiff_id)
Foreign Key constraints: $1 FOREIGN KEY (art) REFERENCES schiff_art(art) 
ON UPDATE NO ACTION ON DELETE NO ACTION

  \d schiff
                                  Table "public.schiff"
    Column    |          Type          |                    Modifiers
-------------+------------------------+-------------------------------------------------
  schiff_id   | integer                | not null default 
nextval('schiff_id_seq'::text)
  art         | character varying(4)   |
  schiffsname | character varying(255) | not null

____________________
Second step.
____________________


ALTER TABLE schiff_admin
ADD CONSTRAINT schiff_admin_fk_art
FOREIGN KEY(art)
REFERENCES
schiff_art (art) ON DELETE NO ACTION ;
  \d schiff_admin;
                               Table "public.schiff_admin"
    Column    |          Type          |                    Modifiers
-------------+------------------------+-------------------------------------------------
  schiff_id   | integer                | not null default 
nextval('schiff_id_seq'::text)
  art         | character varying(4)   |
  schiffsname | character varying(255) | not null
Indexes: schiff_admin_pkey primary key btree (schiff_id)
Foreign Key constraints: $1 FOREIGN KEY (art) REFERENCES schiff_art(art) 
ON UPDATE NO ACTION ON DELETE NO ACTION,
                          schiff_admin_fk_art FOREIGN KEY (art) 
REFERENCES schiff_art(art) ON UPDATE NO ACTION ON DELETE NO ACTION
			

\d schiff;
                                  Table "public.schiff"
    Column    |          Type          |                    Modifiers
-------------+------------------------+-------------------------------------------------
  schiff_id   | integer                | not null default 
nextval('schiff_id_seq'::text)
  art         | character varying(4)   |
  schiffsname | character varying(255) | not null
Foreign Key constraints: schiff_admin_fk_art FOREIGN KEY (art) 
REFERENCES schiff_art(art) ON UPDATE NO ACTION ON DELETE NO ACTION




view thread (2+ messages)  latest in thread

Message-ID: <3E881322.7050403@msys.ch>
Permalink:  ../3E881322.7050403@msys.ch/
Also on:    postgresql.org/message-id/3E881322.7050403@msys.ch

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: beatrice@msys.ch
  Subject: Re: question regarding REFERENCES and INHERITS
  In-Reply-To: <3E881322.7050403@msys.ch>
  References: <3E881322.7050403@msys.ch>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox