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

Re: Problème de clé é

From: Stephane Bortzmeyer <bortzmeyer(at)nic(dot)fr>
To: Jonathan Ballet <jon(at)multani(dot)info>
Cc: pgsql-fr-generale(at)postgresql(dot)org
Subject: Re: Problème de clé é
Date: 2005-12-02 10:45:43
Message-ID: 20051202104543.GA18581@nic.fr (view raw or flat)
Thread:
Lists: pgsql-fr-generale
On Wed, Nov 30, 2005 at 11:31:13PM +0100,
 Jonathan Ballet <jon(at)multani(dot)info> wrote 
 a message of 32 lines which said:

> une table B qui dérive de A

Pas la peine d'aller plus loin : l'héritage en PostgreSQL est *très*
limité (au point que je ne l'utiliserai plus) et notamment les
contraints d'intégrité ne sont pas transmises ou pas correctement.

http://archives.free.net.ph/message/20050802.054006.572ae7ba.en.html

Mon expérience :

ssais=> CREATE TABLE Things (id SERIAL UNIQUE NOT NULL);
NOTICE: CREATE TABLE will create implicit sequence "things_id_seq" for serial column "things.id"
NOTICE: CREATE TABLE / UNIQUE will create implicit index "things_id_key" for table "things"
CREATE TABLE
essais=> CREATE TABLE Users (name TEXT) INHERITS (Things);
CREATE TABLE
essais=> CREATE TABLE Groups (name TEXT) INHERITS (Things);
CREATE TABLE
essais=> CREATE TABLE Foobar (name TEXT, id INTEGER REFERENCES Things(id));
CREATE TABLE
essais=>
essais=> INSERT INTO Users (name) VALUES ('Wolf');
INSERT 42132 1
essais=> INSERT INTO Groups (name) VALUES ('FT');
INSERT 42133 1
essais=> SELECT * FROM Things;
id
----
id
----
1
2
(2 rows)

essais=> INSERT INTO Foobar VALUES ('computer', 2);
ERROR: insert or update on table "foobar" violates foreign key constraint "foobar_id_fkey"
DETAIL: Key (id)=(2) is not present in table "things".
essais=> INSERT INTO Foobar VALUES ('computer', 1);
ERROR: insert or update on table "foobar" violates foreign key constraint "foobar_id_fkey"
DETAIL: Key (id)=(1) is not present in table "things".
essais=> \d things
Table "public.things"
Column | Type | Modifiers
--------+---------+--------------------------------------------------------
id | integer | not null default nextval('public.things_id_seq'::text)
Indexes:
"things_id_key" UNIQUE, btree (id)

In response to

Responses

pgsql-fr-generale by date

Next:From: Emmanuel SeymanDate: 2005-12-02 11:06:17
Subject: synchroniser les tables de ?==?iso-8859-1?Q?deux bases différentes
Previous:From: Jonathan BalletDate: 2005-11-30 22:31:13
Subject: Problème de clé étrangère

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