开发者

Apache derby Double datatype - and trying to default it to "null"

Well, I'm a bit puzzeled here, yet it seems to be a really dumb question.

I'm trying to create a table that has a double column that is null by default. What i get is a table with a double column that is 0 by default, and I have no idea why.

The relevant part of the code:

CREATE_TABLE_STATEMENT = "create table " + TABLE_NAME + " 
(id int n开发者_运维技巧ot null generated always as identity constraint pk primary key, 
 parentid int default null, title varchar(50), minimum double default null,
 maximum double default null, timeUnit double default null, 
 comment varchar(150) default null)";

And the corresponding "insert":

"insert into " + TABLE_NAME + " " + "(parentid, title) values (1, 'first')"


Seems to work fine on my copy of Derby (see below).

What makes you think the default of null isn't working properly?

ij> create table xxx (id int not null generated always as identity constraint pk primary key, 
 parentid int default null, title varchar(50), minimum double default null,
 maximum double default null, timeUnit double default null, 
 comment varchar(150) default null) ;
0 rows inserted/updated/deleted
ij> describe xxx;
COLUMN_NAME         |TYPE_NAME|DEC&|NUM&|COLUM&|COLUMN_DEF|CHAR_OCTE&|IS_NULL&
------------------------------------------------------------------------------
ID                  |INTEGER  |0   |10  |10    |AUTOINCRE&|NULL      |NO      
PARENTID            |INTEGER  |0   |10  |10    |NULL      |NULL      |YES     
TITLE               |VARCHAR  |NULL|NULL|50    |NULL      |100       |YES     
MINIMUM             |DOUBLE   |NULL|2   |52    |NULL      |NULL      |YES     
MAXIMUM             |DOUBLE   |NULL|2   |52    |NULL      |NULL      |YES     
TIMEUNIT            |DOUBLE   |NULL|2   |52    |NULL      |NULL      |YES     
COMMENT             |VARCHAR  |NULL|NULL|150   |NULL      |300       |YES     

7 rows selected
ij> insert into xxx (parentid, title) values (1, 'first');
1 row inserted/updated/deleted
ij> select * from xxx;
ID         |PARENTID   |TITLE                                             |MINIMUM               |MAXIMUM               |TIMEUNIT              |COMMENT                                                                                                                         
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1          |1          |first                                             |NULL                  |NULL                  |NULL                  |NULL                                                                                                                            

1 row selected
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜