Re: FK issue

From: "Uwe C(dot) Schroeder" <uwe(at)oss4u(dot)com>
To: mike <mike(at)bristolreccc(dot)co(dot)uk>, pgsql-general(at)postgresql(dot)org
Subject: Re: FK issue
Date: 2004-06-10 16:03:04
Message-ID: 200406100903.04379.uwe@oss4u.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 10 June 2004 08:21 am, mike wrote:
> I have set up a FK as follows
>
> ALTER TABLE lk_sub_con ADD FOREIGN KEY (type) REFERENCES
> lk_sort_of_contact(type_code);
>
> However when I do this
>
> INSERT INTO lk_sort_of_contact (type_code) VALUES ('1') (ie: a NULL into
> the FK) it works
>
> Is this a bug?

No.
you have a table lk_sub_con. That table has the foreign key assigned.
This means it doesn't matter what you put into lk_sort_of_contact , it matters
what you put into lk_sub_con.
The foreign key says something like
"If you put a value into field type of table lk_sub_con, the same value must
be existant in table lk_sort_of_contact field type_code"

Try to add a null value to lk_sub_con.type - or any value that's not in
lk_sort_of_contact. Postgres will throw an error.
If you don't want nulls in the referenced table lk_sort_of_contact you have to
define that there. Maybe you make the field type_code unique or the primary
key.

UC

- --
Open Source Solutions 4U, LLC 2570 Fleetwood Drive
Phone: +1 650 872 2425 San Bruno, CA 94066
Cell: +1 650 302 2405 United States
Fax: +1 650 872 2417
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAyIY4jqGXBvRToM4RArWZAJwLGsUpEwCgPTybCbmkIE52op1fmwCfWrfl
44hCrMlGYIaL8AvTXzeR7VI=
=yMO4
-----END PGP SIGNATURE-----

In response to

  • FK issue at 2004-06-10 15:21:53 from mike

Responses

Browse pgsql-general by date

  From Date Subject
Next Message mike 2004-06-10 16:27:25 Re: FK issue
Previous Message Tom Lane 2004-06-10 16:00:53 Re: FK issue