From: | Terry Lee Tucker <terry(at)esc1(dot)com> |
---|---|
To: | Victor Spång Arthursson <victor(at)tosti(dot)dk>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Foreign key question |
Date: | 2004-01-15 16:21:16 |
Message-ID: | 200401151121.16152.terry@esc1.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
From the HTML docs:
"The referenced columns must be the columns of a unique or primary key
constraint in the referenced table."
I personally don't know of a work around. Maybe some of the others do.
On Thursday 15 January 2004 10:56 am, Victor Spång Arthursson wrote:
> New to foreign keys and have some questions…
>
> The first is, i have a language table with a primary key on the fields
> lang and relid:
>
> relid | lang | text
> -------+------+-------------
> 11111 | uk | hello
> 11111 | dk | hej
> 11111 | de | guten tag
> 11112 | uk | world
> 11112 | dk | værld
>
> In another table, texts, I have the following:
>
> id | text
> -------+------+
> 4 | 11112 |
>
> What I want to do is to create a foreign key between the two tables.
> But trying to do so, with the following syntax, I get the following
>
> error message:
> > ALTER TABLE varer ADD CONSTRAINT varenavn FOREIGN KEY (varenavn)
>
> REFERENCES languages(relid) MATCH FULL ON DELETE CASCADE;
>
> >ERROR: there is no unique constraint matching given keys for
>
> referenced table "languages"
> tostipippitest=#
>
> Can't i create a Foreign key to a field that is not defined as UNIQUE?
>
> And if so, are there any other approach to solve this problem?
>
> Sincerely
>
> Victor
>
> PS If someone has a link to a good tutorial I would love to have it DS
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
--
"The most important reason that people save is the hope of providing a
better life for their children. A society that punishes that impulse
with taxes is foolish. It is draining energy from the single most power-
ful engine of capital accumulation. If the super-rich don't want their
kids to get their money, fine. Donate every penny of it to someone else.
But they are wrong to block others from exercising a free choice."
--Lew Rockwell
Work: 1-336-372-6812
Cell: 1-336-363-4719
email: terry(at)esc1(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Julio Misael Gutierrez | 2004-01-15 16:22:20 | when I create a table, postgresql creates a new type |
Previous Message | Adrian Klaver | 2004-01-15 16:19:01 | Re: Errors after power failure |