我很难将简单的数据输入到postgres表中。
这是表格:
user=# \d main_attribute_types;
Column | Type | Modifiers
------------+-----------------------+-------------------------------------------------------------------
id | integer | not null default nextval('main_attribute_types_id_seq'::regclass)
name | character varying(16) | not null
field_name | character varying(16) | not null
Indexes:
"main_attribute_types_pkey" PRIMARY KEY, btree (id)
Referenced by:
TABLE "main_additional_attributes" CONSTRAINT "main_addi_attribute_type_id_1cb89d3d_fk_main_attribute_types_id" FOREIGN KEY (attribute_type_id) REFERENCES main_attribute_types(id) DEFERRABLE INITIALLY DEFERRED
我试过的命令:
INSERT INTO main_attribute_types (NULL, "Integer", "IntegerField");
INSERT INTO main_attribute_types (1, "Integer", "IntegerField);
INSERT INTO main_attribute_types (id, name, field_name) VALUES (NULL, "Integer", "IntegerField");
INSERT INTO main_attribute_types (name, field_name) VALUES ("Integer", "IntegerField");
每次我收到错误:
ERROR: column "Integer" does not exist
LINE 1: INSERT INTO main_attribute_types VALUES (1, "Integer", "Inte...
^
在官方文档中如何做到这一点: https://www.postgresql.org/docs/9.0/static/dml-insert.html
我的Postgres版本是9.3.13
我完全不知道为什么它不起作用。
答案 0 :(得分:0)
尝试
INSERT INTO main_attribute_types (name, field_name) VALUES ('Integer', 'IntegerField');
请记住,not null为每列定义not null。