PG COPY error: invalid input syntax for integer

前端 未结 12 1782
走了就别回头了
走了就别回头了 2020-12-29 01:02

Running COPY results in ERROR: invalid input syntax for integer: \"\" error message for me. What am I missing?

My /tmp/people.cs

12条回答
  •  悲&欢浪女
    2020-12-29 01:53

    I think it's better to change your csv file like:

    "age","first_name","last_name"
    23,Ivan,Poupkine
    ,Eugene,Pirogov
    

    It's also possible to define your table like

    CREATE TABLE people (
      age        varchar(20),
      first_name varchar(20),
      last_name  varchar(20)
    );
    

    and after copy, you can convert empty strings:

    select nullif(age, '')::int as age, first_name, last_name
    from people
    

提交回复
热议问题