From: | Dennis Gearon <gearond(at)cvc(dot)net> |
---|---|
To: | "Ed L(dot)" <pgsql(at)bluepolka(dot)net> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: ERROR: UNIQUE constraint ... not found? |
Date: | 2003-04-02 23:09:00 |
Message-ID: | 3E8B6D8C.2050007@cvc.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Which record in the parent table would the foreign key refer to if there were
multiple (non unique) records with the same value in the referenced table?
Ed L. wrote:
> On Wednesday April 2 2003 3:31, Ed L. wrote:
>
>>Well, I've stared at this little riddle for long enough. Anyone see a
>>mistake?
>>
>>CREATE TABLE person (
>> id SERIAL,
>> name VARCHAR NOT NULL
>>);
>>
>>CREATE TABLE session (
>> id SERIAL,
>> person_id INTEGER NOT NULL,
>> FOREIGN KEY (person_id) REFERENCES person (id)
>>);
>>
>>psql:test.sql:12: ERROR: UNIQUE constraint matching given keys for
>>referenced table "person" not found
>
>
> Ah. I was wondering why this didn't work anymore when it worked in 7.1. I
> guess the change in SERIAL semantics where the unique index is no longer
> created is what causes the problem. If I used PRIMARY KEY or create a
> unique index manually on person.id, it works fine. It seems odd that one
> cannot have a foreign key to a non-indexed column in another table.
>
> Ed
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2003-04-02 23:21:55 | Re: Backend often crashing |
Previous Message | Patrick Hatcher | 2003-04-02 22:59:18 | Updating a view |