dbTalk Databases Forums  

[BUGS] BUG #2771: NULL values in FOREIGN KEY fields

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #2771: NULL values in FOREIGN KEY fields in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
vincent
 
Posts: n/a

Default [BUGS] BUG #2771: NULL values in FOREIGN KEY fields - 11-20-2006 , 07:17 PM







The following bug has been logged online:

Bug reference: 2771
Logged by: vincent
Email address: vincent (AT) iim (DOT) 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

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Reply With Quote
  #2  
Old   
Jaime Casanova
 
Posts: n/a

Default Re: [BUGS] BUG #2771: NULL values in FOREIGN KEY fields - 11-20-2006 , 10:44 PM






On 11/20/06, vincent <vincent (AT) iim (DOT) nctu.edu.tw> wrote:
Quote:
When insert a null value in foreign key fields, an error occurs.

CREATE TABLE TGroup (
C_Group_ID CHAR(8) NOT NULL,
C_Group_Name VARCHAR(50),
C_Group_Parent CHAR(8) NOT NULL,
CONSTRAINT TGroup_C_Group_Parent_fkey FOREIGN KEY (C_Group_Parent)
That's because your C_Group_Parent column has a Not Null constraint
and you can't insert null values in a Not Null columns

--
regards,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
Richard Cook

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
  #3  
Old   
Euler Taveira de Oliveira
 
Posts: n/a

Default Re: [BUGS] BUG #2771: NULL values in FOREIGN KEY fields - 11-20-2006 , 10:49 PM



vincent wrote:

Quote:
When insert a null value in foreign key fields, an error occurs.

This is not a bug. The error occurs because you're trying to insert NULL
in a NOT NULL field (C_Group_Parent). Try to strip the NOT NULL from
C_Group_Parent field so you can insert NULL in it.


--
Euler Taveira de Oliveira
http://www.timbira.com/


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.