2011-09-13 119 views
0

我正在使用PostgreSQL 7.4.19。爲什麼我不能使用基本的SQL語句作爲INSERT? 我正在網上的例子(從博客'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'); 

當我運行它,它產生:

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

我在做什麼錯?

+2

做一個'選擇版本();'從裏面'psql'或運行'PSQL --version'檢查你使用的PostgreSQL的版本。 –

+0

適合我。 ver 8.3 – Bohemian

+0

在9.0和9.1中適用於我。肯定有你沒有向我們展示的東西。 –

回答

1

它適用於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)