Postgresql 多行插入失败

Postgresql 多行插入失败,postgresql,insert,multiline,Postgresql,Insert,Multiline,我正在使用PostgreSQL 7.4.19。为什么我不能使用基本SQL语句作为INSERT? 我正在运行博客中的在线示例: 当我运行它时,它会产生: ERROR: syntax error at or near "," LINE 1: insert into things (thing) values ('thing nr. 0'), ^ 我做错了什么?它在PostgreSQL

我正在使用PostgreSQL 7.4.19。为什么我不能使用基本SQL语句作为INSERT? 我正在运行博客中的在线示例:

当我运行它时,它会产生:

ERROR:  syntax error at or near ","
LINE 1: insert into things (thing) values ('thing nr. 0'),
                                                         ^

我做错了什么?

它在PostgreSQL 9.0上对我有效,您的PostgreSQL版本是什么

skytf=> create table things (things_id serial primary key, thing text); NOTICE: CREATE TABLE will create implicit sequence "things_things_id_seq" for serial column "things.things_id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "things_pkey" for table "things" CREATE TABLE skytf=> \d things Table "skytf.things" Column | Type | Modifiers -----------+---------+------------------------------------------------------------ things_id | integer | not null default nextval('things_things_id_seq'::regclass) thing | text | Indexes: "things_pkey" PRIMARY KEY, btree (things_id) skytf=> insert into things (thing) values ('thing nr. 0'), skytf-> ('thing nr. 1'), skytf-> ('thing nr. 2'), skytf-> ('thing nr. 3'); INSERT 0 4 skytf=> select version(); version ------------------------------------------------------------------------------------------------------------------- PostgreSQL 9.0.1 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48), 64-bit (1 row)
做一个选择版本;从psql内部或运行psql-version来检查您使用的是哪个PostgreSQL版本。在9.0和9.1中对我有效。一定有什么东西你没有给我们看。我猜我的服务提供商运行的PostgreSQL版本太旧了,不适合7.4.19。看起来我暂时需要很多insert语句。支持这种语法的第一个版本是。 skytf=> create table things (things_id serial primary key, thing text); NOTICE: CREATE TABLE will create implicit sequence "things_things_id_seq" for serial column "things.things_id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "things_pkey" for table "things" CREATE TABLE skytf=> \d things Table "skytf.things" Column | Type | Modifiers -----------+---------+------------------------------------------------------------ things_id | integer | not null default nextval('things_things_id_seq'::regclass) thing | text | Indexes: "things_pkey" PRIMARY KEY, btree (things_id) skytf=> insert into things (thing) values ('thing nr. 0'), skytf-> ('thing nr. 1'), skytf-> ('thing nr. 2'), skytf-> ('thing nr. 3'); INSERT 0 4 skytf=> select version(); version ------------------------------------------------------------------------------------------------------------------- PostgreSQL 9.0.1 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48), 64-bit (1 row)