Home > Database > Mysql Tutorial > 如何把其他数据库中AUTO_INCREMENT约束的字段(如ID)导入Vertic

如何把其他数据库中AUTO_INCREMENT约束的字段(如ID)导入Vertic

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:55:45
Original
1213 people have browsed it

如果在Vertica数据库在建一张同样带AUTO_INCREMENT约束字段(ID)的表,由于AUTO_INCREMENT约束的限制,COPY导入数据时会发生冲突,导致COPY执行失败。 经过分析研究及测试,先创建SEQUENCE,然后创建表并设置ID字段的缺省为NEXTVAL('schemaname.sequencenam

如果在Vertica数据库在建一张同样带AUTO_INCREMENT约束字段(ID)的表,由于AUTO_INCREMENT约束的限制,COPY导入数据时会发生冲突,导致COPY执行失败。

经过分析研究及测试,先创建SEQUENCE,然后创建表并设置ID字段的缺省值为NEXTVAL('schemaname.sequencename'),就可COPY导入AUTO_INCREMENT约束字段的数据。步骤如下:

1、创建SEQUENCE:

create SEQUENCE public.mytab_id_seq;

2、创建表:
CREATE TABLE IF NOT EXISTS public.mytab (
id bigint NOT NULL DEFAULT NEXTVAL('public.mytab_id_seq') UNIQUE PRIMARY KEY,
...
);

3、导入数据:
copy public.mytab ( we_id,...) from '/home/username/mytab.csv' DELIMITER '|';

4、查询ID的最大值:

select max(id) from mytab;

5、修改SEQUENCE的初始值为ID的最大值(如720):

ALTER SEQUENCE public.mytab_id_seq RESTART WITH 720;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template