【问题标题】:Postgres COPY invalid syntax for integerPostgres COPY 整数的无效语法
【发布时间】:2017-08-14 08:37:15
【问题描述】:

我的桌子,

       Table "public.product_status"
 Column |         Type          | Modifiers
--------+-----------------------+-----------
 id     | integer               | not null
 code   | character varying(10) |
 notes  | text                  |

我的 CSV 文件的第一行,

1,S,blah blah blah

复制命令,

=# copy product_status from 'status_table.csv' with csv;
ERROR:  invalid input syntax for integer: "1"
CONTEXT:  COPY product_status, line 1, column id: "1"

真的不明白整数的语法无效! 甚至 postgres 似乎也同意我的观点,

=# insert into product_status values (1,'S','blah blah blah');
=# copy product_status to STDOUT with csv;
1,S,blah blah blah

有什么想法吗?我在网站上发现的其他问题似乎不适用于我在这里做错了什么。

【问题讨论】:

    标签: postgresql


    【解决方案1】:

    文件开头可能有一个“隐形”字符。

    检查内容;如果你在 sume UNIX 上,你可以使用od -c status_table.csv

    文件开头可能有一个无用的byte order mark。只需将其删除。

    【讨论】:

    • 谢谢 Laurenz,我的文件中确实有 BOM!
    • 谢谢 - od -c 非常有用!
    【解决方案2】:

    我也遇到了同样的问题,我的回答和上面一样,“文件开头没用的byte order mark”。这是我删除它的方法。

    1) 在vim中打开文件

    vim file_with_bom.txt
    

    2) 设置“nobomb”选项

    :set nobomb
    

    3) 保存文件并退出

    :wq
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2013-08-20
      • 1970-01-01
      • 2012-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-26
      • 1970-01-01
      • 2016-07-21
      相关资源
      最近更新 更多