How to import fields (such as IDS) with AUTO_INCREMENT constraints from other databases to Vertic

Source: Internet
Author: User
If you create a table with the AUTO_INCREMENT constraint field (ID) in the Vertica database, due to the limitations of the AUTO_INCREMENT constraint, the COPY operation will fail due to conflicts during data import. After analysis and test, create a SEQUENCE, create a table, and set the default value of the ID field to NEXTVAL (schemaname. sequencenam

If you create a table with the AUTO_INCREMENT constraint field (ID) in the Vertica database, due to the limitations of the AUTO_INCREMENT constraint, the COPY operation will fail due to conflicts during data import. After analysis and test, create a SEQUENCE, create a table, and set the default value of the ID field to NEXTVAL ('schemaname. sequencenam

If you create a table with the AUTO_INCREMENT constraint field (ID) in the Vertica database, due to the limitations of the AUTO_INCREMENT constraint, the COPY operation will fail due to conflicts during data import.

After analysis and test, you can create a SEQUENCE, create a table, and set the default value of the ID field to NEXTVAL ('schemaname. sequencename') to COPY the data of the AUTO_INCREMENT constraint field.The procedure is as follows:

1. Create a SEQUENCE:

Create SEQUENCE public. mytab_id_seq;

2. Create a table:
Create table if not exists public. mytab (
Id bigint not null default nextval ('Public. mytab_id_seq ') unique primary key,
...
);

3. import data:
Copy public. mytab (we_id,...) from '/home/username/mytab.csv' DELIMITER '| ';

4. Maximum query ID:

Select max (id) from mytab;

5. Modify the initial value of SEQUENCE to the maximum value of ID (such as 720 ):

Alter sequence public. mytab_id_seq restart with 720;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.