多行插入失败

发布于 2024-12-04 04:08:56 字数 604 浏览 0 评论 0原文

我正在使用 PostgreSQL 7.4.19。为什么我不能使用基本的 SQL 语句作为 INSERT? 我正在运行在线示例(来自博客 'Faster INSERT对于多行'):

create table things (things_id serial primary key, thing text);
insert into things (thing) values ('thing nr. 0'),
('thing nr. 1'),
('thing nr. 2'),
('thing nr. 3');

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

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

我做错了什么?

I'm using PostgreSQL 7.4.19. Why can I not use a basic SQL statement as INSERT?
I am running online examples (from the blog 'Faster INSERT for Multiple Rows'):

create table things (things_id serial primary key, thing text);
insert into things (thing) values ('thing nr. 0'),
('thing nr. 1'),
('thing nr. 2'),
('thing nr. 3');

When I run it, it yields:

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

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁对谁错谁最难过 2024-12-11 04:08:56

它适用于我的 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)

It works for me on PostgreSQL 9.0 , What your PostgreSQL Version?

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文