MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Timestamp and nulls

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
Bambuk
Beginner


Joined: 20 Sep 2008
Posts: 2
Topics: 1

PostPosted: Sun Sep 21, 2008 4:54 pm    Post subject: Timestamp and nulls Reply with quote

There is a timestamp column defined to allow nulls (Col_4)

The table looked like this:

Define Table
Col_1 Char (10) not null,
Col_2 Char (5) not null,
Col_3 Timestamp not null,
Col_4 Timestamp,
Col_5 Char (1).

But all the row in the table contain valid data in that column. Does it mean the DB2 would substitute nulls with Current Timestamp or is it just happened that this particular table was populated with good values.


2. There is a code in the program that selects a row (into Var1 thru Var5) and if some conditions are met moves Var4 to Var3 and then updates the table.

IF A = B
Move VAR4 to Var3
......

My concern is that Col_3 does not allow nulls and if COL_4 has nulls, the value of VAR4 would be spaces which will be moved to VAR3. Which in turn will cause an abend on UPDATE since COL_3 does not allow nulls.

Is this a good practice to move value of the column that might have nulls to the column that does not allow nulls? Should not it check if Col_4 is not null and only then move its value to Var3?

It works since currently there are no rows that have nulls and maybe there never will be. Should I make the change just in case or should I leave it alone?

Thanks.
Back to top
View user's profile Send private message
Dibakar
Advanced


Joined: 02 Dec 2002
Posts: 700
Topics: 63
Location: USA

PostPosted: Sun Sep 21, 2008 7:09 pm    Post subject: Reply with quote

You are right, current timestamp is the default value - http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.intro/db2z_defaultvalues.htm
Back to top
View user's profile Send private message Send e-mail
Bambuk
Beginner


Joined: 20 Sep 2008
Posts: 2
Topics: 1

PostPosted: Sun Sep 21, 2008 7:21 pm    Post subject: Reply with quote

Dibakar wrote:
You are right, current timestamp is the default value - http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.intro/db2z_defaultvalues.htm


My understanding is that Current Timestamp is a default when the column is defined as NOT NULL WITH DEFAULT.

But in my case, the column is defined to allow nulls. So is it possible that a timestamp column did not have a timestamp value in it?
Back to top
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Mon Sep 22, 2008 9:09 am    Post subject: Reply with quote

Quote:
So is it possible that a timestamp column did not have a timestamp value in it?


No. A timestamp column will only have a timestamp value, or null. Remember, null is the absence of a value. It is not a value.

If you plan to UPDATE a column defined as NOT NULL using a nullable source column, you should consider using the COALESCE function to control the target column value in the case where the source column is null.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group