I’m trying to add a fixed value in the method copy.
There is a csv file, but in addition to the data from it, I want to add a fixed value to the table.
In vertica there is column‑as‑expression.
create table if not exists public.test
(
ID int,
OPTION_TYPE varchar(500),
dttm date,
NUM_CSV int
)
Copy:
COPY public.test(
ID,OPTION_TYPE,DTTM,
NUM_CSV AS 1
)
FROM STDIN
WITH (FORMAT CSV)
I tried to do it via query, but it didn’t work.
2
Answers
Randomly inventing new syntax is rarely the path to success.
The only way I can think of is changing the default value:
Then omit that column in the
COPY
statement:You can achieve this by by providing the fixed value directly in the COPY command.
The query is as follows:
Use the COPY command to load data from the CSV file into the table. Then, you run an UPDATE statement to set the value of NUM_CSV to 1 for all rows in the table.