473,805 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FK issue

I have set up a FK as follows

ALTER TABLE lk_sub_con ADD FOREIGN KEY (type) REFERENCES
lk_sort_of_cont act(type_code);

However when I do this

INSERT INTO lk_sort_of_cont act (type_code) VALUES ('1') (ie: a NULL into
the FK) it works

Is this a bug?

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #1
12 1486
mike <mi**@bristolre ccc.co.uk> writes:
I have set up a FK as follows

ALTER TABLE lk_sub_con ADD FOREIGN KEY (type) REFERENCES
lk_sort_of_cont act(type_code);

However when I do this

INSERT INTO lk_sort_of_cont act (type_code) VALUES ('1') (ie: a NULL into
the FK) it works

Is this a bug?


No.

NULLs are permitted in referencing columns unless that column is
declared NOT NULL.

-Doug

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #2
mike <mi**@bristolre ccc.co.uk> writes:
I have set up a FK as follows

ALTER TABLE lk_sub_con ADD FOREIGN KEY (type) REFERENCES
lk_sort_of_cont act(type_code);

However when I do this

INSERT INTO lk_sort_of_cont act (type_code) VALUES ('1') (ie: a NULL into
the FK) it works

Is this a bug?


No.

NULLs are permitted in referencing columns unless that column is
declared NOT NULL.

-Doug

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #3
-----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_cont act(type_code);

However when I do this

INSERT INTO lk_sort_of_cont act (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_cont act , 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_cont act field type_code"

Try to add a null value to lk_sub_con.type - or any value that's not in
lk_sort_of_cont act. Postgres will throw an error.
If you don't want nulls in the referenced table lk_sort_of_cont act you haveto
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)

iD8DBQFAyIY4jqG XBvRToM4RArWZAJ wLGsUpEwCgPTybC bmkIE52op1fmwCf Wrfl
44hCrMlGYIaL8Av TXzeR7VI=
=yMO4
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #4
-----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_cont act(type_code);

However when I do this

INSERT INTO lk_sort_of_cont act (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_cont act , 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_cont act field type_code"

Try to add a null value to lk_sub_con.type - or any value that's not in
lk_sort_of_cont act. Postgres will throw an error.
If you don't want nulls in the referenced table lk_sort_of_cont act you haveto
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)

iD8DBQFAyIY4jqG XBvRToM4RArWZAJ wLGsUpEwCgPTybC bmkIE52op1fmwCf Wrfl
44hCrMlGYIaL8Av TXzeR7VI=
=yMO4
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #5
mike <mi**@bristolre ccc.co.uk> writes:
INSERT INTO lk_sort_of_cont act (type_code) VALUES ('1') (ie: a NULL into
the FK) it works Is this a bug?


No. Mark the column NOT NULL if you wish to disallow nulls.

regards, tom lane

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

Nov 23 '05 #6
mike <mi**@bristolre ccc.co.uk> writes:
INSERT INTO lk_sort_of_cont act (type_code) VALUES ('1') (ie: a NULL into
the FK) it works Is this a bug?


No. Mark the column NOT NULL if you wish to disallow nulls.

regards, tom lane

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

Nov 23 '05 #7
On Thu, 2004-06-10 at 17:03, Uwe C. Schroeder wrote:
-----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_cont act(type_code);

However when I do this

INSERT INTO lk_sort_of_cont act (type_code) VALUES ('1') (ie: a NULL into
the FK) it works

this should have said

INSERT INTO lk_sub_con (sub_cat) VALUES ('1') (ie: a NULL into
the FK) it works ie: a NULL in type

(wrong copy) 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_cont act , 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_cont act field type_code"

Try to add a null value to lk_sub_con.type - or any value that's not in
lk_sort_of_cont act. Postgres will throw an error.


this is the problem - it doesnt if I put a null in (the refernced column
has no nulls)

If you don't want nulls in the referenced table lk_sort_of_cont act you have to
define that there. Maybe you make the field type_code unique or the primary
key.

It is UC

For info

SELECT type_code FROM lk_sort_of_cont act; type_code
----------- 3 6 5 1
2
4
7
9
8
10
11
12
13
14
16
17
20
21
SELECT * FROM lk_sub_con;
sub_id | type | sub_cat | scat_desc
--------+------+---------+-----------
1 | | 1 |
2 | | 20 |
3 | 21 | 22 |

(after the above FK & INSERT)
- -- 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)

iD8DBQFAyIY4jqG XBvRToM4RArWZAJ wLGsUpEwCgPTybC bmkIE52op1fmwCf Wrfl
44hCrMlGYIaL8Av TXzeR7VI=
=yMO4
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #8
On Thu, 2004-06-10 at 17:03, Uwe C. Schroeder wrote:
-----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_cont act(type_code);

However when I do this

INSERT INTO lk_sort_of_cont act (type_code) VALUES ('1') (ie: a NULL into
the FK) it works

this should have said

INSERT INTO lk_sub_con (sub_cat) VALUES ('1') (ie: a NULL into
the FK) it works ie: a NULL in type

(wrong copy) 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_cont act , 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_cont act field type_code"

Try to add a null value to lk_sub_con.type - or any value that's not in
lk_sort_of_cont act. Postgres will throw an error.


this is the problem - it doesnt if I put a null in (the refernced column
has no nulls)

If you don't want nulls in the referenced table lk_sort_of_cont act you have to
define that there. Maybe you make the field type_code unique or the primary
key.

It is UC

For info

SELECT type_code FROM lk_sort_of_cont act; type_code
----------- 3 6 5 1
2
4
7
9
8
10
11
12
13
14
16
17
20
21
SELECT * FROM lk_sub_con;
sub_id | type | sub_cat | scat_desc
--------+------+---------+-----------
1 | | 1 |
2 | | 20 |
3 | 21 | 22 |

(after the above FK & INSERT)
- -- 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)

iD8DBQFAyIY4jqG XBvRToM4RArWZAJ wLGsUpEwCgPTybC bmkIE52op1fmwCf Wrfl
44hCrMlGYIaL8Av TXzeR7VI=
=yMO4
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #9

On Thu, 10 Jun 2004, mike wrote:
On Thu, 2004-06-10 at 17:03, Uwe C. Schroeder wrote:
Try to add a null value to lk_sub_con.type - or any value that's not in
lk_sort_of_cont act. Postgres will throw an error.


this is the problem - it doesnt if I put a null in (the refernced column
has no nulls)


NULLs in a referencing column are a special case in the spec. For a
single column key, a NULL is considered to pass the constraint. For
multiple column keys it depends on the match type.
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5227
by: Paul Mateer | last post by:
Hi, I have been running some queries against a table in a my database and have noted an odd (at least it seems odd to me) performance issue. The table has approximately 5 million rows and includes the following columns: DocID (INTEGER, PRIMARY KEY, CLUSTERED) IsRecord (INTEGER, NONCLUSTERED)
7
3304
by: George Hester | last post by:
Please take a look at this google artcle: http://groups.google.com/groups?hl=en&lr=&frame=right&th=55d6f4b50f5f9382&seekm=411f370d%241%40olaf.komtel.net#link9 The op was having trouble with access denied using resizeTo. I am having the same issue but the explanations in this article don't seem to apply here. I am not trying to resize a window with content from a different server. This issue lies here. What I do is make a popup...
2
2468
by: Anthony Cuttitta Jr. | last post by:
We have an application that outputs several different graphs from data downloaded from our AS400. The application has worked without (this) issue for several months now, but just recently, the workstation it is normally run from has been upgraded to WinXP from WinNT 5.0. The issue is that the graphs will either display the data within the recordsource (a query), OR it will display the "temp" data in the chart's datasheet (from initial...
0
3577
by: Kevin Spencer | last post by:
Hi all, I am working on a service that uploads METAR weather information to the National Weather Service FTP site. The service I'm authoring is hosted on a Windows 200 server, and the NWS FTP host is on a Unix server. I'm using the FtpWebRequest and FtpWebResponse classes to do the file uploading. I have tested it without any errors at all uploading to an IIS FTP server hosted on our network Most of the time it uploads without error to...
2
2826
by: Ben Rush | last post by:
Hello World, Okay, I have spent the day browsing the newsgroups and reading up on article after article concerning ViewState corruption and so forth, and I have a couple questions. We intermittantly get the following exception - EXCEPTION MESSAGE: The viewstate is invalid for this page and might be corrupted. STACK TRACE:
5
2529
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant applications. I am testing an upgrade of all of the sites and have converted the main root site...although not necessarily fixed any issues. I move on instead and converted one of the virtual roots that is a seperate
0
2230
by: Charles Leonard | last post by:
I am having yet another issue with Windows Server 2003. This time, the web service (a file import web service) appears to run except for one odd message: "ActiveX component can't create object". There are no other statements to indicate what object cannot be created. Otherwise, everything on the test Windows Server 2003 works fine—all import data updates correctly. Unfortunately, my normal development environment is not Windows...
4
3224
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so the page can carry on rendering whilst the call is taking place and also returning the ASP.NET worker thread to service another page request (for scalability). I have developed a very basic asynchronous object (for testing, that reproduces the same...
1
3273
by: AlekseyUS | last post by:
Hi, I'm a little stuck, I basically need to copy all the information within a specific file in Temp and append it to a file in another location. I'm not having any problems with smaller size log files stored within temp foldier and everything reads and appends perfectly, however when i try to read and append from IS12Install.log file in Temp all it appends to my destination file is: ÿþ= and a whole bunch of empty lines I believe...
13
3522
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show allowing the user to make a selection from the popup window. I have enabled AJAX extensions and have a working sample outside of a gridview. However, when I click in the textbox of a gridview row, all I see is a really small square instead of the...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.