How to deal with empty values in psycopg copy to from CSV

Viewed 12

I'm using psycopg3 to copy rows from a csv into a SQL table.

But in the CSV are some empty values that are represented with a ' '. So when it gets copied to a int value field, I get a invalid input syntax for type integer: ""

    with conn.cursor() as cur:
                with cur.copy("COPY manycolumns...") FROM STDIN") as copy:
    
                        for line in csv.reader(data):
    
                            print(line)
    
                            copy.write_row(line)

I've tried to turn all empty values in the list to null. But is a very inefficient solution. Is there an argument in how I read the csv that doesn't read empty values?

0 Answers
Related