我試圖使用插入「UNNEST」功能,
而這樣做,序列跳過了一些對每個插入,
plz幫助我解決這個...插入與UNNEST功能 - 跳過序列列中的數字
mydb=# \d tab1
Table "public.tab1"
Column | Type | Modifiers
--------+---------+---------------------------------------------------
id | integer | not null default nextval('tab1_id_seq'::regclass)
col1 | integer |
col2 | integer |
Indexes:
"tab1_pkey" PRIMARY KEY, btree (id)
mydb=# insert into tab1(id,col1,col2) values (nextval('tab1_id_seq'),1,unnest(array[4,5]));
INSERT 0 2
mydb=# select * from tab1;
id | col1 | col2
----+------+------
1 | 1 | 4
2 | 1 | 5
(2 rows)
mydb=# insert into tab1(id,col1,col2) values (nextval('tab1_id_seq'),2,unnest(array[4,5]));
INSERT 0 2
mydb=# select * from tab1;
id | col1 | col2
----+------+------
1 | 1 | 4
2 | 1 | 5
4 | 2 | 4
5 | 2 | 5
(4 rows)
mydb=# insert into tab1(col1,col2) values(2,unnest(array[4,5]));
INSERT 0 2
mydb=# select * from tab1;
id | col1 | col2
----+------+------
1 | 1 | 4
2 | 1 | 5
4 | 2 | 4
5 | 2 | 5
7 | 2 | 4
8 | 2 | 5
(6 rows)
mydb=# insert into tab1(col2) values(unnest(array[4,5]));
INSERT 0 2
mydb=# select * from tab1;
id | col1 | col2
----+------+------
1 | 1 | 4
2 | 1 | 5
4 | 2 | 4
5 | 2 | 5
7 | 2 | 4
8 | 2 | 5
10 | | 4
11 | | 5
(8 rows)
mydb=# select nextval('tab1_id_seq');
nextval
---------
13
(1 row)
爲每個插入跳過ID列中的數字,幫我解決這個PLZ ...
感謝它真的不錯...感謝您的快速回復 – MAHI 2012-03-02 08:42:35