Re: Creating a table: UNIQUE constraint matching given keys for referenced table "xy" not found - Mailing list pgsql-novice

From Tom Lane
Subject Re: Creating a table: UNIQUE constraint matching given keys for referenced table "xy" not found
Date
Msg-id 15377.1060267299@sss.pgh.pa.us
Whole thread Raw
In response to Creating a table: UNIQUE constraint matching given keys for referenced table "xy" not found  (Jason Hihn <jhihn@paytimepayroll.com>)
Responses Re: Creating a table: UNIQUE constraint matching given keys
List pgsql-novice
Jason Hihn <jhihn@paytimepayroll.com> writes:
> create table xy( x integer not null, y integer not null, primary key (x,y));
> create table xyz( x integer not null references xy(x), y integer not null
> references xy(y), z integer not null, primary key (x,y,z));
> ERROR:  UNIQUE constraint matching given keys for referenced table "xy" not
> found

I think what you want is a two-column foreign key reference:

create table xyz( x integer not null, y integer not null, z integer not null,
primary key (x,y,z),
foreign key (x,y) references xy(x,y));

            regards, tom lane

pgsql-novice by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Creating a table: UNIQUE constraint matching given keys for referenced table "xy" not found
Next
From: Jason Hihn
Date:
Subject: Re: Creating a table: UNIQUE constraint matching given keys