Re: Creating a table: UNIQUE constraint matching given keys for referenced table "xy" not found

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jason Hihn <jhihn(at)paytimepayroll(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Creating a table: UNIQUE constraint matching given keys for referenced table "xy" not found
Date: 2003-08-07 14:41:39
Message-ID: 15377.1060267299@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Jason Hihn <jhihn(at)paytimepayroll(dot)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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Jason Hihn 2003-08-07 15:06:46 Re: Creating a table: UNIQUE constraint matching given keys
Previous Message Bruno Wolff III 2003-08-07 14:27:24 Re: Creating a table: UNIQUE constraint matching given keys for referenced table "xy" not found