谷歌搜索告诉我尝试这个:
insert into Plan default values;
但我得到了:
null value in column "id" violates not-null constraint
或这个:
insert into Plan (id) values (null);
但我得到了同样的东西。
这些示例适用于 SQL:PostgreSQL 有什么不同吗?
表结构:
create table Plan (
id int4 not null,
primary key (id)
);
您的列不接受 NULL 值(定义not null
),并且您也没有定义默认值。那么你must提供一个integer
value:
insert into plan (id) values (1235); -- any integer value
很可能你真的想要一个serial
列,它从序列中提取默认值:
- 自动递增SQL函数 https://stackoverflow.com/questions/9875223/auto-increment-sql-function/9875517#9875517
您的表格可能如下所示:
CREATE TABLE plan (plan_id serial PRIMARY KEY);
An the INSERT
可能:
INSERT INTO plan DEFAULT VALUES;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)