473,671 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
+ 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 11203
that's an empty string...... not null...

regards,
dotyet

On Mar 28, 2:15 pm, "db2admin" <jag...@gmail.c omwrote:
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.j ons...@gmail.co mwrote:
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.c omwrote:
On Mar 28, 2:53 pm, Lennart <erik.lennart.j ons...@gmail.co mwrote:
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
7423
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
2076
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 first while-statement the OP cast the NULL to a (long), isn't *buf a char ? and another question is what's the purpose of NULL in string manipulation, and how to test to see if an input string is empty ? Thanx for your help. void parse (char...
102
5975
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" ( i am talking of unix machine ) while trying to read that location. Then how can i distinguish between a NULL pointer and an invalid location ? Is this essential that NULL pointer should not point to any of the location in the virtual address...
29
3737
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 compiler dependent (and that NULL might be anything, but it is always NULL). The source snippet is below. The question is: - When I use calloc to allocate a block of memory, preinitialising it to zero, is this equivalent (and portable C) to...
42
5913
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 printed will it be all 0's or 0x12345678 int main(void) { char *ptr; ptr = 0;
64
3902
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")? - AFAIK C allows "null pointers" to be represented differently then "all bits 0". Is this correct? - AFAIK I can't `#define NULL 0x10000' since `void* p=0;' should work just like `void* p=NULL'. Is this correct?
69
5557
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 assigning them their maximum defined values. However, the output of printf() for the long double 'ld' and the pointer of type void 'v_p', after initialisation don't seem to be right. The compiler used was gcc (mingw) with '-Wall', '-std=c99' and
37
7025
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 NULL improperly. However, 18.1/4(footnote 180) indicates that 0 and 0L are valid NULLs, while (void*)0 is explicitly invalid.
31
17693
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
12284
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) length string, an empty Field, or no value at all - so exactly what is Null? The purpose of this Topic is hopefully to explain what a Null Value is, discuss some peculiarities about Nulls, show how we can detect them, and finally, how to convert...
0
8474
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
8392
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,...
0
8912
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8597
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
8669
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
7428
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...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2809
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 we have to send another system
2
1807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.