Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 10th, 2008, 08:59 AM
Newbie
 
Join Date: Sep 2008
Posts: 4
Default DB2 does not complain(or warn) about data loss

I am trying to insert data from one table to another using the query below

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO SORT_KEY_TEMP2 (SELECT * FROM SORT_KEYS ORDER BY SK_PAGE_ID FETCH FIRST 100 ROWS ONLY);
  2.  
Table
Expand|Select|Wrap|Line Numbers
  1. SORT_KEY_TEMP2
  2.     Name        Data type        Length    Nullable
  3.     SK_PAGE_ID    CHARACTER        8    Yes
  4.     SK_LAUNCH_DATE    TIMESTAMP        10    Yes
  5.     SK_LIST_TYPE    CHARACTER        1    Yes
  6.     SK_SORT_KEY    VARCHAR    FOR BIT DATA    1000    Yes
  7.     SK_ALPHA_GROUP    VARCHAR            5    Yes


Table
Expand|Select|Wrap|Line Numbers
  1. SORT_KEYS
  2.     Name        Data type        Length    Nullable
  3.     SK_PAGE_ID    CHARACTER        8    Yes
  4.     SK_LAUNCH_DATE    TIMESTAMP        10    Yes
  5.     SK_LIST_TYPE    CHARACTER        1    Yes
  6.     SK_SORT_KEY    VARCHAR            1000    Yes
  7.     SK_ALPHA_GROUP    VARCHAR            5    Yes
  8.  


The above query runs fine using control center for DB2 version 8 on AIX.
But on actually viewing the data within table SORT_KEY_TEMP2
, I find that the 'SK_SORT_KEY' column contains no data.
First and foremost it is suprising that DB2 does not throw any warning or error to report this data loss
Second is there a suggested alternate way of accomplishing this thing.
The data in SK_SORT_KEY is a sequence of bytes stored as VARCHAR.
Reply
  #2  
Old September 10th, 2008, 07:57 PM
Expert
 
Join Date: Nov 2006
Posts: 351
Default

Are you completely sure the data is not there? It might be that the the SQL client is just not displaying it since it is "BIT DATA", which I assume means binary data. If your SQL client can only display ASCII data it may not be able to display what ever is in that column.

You might try testing this by running something like this to see if there is something there.

Expand|Select|Wrap|Line Numbers
  1. SELECT SK_SORT_KEY, LENGTH(SK_SORT_KEY)
  2. FROM SORT_KEY_TEMP2
  3.  
The other possibility is that there is no data in the source column (SK_SORT_KEY VARCHAR) that qualifies as "BIT DATA" so there is nothing to insert. Just a guess.
Reply
  #3  
Old September 11th, 2008, 08:48 AM
Newbie
 
Join Date: Sep 2008
Posts: 4
Default

You are right !. The data is present in the column but the DB2 client does not show that up. Gr8 thinking !!. Thanks!!!.

One more related question I had was that the data, which is a sequence of bytes, is primarily used as a collation key to enable database to sort data based on it and hence do you see any impact if the data type for storing data is changed from VARCHAR to VARCHAR FOR BIT DATA? Specifically do you see the impact like the database does not sort the data in the same order as before, just because the data storage (data type) has been changed from VARCHAR to VARCHAR FOR BIT DATA.

And Thanks again !!.
Reply
  #4  
Old September 11th, 2008, 07:23 PM
Expert
 
Join Date: Nov 2006
Posts: 351
Default

Quote:
Originally Posted by rahulj
do you see any impact if the data type for storing data is changed from VARCHAR to VARCHAR FOR BIT DATA? Specifically do you see the impact like the database does not sort the data in the same order as before, just because the data storage (data type) has been changed from VARCHAR to VARCHAR FOR BIT DATA.
Just guessing this question is way beyond me. I do not use DB2 that often. I would think that changing a key used for sorting from ASCII values to binary could very possibly change the sort order. So I would avoid it if possible. You would need to talk to a DB2 DBA to find out for sure.
Reply
Reply

Bookmarks

Thread Tools

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 Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles