简体   繁体   English

PSQL:COPY上整数的无效输入语法

[英]PSQL: Invalid input syntax for integer on COPY

I have a .txt file with a plain list of words (one word on each line) that I want to copy into a table. 我有一个.txt文件,其中包含要复制到表格中的单词的简单列表(每行一个单词)。 The table was created in Rails with one row: t.string "word". 该表是在Rails中创建的,具有一行:t.string“ word”。

The same file loaded into another database/table worked fine, but in this case I get: 加载到另一个数据库/表中的相同文件工作正常,但是在这种情况下,我得到:

pg_fix_development=# COPY dictionaries FROM '/Users/user/Documents/en.txt' USING DELIMITERS ' ' WITH NULL as '\null';
ERROR:  invalid input syntax for integer: "aa"
CONTEXT:  COPY dictionaries, line 1, column id: "aa"

I did some googling on this but can't figure out how to fix it. 我对此进行了一些谷歌搜索,但不知道如何解决。 I'm not well versed in SQL. 我不太熟悉SQL。 Thanks for your help! 谢谢你的帮助!

If you created that table in Rails then you almost certainly have two columns, not one. 如果在Rails中创建了该表,则几乎可以肯定有列,而不是一列。 Rails will add an id serial column behind your back unless you tell it not to; Rails会在您的背后添加一个id serial列,除非您告知不要这样做; this also explains your "input syntax for integer" error: COPY is trying to use the 'aa' string from your text file as a value for the id column. 这也解释了“整数的输入语法”错误:COPY试图将文本文件中的'aa'字符串用作id列的值。

You can tell COPY which column you're importing so that the default id values will be used: 您可以告诉COPY您要导入的列,以便使用默认的id值:

copy dictionaries(word) from ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM