Vertica copy command with identity column
i created two tables
CREATE TABLE TEST1
(
TEST1_ID identity(1) ,
CHART_TYPE_DESC varchar(100) NOT NULL,
CREATED_BY_ID varchar(50),
MODIFIED_BY_ID varchar(50)
);
CREATE TABLE TEST2
(
TEST2_ID int ,
CHART_TYPE_DESC varchar(100) NOT NULL,
CREATED_BY_ID varchar(50),
MODIFIED_BY_ID varchar(50)
);
When i insert into table TEST1 doesnt work
insert into table test1 values (1,'ABC','A','A');
however taking inputs from
i added SELECT set_optimizer_directives('AllowIdentityInsert=True');
and the insert worked.
However when i tried with copy command it doesnt work and gives error
vsql -U dbadmin -w test -c "SELECT set_optimizer_directives('AllowIdentityInsert=True');COPY test3 FROM '/home/dbadmin/test.csv' delimiter E',' EXCEPTIONS '/home/dbadmin/exceptions';"
COPY: Input record 1 has been rejected (Too many columns found). Please see /home/dbadmin/test/v_test_node0001_catalog/CopyErrorLogs/test3-test.csv-copy-from-rejected-data, record 1 for the rejected record.
however when i insert into table test2 which doesnt have identity column copy command works.
Is there any way to ask copy to ignore identity column and allow insert?
Comments
This is crucial. When importing data from another DBMS, you are more or less obliged to use explicit named sequences instead of identity columns, so you loose all the benefit of the identity columns (you have no last_insert_id(), you have to declare sequences as independent objects, ...). There should definitely be a parameter allowing one to set the values of identity columns.
The reason why it has been implemented this way, something along the lines of people tending to loose confidence in systems where such overwriting of identity columns are possible, is fallacious: you just avoid using identity columns because you want to use the IDs already present in your exports. And there is a plethora of use cases where this limitation is wrong, as long as plenty of other ways to corrupt your data if you really want to.
In brief, it's a real showstopper.
Plus, we know that it's not a low level constraint, but just a design choice, since Vertica is able to copy identity values from one node to another using imports/exports.
Dear Vertica, do something!
@sreeblr - You can load the data into TEST2, connect to the same DB and run a COPY FROM VERTICA to get data int TEST1...
Example:
Then alter the Identity's sequence to restart with the max value for TEST1_ID + 1. Now you can use the identity to insert new values ...