I\'m trying to restore my dump file, but it caused an error:
psql:psit.sql:27485: invalid command \\N
Is there a solution? I searched, but
In my recent experience, it's possible to get this error when the real problem has nothing to do with escape characters or newlines. In my case, I had created a dump from database A with
pg_dump -a -t table_name > dump.sql
and was trying to restore it to database B with
psql < dump.sql
(after updating the proper env vars, of course)
What I finally figured out was that the dump, though it was data-only
(the -a
option, so that the table structure isn't explicitly part of the dump), was schema-specific. That meant that without manually modifying the dump, I couldn't use a dump generated from schema1.table_name
to populate schema2.table_name
. Manually modifying the dump was easy, the schema is specified in the first 15 lines or so.
Same thing was happened to me today. I handled issue by dumping with --inserts command.
What I do is:
1) pg_dump with inserts:
pg_dump dbname --username=usernamehere --password --no-owner --no-privileges --data-only --inserts -t 'schema."Table"' > filename.sql
2) psql (restore your dumped file)
psql "dbname=dbnamehere options=--search_path=schemaname" --host hostnamehere --username=usernamehere -f filename.sql >& outputfile.txt
Note-1 ) Make sure that adding outputfile will increase speed of import.
Note-2 ) Do not forget to create table with exact same name and columns before importing with psql.