1

I have a .txt file with a plain list of words (one word on each line) that I want to copy into a table. The table was created in Rails with one row: 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. Thanks for your help!

1 Answer 1

1

If you created that table in Rails then you almost certainly have two columns, not one. Rails will add an id serial column behind your back unless you tell it not to; 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.

You can tell COPY which column you're importing so that the default id values will be used:

copy dictionaries(word) from ....
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That worked. I deleted the created_at and updated_at columns and used your syntax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.