The following bug has been logged online:
Bug reference: 2771
Logged by: vincent
Email address: vincent@iim.nctu.edu.tw
PostgreSQL version: 8.x
Operating system: windows2k
Description: NULL values in FOREIGN KEY fields
Details:
When insert a null value in foreign key fields, an error occurs.
example table
===================
CREATE TABLE TGroup (
C_Group_ID CHAR(8) NOT NULL,
C_Group_Name VARCHAR(50),
C_Group_Parent CHAR(8) NOT NULL,
CONSTRAINT TGroup_pkey PRIMARY KEY(C_Group_ID),
CONSTRAINT TGroup_C_Group_Parent_fkey FOREIGN KEY (C_Group_Parent)
REFERENCES TGroup(C_Group_ID)
ON DELETE RESTRICT
ON UPDATE RESTRICT
NOT DEFERRABLE
) WITHOUT OIDS;
The definition of foreign key constraint:
A FOREIGN KEY constraint does not have to be linked only to a PRIMARY KEY
constraint in another table; it can also be defined to reference the columns
of a UNIQUE constraint in another table. A FOREIGN KEY constraint can
contain null values; however, if any column of a composite FOREIGN KEY
constraint contains null values, verification of all values that make up the
FOREIGN KEY constraint is skipped. To make sure that all values of a
composite FOREIGN KEY constraint are verified, specify NOT NULL on all the
participating columns.
ref: http://msdn2.microsoft.com/en-us/library/ms175464.aspx