create table Portfolio_IDH
(
ANO int,
NOME varchar(30) unique,
IDHM numeric(10,3) not null,
IDHM_L numeric(10,3) not null,
IDHM_E numeric(10,3) not null,
IDHM_R numeric(10,3) not null,
IDHMAD numeric(10,3) not null,
IDHMAD_L numeric (10,3) not null,
IDHMAD_E numeric (10,3) not null,
IDHMAD_R numeric(10,3) not null,
RDPC numeric(10,3),
GINI numeric(10,3),
THEIL numeric(10,3)
);
insert into portfolio_idh(ano)
values (2004);
我是 SQL 初学者,我想了解有关空值的错误。我认为正是由于该错误,我无法导入 Excel 存档。
根据文档:
https://www.postgresql.org/docs/current/sql-createtable.html
默认default_expr [...] 默认表达式将用于任何未指定列值的插入操作。如果某列没有默认值,则默认值为 null。
https://www.postgresql.org/docs/current/sql-insert.html
显式或隐式列列表中不存在的每一列都将填充一个默认值,要么是其声明的默认值,要么是 null(如果没有)。
如果您不想收到错误,您需要:
在具有
DEFAULT
约束的列定义中提供显式 NOT NULL
值,
确保
INSERT
列列表包含 NOT NULL
字段并在 NOT NULL
部分中提供 VALUES()
值。
将表更改为对字段没有
NOT NULL
约束。