RE: Strange reference problem

From: Michael Ansley <Michael(dot)Ansley(at)intec-telecom-systems(dot)com>
To: "'Tom Lane'" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "'pgsql-general(at)postgresql(dot)org '" <pgsql-general(at)postgresql(dot)org>
Subject: RE: Strange reference problem
Date: 2001-01-18 09:58:33
Message-ID: 7F124BC48D56D411812500D0B747251480F39C@FILESERVER002
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

OK, I see. The REFERENCES clause added to a column definition is a short
cut if you only have one column as the foreign key, similar to the PRIMARY
KEY clause, which you can add to a single column, but if you want a
multi-column primary key, then you have to do it at the end.

Thanks, Tom.

-----Original Message-----
From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
Sent: 18 January 2001 02:21
To: Michael Ansley
Cc: 'pgsql-general(at)postgresql(dot)org '
Subject: Re: [GENERAL] Strange reference problem

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

**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
Nick West - Global Infrastructure Manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

Attachment Content-Type Size
unknown_filename application/ms-tnef 2.8 KB

Browse pgsql-general by date

  From Date Subject
Next Message Toni Pljakoski 2001-01-18 10:14:28 Problem with starting my db with Postmaster
Previous Message Dan Langille 2001-01-18 09:30:48 Re: GET DIAGNOSTICS SELECT PROCESSED INTO <int4_variable>