在条件语句和 SET 中使用 DEFAULT 值
DEFAULT 关键字处理有问题
示例:
CREATE TABLE BAR(c1 int null,c2 int default 1 not null)
像这样执行 SQL:
INSERT INTO BAR SET c1 = 1, c2 = COALESCE(null,DEFAULT)
结果为: 未找到“DEFAULT”列; SQL语句: 插入条形图集 c1 = 1,c2 = COALESCE(null,DEFAULT) [42122-161] 42S22/42122
同时:
INSERT INTO BAR (c1,c2) values (1, DEFAULT)
好的!
但是,
INSERT INTO BAR SET c1 = 1, c2 = DEFAULT
结果: 列“C2”不允许为 NULL; SQL语句: INSERT INTO BAR SET c1 = 1, c2 = DEFAULT [23502-161] 23502/23502
我认为这是一个错误。如果不是,有什么方法可以指定使用 默认值存在吗?
H2 1.3.161 (2011-10-28)
There is something wrong with DEFAULT keyword handling
Example:
CREATE TABLE BAR(c1 int null,c2 int default 1 not null)
Executing SQL like this:
INSERT INTO BAR SET c1 = 1, c2 = COALESCE(null,DEFAULT)
Results in:
Column "DEFAULT" not found; SQL statement:
INSERT INTO BAR SET c1 = 1, c2 = COALESCE(null,DEFAULT) [42122-161]
42S22/42122
At the same time:
INSERT INTO BAR (c1,c2) values (1, DEFAULT)
Ok!
But,
INSERT INTO BAR SET c1 = 1, c2 = DEFAULT
Result:
NULL not allowed for column "C2"; SQL statement:
INSERT INTO BAR SET c1 = 1, c2 = DEFAULT [23502-161] 23502/23502
I think it is a bug. If it is not, is any way to specify use of
default value exists?
H2 1.3.161 (2011-10-28)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
术语 DEFAULT 不是伪列或可以在公式中使用的表达式。 DEFAULT 用于而不表达式。我尝试了 MySQL,它的工作方式与 H2 相同。
您可能想要的是使用参数化语句(对吗?),其中 NULL 被转换为默认值。 H2 确实支持这一点,但没有完整记录。您可以使用:
The term DEFAULT isn't a pseudo-column or an expression that can be used in a formula. DEFAULT is used instead of an expression. I tried MySQL and it works in the same way as H2.
What you probably want is use a parameterized statement (right?) where NULL is converted to default. H2 does support this, but it's not fully documented. You can use: