473,471 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

'' and NULL confusion

hello,

db2 does not recognize '' as null?
say i have T1(C1 INT,C2 CHAR(4))
and i insert (1,'') , it would not be same as (1,NULL)
what db2 consider '' as? how does it store value '' as if not as NULL
because technically is it no data just empty string.

we have application which try to update some columns to ''.
same column is a foreign key from other table and it complains because
parent column has NULL and child column value '' does not equal NULL.
we can not change applications at this time and also can not remove
foreign key

please suggest if you have any ideas.

regards,
jagdip singh

Mar 28 '07 #1
6 11192
that's an empty string...... not null...

regards,
dotyet

On Mar 28, 2:15 pm, "db2admin" <jag...@gmail.comwrote:
hello,

db2 does not recognize '' as null?
say i have T1(C1 INT,C2 CHAR(4))
and i insert (1,'') , it would not be same as (1,NULL)
what db2 consider '' as? how does it store value '' as if not as NULL
because technically is it no data just empty string.

we have application which try to update some columns to ''.
same column is a foreign key from other table and it complains because
parent column has NULL and child column value '' does not equal NULL.
we can not change applications at this time and also can not remove
foreign key

please suggest if you have any ideas.

regards,
jagdip singh

Mar 28 '07 #2
db2admin wrote:
db2 does not recognize '' as null?
Correct, DB2 does not recognize an apple as a banana.
It's a standard thing...

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Mar 28 '07 #3
db2admin wrote:
hello,

db2 does not recognize '' as null?
If it did it would have been a bug
say i have T1(C1 INT,C2 CHAR(4))
and i insert (1,'') , it would not be same as (1,NULL)
'' is a value, null is not
what db2 consider '' as? how does it store value '' as if not as NULL
because technically is it no data just empty string.
How does it store 0 as if not null because technically is it no data
just zero?
we have application which try to update some columns to ''.
same column is a foreign key from other table and it complains because
parent column has NULL and child column value '' does not equal NULL.
FYI, your problem is not that there is null in the parent row (if it
where, that column could not have been part of p.k or unique constaint)
we can not change applications at this time and also can not remove
foreign key

please suggest if you have any ideas.
Guess you can implement before triggers that translates '' to null

create trigger Trig1
....
referencing new as n
before inert on T
set (col1, col2, ...,coln) = (nullif(n.col1, ''), nullif(n.col2, ''),
...., nullif(coln, ''))
/Lennart

Mar 28 '07 #4
On Mar 28, 2:53 pm, Lennart <erik.lennart.jons...@gmail.comwrote:
db2admin wrote:
hello,
db2 does not recognize '' as null?

If it did it would have been a bug
say i have T1(C1 INT,C2 CHAR(4))
and i insert (1,'') , it would not be same as (1,NULL)

'' is a value, null is not
what db2 consider '' as? how does it store value '' as if not as NULL
because technically is it no data just empty string.

How does it store 0 as if not null because technically is it no data
just zero?
we have application which try to update some columns to ''.
same column is a foreign key from other table and it complains because
parent column has NULL and child column value '' does not equal NULL.

FYI, your problem is not that there is null in the parent row (if it
where, that column could not have been part of p.k or unique constaint)
we can not change applications at this time and also can not remove
foreign key
please suggest if you have any ideas.

Guess you can implement before triggers that translates '' to null

create trigger Trig1
...
referencing new as n
before inert on T
set (col1, col2, ...,coln) = (nullif(n.col1, ''), nullif(n.col2, ''),
..., nullif(coln, ''))

/Lennart
thanks for help
i feel stupid

Mar 28 '07 #5
oh that's OK... we all do... sometimes :)

regards,
dotyet

On Mar 28, 4:50 pm, "db2admin" <jag...@gmail.comwrote:
On Mar 28, 2:53 pm, Lennart <erik.lennart.jons...@gmail.comwrote:
db2admin wrote:
hello,
db2 does not recognize '' as null?
If it did it would have been a bug
say i have T1(C1 INT,C2 CHAR(4))
and i insert (1,'') , it would not be same as (1,NULL)
'' is a value, null is not
what db2 consider '' as? how does it store value '' as if not as NULL
because technically is it no data just empty string.
How does it store 0 as if not null because technically is it no data
just zero?
we have application which try to update some columns to ''.
same column is a foreign key from other table and it complains because
parent column has NULL and child column value '' does not equal NULL.
FYI, your problem is not that there is null in the parent row (if it
where, that column could not have been part of p.k or unique constaint)
we can not change applications at this time and also can not remove
foreign key
please suggest if you have any ideas.
Guess you can implement before triggers that translates '' to null
create trigger Trig1
...
referencing new as n
before inert on T
set (col1, col2, ...,coln) = (nullif(n.col1, ''), nullif(n.col2, ''),
..., nullif(coln, ''))
/Lennart

thanks for help
i feel stupid

Mar 29 '07 #6
db2admin wrote:
hello,

db2 does not recognize '' as null?
Of course not. '' is an empty string whereas NULL indicates the absence of
a string. You have the same string in Java, for example. A NULL pointer
is not the same as an empty string "".
say i have T1(C1 INT,C2 CHAR(4))
and i insert (1,'') , it would not be same as (1,NULL)
what db2 consider '' as? how does it store value '' as if not as NULL
because technically is it no data just empty string.
In this case, DB2 will store a string comprised of 4 blanks. You used
CHAR(4) and not VARCHAR(4), which implies that all strings are padded to
the right with blanks. Since you have an empty string, 4 padding blanks
are needed to reach the length of 4.

In case of VARCHAR(4), you would have a length of 0 for the value and no
characters in the string.
we have application which try to update some columns to ''.
same column is a foreign key from other table and it complains because
parent column has NULL and child column value '' does not equal NULL.
Naturally. NULL is not an empty string.
we can not change applications at this time and also can not remove
foreign key
You could add a BEFORE trigger to the dependent table which changes '' to
NULL.

CREATE TRIGGER ... BEFORE INSERT ON ...
REFERENCING NEW AS n
FOR EACH ROW
SET n.string_column = NULLIF(n.string_column, '')

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Mar 29 '07 #7

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

Similar topics

69
by: Ken | last post by:
Hi all. When referring to a null pointer constant in C++, is there any reason to prefer using 0 over a macro called NULL that is defined to be 0? Thanks! Ken
8
by: sugaray | last post by:
Hi, I just came upon this code snippet which parses a string stored in buf with comma(,) as delimiter and store each substring into args, the question I'm having here is that I don't get why in the...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
29
by: Jason Curl | last post by:
I've been reading this newsgroup for some time and now I am thoroughly confused over what NULL means. I've read a NULL pointer is zero (or zero typecast as a void pointer), others say it's...
42
by: junky_fellow | last post by:
Consider an implementation that doesn't use all bits 0 to represent a NULL pointer. Let the NULL pointer is represented by 0x12345678. On such an implementation, if the value of NULL pointer is...
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
69
by: fieldfallow | last post by:
Hello all, Before stating my question, I should mention that I'm fairly new to C. Now, I attempted a small demo that prints out the values of C's numeric types, both uninitialised and after...
37
by: red floyd | last post by:
I searched the FAQ on this one, couldn't really find an answer. Stylistically, is it better to use 0 or NULL? I know that pre-Standard, 0 was recommended, because some compilers implemented...
31
by: leonm54 | last post by:
I remember that this is a bad practice, but can not find a definitive resource that states it is bad and why. Can anyone help?
3
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.