If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Nullable Column Vs Spaces

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-02-07, 04:46
franka franka is offline
Registered User
 
Join Date: Feb 2007
Posts: 10
Nullable Column Vs Spaces

I have been trying to create a test database in DB2 V7 environment. In one table, am finding this error "The field value in a row X and column Y is missing, but the target column is not nullable." where row X and column Y correspond to a data value that is an empty space. I tried recreating the table with the NOT NULL clause in column Y removed and it loaded all rows. My problem is that the rows with no values for column Y should be recognized as spaces and not nulls, in that when I run
select count(*) in tableZ where columnY =''
I should get the number of all records with no values for column Y.
There should be no nulls in any character field in my data model so that when I run the same query as below:
select count(*) in tableZ where columnY is null
I sholud get 0.

How can I achieve this so that I load my database appropriately?

Thanks,
Franka
Reply With Quote
  #2 (permalink)  
Old 08-02-07, 04:56
guyprzytula guyprzytula is offline
Registered User
 
Join Date: Jun 2006
Posts: 471
create the table with not null and load at least 1 space in this column - as value is required
this should resolve the problem
select * from table where col=' ' (one or more spaces should return the same result)
__________________
Best Regards, Guy Przytula
DB2 UDB LUW certified V6/7/8
Reply With Quote
  #3 (permalink)  
Old 08-03-07, 03:51
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
That doesn't make much sense to me. The empty string is a value. So if you want to indicate that no value is there, you use NULL in SQL.

Anyway, what I think you want to do is to declare the column with DEFAULT '' to tell DB2 that whenever no value is supplied for this column in an INSERT statement, you will use the empty string as value. Since this may not cover all scenarios (IMPORT will try to insert the NULL if you don't exclude the column to begin with), add a trigger that maps a NULL to the empty string.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On