Re: Strange reference problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Ansley <Michael(dot)Ansley(at)intec-telecom-systems(dot)com>
Cc: "'pgsql-general(at)postgresql(dot)org '" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Strange reference problem
Date: 2001-01-18 02:20:47
Message-ID: 22720.979784447@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michael Ansley <Michael(dot)Ansley(at)intec-telecom-systems(dot)com> writes:
> CREATE TABLE "swt" (
> "id" varchar(10) not null,
> "org" varchar(7) not null references "organisation"("id"),
> "description" varchar not null,
> primary key("id", "org")
> );

> DROP TABLE "poi";
> CREATE TABLE "poi" (
> "id" varchar(15) not null,
> "org" varchar(7) not null references "organisation"("id"),
> "name" varchar not null,
> primary key("id", "org")
> );

> DROP TABLE "tug";
> CREATE TABLE "tug" (
> "id" varchar(21) not null primary key,
> "description" varchar not null,
> "id_swt" varchar(10) not null references "swt"("id"),
> "swt_org" varchar(7) not null references "swt"("org"),
> "id_poi" varchar(15) not null references "poi"("id"),
> "poi_org" varchar(7) not null references "poi"("org")
> );

Those primary key declarations say that the combination of ID and ORG
together will be unique for each row of swt (ditto poi). They do not
promise that either ID or ORG will be unique by itself --- but that's
what the references clauses require to be valid. You probably want
to declare the references using a FOREIGN KEY clause that says that
the two-column pair id_swt, swt_org references the two-column pair
swt(id,org), and likewise for poi. AFAIK that's the only way to
define a multi-column reference key.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message HC Mercy T. de Vera 2001-01-18 03:11:58 TRIGGER
Previous Message Michael Ansley 2001-01-18 01:37:05 Strange reference problem