pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: nzanella@cs.mun.ca
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL DDL: FOREIGN KEY construct and field mapping: unexpected behavior
Date: Sun, 06 Jun 2004 18:37:42 -0400
Message-ID: <21440.1086561462@sss.pgh.pa.us> (raw)
In-Reply-To: <b68d2f19.0406060019.2daa1082@posting.google.com>
References: <b68d2f19.0406060019.2daa1082@posting.google.com>

nzanella@cs.mun.ca (Neil Zanella) writes:
> CREATE TABLE X (
>   A INT,
>   B INT,
>   PRIMARY KEY (A, B)
> );

> CREATE TABLE Y (
>   A INT,
>   B INT,
>   C INT,
>   PRIMARY KEY (C),
>   FOREIGN KEY (B, A) REFERENCES X
> );

> whereas I was expecting the database server to match the names as in:

Why were you expecting that?  The SQL spec is perfectly clear that the
columns are matched in the order written in the primary key.  For
instance, SQL92 11.8 <referential constraint definition> saith:

         2) Case:
            b) If the <referenced table and columns> does not specify a
              <reference column list>, then the table descriptor of the
              referenced table shall include a unique constraint that spec-
              ifies PRIMARY KEY. Let referenced columns be the column or
              columns identified by the unique columns in that unique con-
              straint and let referenced column be one such column. The
              <referenced table and columns> shall be considered to implic-
              itly specify a <reference column list> that is identical to
              that <unique column list>.

         7) The <referencing columns> shall contain the same number of <col-
            umn name>s as the <referenced table and columns>. The i-th col-
            umn identified in the <referencing columns> corresponds to the
            i-th column identified in the <referenced table and columns>.
            The data type of each referencing column shall be the same as
            the data type of the corresponding referenced column.

Nothing there about "try to match by name".

			regards, tom lane



view thread (2+ messages)

Message-ID: <21440.1086561462@sss.pgh.pa.us>
Permalink:  ../21440.1086561462@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21440.1086561462@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, nzanella@cs.mun.ca
  Subject: Re: SQL DDL: FOREIGN KEY construct and field mapping: unexpected behavior
  In-Reply-To: <21440.1086561462@sss.pgh.pa.us>

* 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