View previous topic :: View next topic |
Author |
Message |
Bambuk Beginner
Joined: 20 Sep 2008 Posts: 2 Topics: 1
|
Posted: Sun Sep 21, 2008 4:54 pm Post subject: Timestamp and nulls |
|
|
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 |
|
 |
Dibakar Advanced

Joined: 02 Dec 2002 Posts: 700 Topics: 63 Location: USA
|
|
Back to top |
|
 |
Bambuk Beginner
Joined: 20 Sep 2008 Posts: 2 Topics: 1
|
Posted: Sun Sep 21, 2008 7:21 pm Post subject: |
|
|
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 |
|
 |
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Mon Sep 22, 2008 9:09 am Post subject: |
|
|
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 |
|
 |
|
|