473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Should db2 allow this table to be created

Environment: DB2 UDB LUW 8.2

Following problem was submitted.

create table t1 (c1 char(10) not null)

insert into t1 values(default)

This will result in (db2 command line):

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=2,

TABLEID=7606, COLNO=0" is not allowed. SQLSTATE=23502
So the default of an insert is NULL in this case but it is not allowed
and the explanation of the error is quite clear:

"
o The update or insert value was DEFAULT, but the object column
was declared as NOT NULL without WITH DEFAULT in the table
definition. Consequently:

- A default value of NULL cannot be inserted into that
column.

"

Stretching this to it's limits:

should db2 allow to create a table not null without adding a default if
it assumes that the default will be NULL

or

is this a nice trick of db2 to avoid to insert a default (kind of: no
default clause but only possible for not null columns).

or

should there not be a clause: 'no default' , the real trouble is that
in case of static SQL (where the problem submission started from) , the
binder does not detect the statement will fail at runtime.
Bernard Dhooghe

Jul 13 '06 #1
7 3061
Bernard Dhooghe wrote:
Environment: DB2 UDB LUW 8.2

Following problem was submitted.

create table t1 (c1 char(10) not null)

insert into t1 values(default)

This will result in (db2 command line):

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=2,

TABLEID=7606, COLNO=0" is not allowed. SQLSTATE=23502
So the default of an insert is NULL in this case but it is not allowed
and the explanation of the error is quite clear:

"
o The update or insert value was DEFAULT, but the object column
was declared as NOT NULL without WITH DEFAULT in the table
definition. Consequently:

- A default value of NULL cannot be inserted into that
column.

"

Stretching this to it's limits:

should db2 allow to create a table not null without adding a default if
it assumes that the default will be NULL

or

is this a nice trick of db2 to avoid to insert a default (kind of: no
default clause but only possible for not null columns).

or

should there not be a clause: 'no default' , the real trouble is that
in case of static SQL (where the problem submission started from) , the
binder does not detect the statement will fail at runtime.
In earlier version DB2 for LUW refused to compile that INSERT statement,
but consider this:
CREATE TRIGGER trg1 BEFORE INSERT ON T1 REFERENCING NEW AS N
FOR EACH ROW
SET n.c1 = COALECSE(n.c1, RAND() * 100);

Now your INSERT will succeed.
Now of course the CREATE TABLE doesn't know what your plans are for the
triggers and the INSERT should not be in the business of guessing what a
trigger would do.

from another point of view NOT NULL in the SQL Standard is defined as a
constraint. Constraints are checked at runtime after before triggers are
fired.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Jul 13 '06 #2
Use
create table t1 (c1 char(10) not null with default)
then when "insert into t1 values(default)"
DB2 will know what is the default value.
Serge Rielau wrote:
Bernard Dhooghe wrote:
Environment: DB2 UDB LUW 8.2

Following problem was submitted.

create table t1 (c1 char(10) not null)

insert into t1 values(default)

This will result in (db2 command line):

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=2,

TABLEID=7606, COLNO=0" is not allowed. SQLSTATE=23502
So the default of an insert is NULL in this case but it is not allowed
and the explanation of the error is quite clear:

"
o The update or insert value was DEFAULT, but the object column
was declared as NOT NULL without WITH DEFAULT in the table
definition. Consequently:

- A default value of NULL cannot be inserted into that
column.

"

Stretching this to it's limits:

should db2 allow to create a table not null without adding a default if
it assumes that the default will be NULL

or

is this a nice trick of db2 to avoid to insert a default (kind of: no
default clause but only possible for not null columns).

or

should there not be a clause: 'no default' , the real trouble is that
in case of static SQL (where the problem submission started from) , the
binder does not detect the statement will fail at runtime.
In earlier version DB2 for LUW refused to compile that INSERT statement,
but consider this:
CREATE TRIGGER trg1 BEFORE INSERT ON T1 REFERENCING NEW AS N
FOR EACH ROW
SET n.c1 = COALECSE(n.c1, RAND() * 100);

Now your INSERT will succeed.
Now of course the CREATE TABLE doesn't know what your plans are for the
triggers and the INSERT should not be in the business of guessing what a
trigger would do.

from another point of view NOT NULL in the SQL Standard is defined as a
constraint. Constraints are checked at runtime after before triggers are
fired.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Jul 13 '06 #3
Bernard Dhooghe wrote:
Environment: DB2 UDB LUW 8.2

Following problem was submitted.

create table t1 (c1 char(10) not null)

insert into t1 values(default)

This will result in (db2 command line):

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=2,

TABLEID=7606, COLNO=0" is not allowed. SQLSTATE=23502
So the default of an insert is NULL in this case but it is not allowed
and the explanation of the error is quite clear:

"
o The update or insert value was DEFAULT, but the object column
was declared as NOT NULL without WITH DEFAULT in the table
definition. Consequently:

- A default value of NULL cannot be inserted into that
column.

"

Stretching this to it's limits:

should db2 allow to create a table not null without adding a default if
it assumes that the default will be NULL
No, there is no reason to be so restrictive there. Your applications could
always provide a value to be inserted, so that the NOT NULL constraint has
no effect on the apps.
or

is this a nice trick of db2 to avoid to insert a default (kind of: no
default clause but only possible for not null columns).
Default and NOT NULL are two different, orthogonal things. If you don't
specify an explicit default, then NULL is used. If that doesn't match with
your table definition, it is up to you how to handle it (in the app or via
triggers).
or

should there not be a clause: 'no default' , the real trouble is that
in case of static SQL (where the problem submission started from) , the
binder does not detect the statement will fail at runtime.
"No default" would mean (to me) that there is "no default value". An the
absence of a value is represented by NULL. So you will be exactly at the
same point again.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Jul 14 '06 #4
Nice background information, thank you Serge.

Remark: So if no triggers are present for the table and a static insert
is made as described, the binder could check at bind time if the insert
is valid or not even if the run-tme check remains active as explained
in the answer.

Bernard Dhooghe

Serge Rielau wrote:
Bernard Dhooghe wrote:
Environment: DB2 UDB LUW 8.2

Following problem was submitted.

create table t1 (c1 char(10) not null)

insert into t1 values(default)

This will result in (db2 command line):

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=2,

TABLEID=7606, COLNO=0" is not allowed. SQLSTATE=23502
So the default of an insert is NULL in this case but it is not allowed
and the explanation of the error is quite clear:

"
o The update or insert value was DEFAULT, but the object column
was declared as NOT NULL without WITH DEFAULT in the table
definition. Consequently:

- A default value of NULL cannot be inserted into that
column.

"

Stretching this to it's limits:

should db2 allow to create a table not null without adding a default if
it assumes that the default will be NULL

or

is this a nice trick of db2 to avoid to insert a default (kind of: no
default clause but only possible for not null columns).

or

should there not be a clause: 'no default' , the real trouble is that
in case of static SQL (where the problem submission started from) , the
binder does not detect the statement will fail at runtime.
In earlier version DB2 for LUW refused to compile that INSERT statement,
but consider this:
CREATE TRIGGER trg1 BEFORE INSERT ON T1 REFERENCING NEW AS N
FOR EACH ROW
SET n.c1 = COALECSE(n.c1, RAND() * 100);

Now your INSERT will succeed.
Now of course the CREATE TABLE doesn't know what your plans are for the
triggers and the INSERT should not be in the business of guessing what a
trigger would do.

from another point of view NOT NULL in the SQL Standard is defined as a
constraint. Constraints are checked at runtime after before triggers are
fired.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Jul 17 '06 #5
Bernard Dhooghe wrote:
Nice background information, thank you Serge.

Remark: So if no triggers are present for the table and a static insert
is made as described, the binder could check at bind time if the insert
is valid or not even if the run-tme check remains active as explained
in the answer.
DB2 for LUW compiles triggers into the insert statement (same with
check, RI, etc). So when you add/drop a trigger that will cause a rebind.
However the trigger could retrive the (not null) value from an external
UDF, completely outside the control of DB2. So whatever we do there is a
hole in what the compiler can control.
Further more, if one is very picky, the fact that NOT NULL is a
constraint, which must fire after the INSERT itself one can argue that
it must not mask any other errors which would show up prior. Let's say a
truncation or overflow in another column.
Most customers don't get excited about these sort of things, but from my
10 years in the SQL compiler I've learned the hard way that whenever the
language gets sloppy on the fringes it unravels like a badly knit
sweater. On the other hand then I could make a living explaining what
"LATERAL" and other gorpy stuff is all about. ;-)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Jul 17 '06 #6
Great, thanks.

Remark: Maybe the binder could issue an error when there is no trigger
that could change the inserted value, in this case, 'default' which is,
as there is no default defined, a NULL value but this is not allowed by
the table definition/constraint. Kind of: trust but check. As early as
possible. And just issue a warning when there is a trigger that the
binder can not detect the result of.

Bernard Dhooghe

Serge Rielau wrote:
Bernard Dhooghe wrote:
Nice background information, thank you Serge.

Remark: So if no triggers are present for the table and a static insert
is made as described, the binder could check at bind time if the insert
is valid or not even if the run-tme check remains active as explained
in the answer.
DB2 for LUW compiles triggers into the insert statement (same with
check, RI, etc). So when you add/drop a trigger that will cause a rebind.
However the trigger could retrive the (not null) value from an external
UDF, completely outside the control of DB2. So whatever we do there is a
hole in what the compiler can control.
Further more, if one is very picky, the fact that NOT NULL is a
constraint, which must fire after the INSERT itself one can argue that
it must not mask any other errors which would show up prior. Let's say a
truncation or overflow in another column.
Most customers don't get excited about these sort of things, but from my
10 years in the SQL compiler I've learned the hard way that whenever the
language gets sloppy on the fringes it unravels like a badly knit
sweater. On the other hand then I could make a living explaining what
"LATERAL" and other gorpy stuff is all about. ;-)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Jul 18 '06 #7
Bernard Dhooghe wrote:
Great, thanks.

Remark: Maybe the binder could issue an error when there is no trigger
that could change the inserted value, in this case, 'default' which is,
as there is no default defined, a NULL value but this is not allowed by
the table definition/constraint. Kind of: trust but check. As early as
possible. And just issue a warning when there is a trigger that the
binder can not detect the result of.
We were considering it, but decided against it. Too twisted.
Note that DB2 is the exception when it comes to static SQL. Most DBMS
don't have the concept of a BIND statement and packages.
Being different in itself can be bad.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Jul 18 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
3
by: ytrewq | last post by:
Should dynamic ("expando") properties be restricted to native and user-defined objects? Or should host objects - such as references to the browser or a plug-in or to the document and its elements -...
14
by: ford_desperado | last post by:
Why isn't ALLOW REVERSE SCANS the default? Why do we have to - drop PK - create an index - recreate PK What are the advantages of indexes that do not allow reverse scans?
3
by: D. Shane Fowlkes | last post by:
Sorry for the length of this post. I have created a rather complex form which has a header/line item (parent and child records) structure. It's for an intranet. A screenshot can be seen here: ...
1
by: Leif K-Brooks | last post by:
I've been programming web applications in PHP/MySQL for a few years. It's worked decently, but I've been getting annoyed with the lack of more advanced features lately. After some reading, I've...
0
by: Jim | last post by:
I am trying to add records to a table using a windows form created in vb with a dataset object. I have dragged and dropped the fields I want onto my form. A BindingNavigator is created and am...
0
by: Jim | last post by:
I am trying to add records to a table using a windows form created in vb with a dataset object. I have dragged and dropped the fields I want onto my form. A BindingNavigator is created and am...
59
by: phil-news-nospam | last post by:
In followups by Brian O'Connor (ironcorona) to other posts, he repeats the idea that using tables in CSS is not something that should be done because IE doesn't support it. Of course I'm not happy...
49
by: ARC | last post by:
Hello all, I have one chance to get this right, as I'm nearing a release of a program. I've looked at the database settings, and so far, have set the following: * Unchecked 'Enable design...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.