I have situation like my file can have more or less columns than the columns in the table. In copy command column names are fixed that it represent all the columns in the table I cant reduce/increase the columns.
- When I have less data in the file:
File Data: "FC1"|"FC2"
COPY COPY_TEST(TC1,TC2,TC3,TC4) FROM LOCAL 'COPYTEST_LESS_COL' DELIMITER '|' ENCLOSED BY '"' AUTO;
Gives error as "rejected (Too few columns found)"
NOTE: > I have tried by keeping the default values for the columns in table still the same error > FILLER is not supporting :
COPY COPY_TEST(TC1,TC2,TC3 FILLER VARCHAR(255),TC4 FILLER VARCHAR(255)) FROM LOCAL 'COPYTEST_LESS_COL' DELIMITER '|' ENCLOSED BY '"' AUTO; ERROR 2671: Column reference "TC3" is ambiguous DETAIL: Reference "TC3" could refer to either "COPY_TEST.TC3" or "FILLER.TC3"
- When I have more data in the file:
File Data: "FC1"|"FC2"|"FC3"|"FC4"|"FC5"|"FC6"|"FC7"
COPY COPY_TEST(TC1,TC2,TC3,TC4) FROM LOCAL 'COPYTEST_More_COL' DELIMITER '|' ENCLOSED BY '"' AUTO;
Gives error as "rejected (Too many columns found)"
I need any alternative solution to load data.
If the columns change considerably, consider reading this part of the Vertica documentation - on flex tables:
https://docs.vertica.com/23.4.x/en/flex-tables/
If the columns at the beginning are stable, however, and only at the end you might have one, two or three fields added occasionally to the otherwise stable file structure, try this scenario - where I added the data in-line in a sql file to be executed using vsql:
What you get is this: