你问:
如果我手动更新序列号获得的记录数执行COPY后?
是的,你应该为documented here:
更新一个COPY FROM后的序列值:
| BEGIN;
| COPY distributors FROM 'input_file';
| SELECT setval('serial', max(id)) FROM distributors;
| END;
你写:
它没有增加在正常复制的做工精细期间顺序ID插入
但事实并非如此! :)当你执行一个正常的INSERT时,通常你不会为SEQUENCE支持的主键指定一个明确的值。如果你没有,你会因为你现在有运行到同一个问题:
postgres=> create table uh_oh (id serial not null primary key, data char(1));
NOTICE: CREATE TABLE will create implicit sequence "uh_oh_id_seq" for serial column "uh_oh.id"
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index "uh_oh_pkey" for table "uh_oh"
CREATE TABLE
postgres=> insert into uh_oh (id, data) values (1, 'x');
INSERT 0 1
postgres=> insert into uh_oh (data) values ('a');
ERROR: duplicate key value violates unique constraint "uh_oh_pkey"
DETAIL: Key (id)=(1) already exists.
你COPY命令,当然是提供一个明确的id
值,就像例如在上方插入。
感谢您的想法! – siva 2012-02-01 06:45:07
将会工作的+1 – pilcrow 2012-02-02 21:05:56