Apache derby Double 数据类型 - 并尝试将其默认为“null”

发布于 2024-12-01 17:49:00 字数 564 浏览 4 评论 0原文

嗯,我在这里有点困惑,但这似乎是一个非常愚蠢的问题。

我正在尝试创建一个具有默认为空的双列的表。我得到的是一个双列的表,默认情况下为 0,我不知道为什么。

代码的相关部分:

CREATE_TABLE_STATEMENT = "create table " + TABLE_NAME + " 
(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)";

以及相应的“插入”:

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

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 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)";

And the corresponding "insert":

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜空下最亮的亮点 2024-12-08 17:49:00

似乎在我的 Derby 副本上运行良好(见下文)。

是什么让您认为默认 null 无法正常工作?

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文