提交 d8483da0 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Generate SQL for nullable columns with non-nullable domain properly

上级 6c7cf723
...@@ -576,6 +576,8 @@ public class Column { ...@@ -576,6 +576,8 @@ public class Column {
} }
if (!nullable) { if (!nullable) {
buff.append(" NOT NULL"); buff.append(" NOT NULL");
} else if (userDataType != null && !userDataType.getColumn().isNullable()) {
buff.append(" NULL");
} }
if (convertNullToDefault) { if (convertNullToDefault) {
buff.append(" NULL_TO_DEFAULT"); buff.append(" NULL_TO_DEFAULT");
......
...@@ -6,19 +6,24 @@ ...@@ -6,19 +6,24 @@
CREATE DOMAIN E AS ENUM('A', 'B'); CREATE DOMAIN E AS ENUM('A', 'B');
> ok > ok
CREATE TABLE TEST(I INT PRIMARY KEY, E1 E, E2 E NOT NULL); CREATE DOMAIN E_NN AS ENUM('A', 'B') NOT NULL;
> ok > ok
INSERT INTO TEST VALUES (1, 'A', 'B'); CREATE TABLE TEST(I INT PRIMARY KEY, E1 E, E2 E NOT NULL, E3 E_NN, E4 E_NN NULL);
> ok
INSERT INTO TEST VALUES (1, 'A', 'B', 'A', 'B');
> update count: 1 > update count: 1
SELECT COLUMN_NAME, NULLABLE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TEST' ORDER BY ORDINAL_POSITION; SELECT COLUMN_NAME, NULLABLE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TEST' ORDER BY ORDINAL_POSITION;
> COLUMN_NAME NULLABLE COLUMN_TYPE > COLUMN_NAME NULLABLE COLUMN_TYPE
> ----------- -------- ------------ > ----------- -------- -------------
> I 0 INT NOT NULL > I 0 INT NOT NULL
> E1 1 E > E1 1 E
> E2 0 E NOT NULL > E2 0 E NOT NULL
> rows (ordered): 3 > E3 0 E_NN NOT NULL
> E4 1 E_NN NULL
> rows (ordered): 5
DROP DOMAIN E RESTRICT; DROP DOMAIN E RESTRICT;
> exception CANNOT_DROP_2 > exception CANNOT_DROP_2
...@@ -26,13 +31,18 @@ DROP DOMAIN E RESTRICT; ...@@ -26,13 +31,18 @@ DROP DOMAIN E RESTRICT;
DROP DOMAIN E CASCADE; DROP DOMAIN E CASCADE;
> ok > ok
DROP DOMAIN E_NN CASCADE;
> ok
SELECT COLUMN_NAME, NULLABLE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TEST' ORDER BY ORDINAL_POSITION; SELECT COLUMN_NAME, NULLABLE, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TEST' ORDER BY ORDINAL_POSITION;
> COLUMN_NAME NULLABLE COLUMN_TYPE > COLUMN_NAME NULLABLE COLUMN_TYPE
> ----------- -------- ---------------------- > ----------- -------- ----------------------
> I 0 INT NOT NULL > I 0 INT NOT NULL
> E1 1 ENUM('A','B') > E1 1 ENUM('A','B')
> E2 0 ENUM('A','B') NOT NULL > E2 0 ENUM('A','B') NOT NULL
> rows (ordered): 3 > E3 0 ENUM('A','B') NOT NULL
> E4 1 ENUM('A','B')
> rows (ordered): 5
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论