Reputation: 79
PostgreSQL version: 9.6
I have a table xyz
with columns a integer
, b integer
, c text
, d integer
.
The column c
has a non-null constraint.
I have a CSV looking like so:
foo.csv
1,4
2,5
3,7
How could I only update column a
and d
by importing the CSV above?
I tried COPY xyz (a,d) FROM '/foo.csv' DELIMITER ',';
but it gave me an error
ERROR: null value in column "c" violates not-null constraint DETAIL: Failing row contains (1, null, null, 4).
Upvotes: 1
Views: 869
Reputation: 121919
Usually, a not null
column should have a default value defined. You can define a default value for an existing column, e.g.
alter table xyz alter c set default '';
After that, the copy command will succeed.
Upvotes: 1