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 > Insert NULL value for timestamp

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-03-09, 08:47
vivek.vivek vivek.vivek is offline
Registered User
 
Join Date: Jan 2009
Posts: 27
Question Insert NULL value for timestamp

I need to insert a null value for a timestamp column(which is nullable), before submitting a approval request.
I want that colum to be populated only after the request is approved.

Can anyone suggest the format to insert null data?

I tried like this

TIMESTAMP(CAST('' AS VARCHAR(10)),'00:00:00')

But not working

Thanks in advance
Vivek
Reply With Quote
  #2 (permalink)  
Old 02-03-09, 09:12
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Null values are represented, surprisingly, with the NULL keyword, not with empty strings or zeroes.
Reply With Quote
  #3 (permalink)  
Old 02-03-09, 11:10
rajinbits rajinbits is offline
Registered User
 
Join Date: Nov 2007
Posts: 26
You can use the following:
insert into <tabname> (colname) values (cast (null as timestamp));
Reply With Quote
  #4 (permalink)  
Old 02-03-09, 14:31
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Yes, you can. But there is no need for the CAST because DB2 is able to figure out the target data type from the column into which you insert.

Btw, it is a common misconception to equate empty strings with NULL. Both are very different things and should not be intermixed.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 02-03-09, 17:09
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by vivek.vivek
I need to insert a null value for a timestamp column(which is nullable)
If the column was declared as nullable but without a default (at CREATE TABLE), just don't insert into that column.
Suppose you have a table with two text columns A and B, and a timestamp column T:
Code:
INSERT INTO mytable(a, b) VALUES ('value for a', 'value for b')
If on the other hand T was declared as "WITH DEFAULT", you'll have to say
Code:
INSERT INTO mytable(a, b, t) VALUES ('value for a', 'value for b', NULL)
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
  #6 (permalink)  
Old 02-24-09, 06:01
camaleonx camaleonx is offline
Registered User
 
Join Date: Feb 2009
Posts: 1
I prove whith CAST(NULL AS CHAR(26)) in INSERT and was good.

My field TimeStap without NULL was:
SELECT CURRENT TIMESTAMP FROM DBA1.TCAMALEON FETCH FIRST 5 ROWS ONLY
--------------------------
2009-02-24-11.43.59.325727
2009-02-24-11.43.59.325727
2009-02-24-11.43.59.325727
2009-02-24-11.43.59.325727
2009-02-24-11.43.59.325727

Last edited by camaleonx; 02-24-09 at 06:08.
Reply With Quote
  #7 (permalink)  
Old 02-24-09, 08:06
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Or you use the following:
Code:
INSERT INTO mytable(a, b, t) VALUES ('value for a', 'value for b', DEFAULT)
Btw, this also works if you have no default specified:
Code:
INSERT INTO mytable(a, b, t) VALUES ('value for a', 'value for b', NULL)
p.s: Some DBMS think that you really want to insert the current timestamp instead of NULL. That's not conforming to the SQL standard and DB2 doesn't do it either.
__________________
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