debugsqlModerate
PostgreSQL import CSV File causes Syntax Error
Viewed 0 times
postgresqlfileerrorcsvsyntaximportcauses
Problem
I'm attempting to import a CSV file into a database via the "COPY" command; however, I get the (what seems common) error that I need to be a superuser and that I should use "\copy" instead. However, when using \copy, I get a syntax error:
With the caret pointing to "\". Here's my query:
I tried both "copy" and "\copy". The first giving me a superuser error the latter giving me that syntax error. Any idea on how to fix it? make it work?
I'm executing the command via myPgAdmin's sql input field.
The only other question I have is concerning the importing of the columns via tablename(column2, column3 and so on. Is that the correct syntax for that?
ERROR: syntax error at or near "\"
LINE 1: \copyWith the caret pointing to "\". Here's my query:
\copy tablename(column2, column3, column4, column5) from '/home/uploads/data.csv' WITH DELIMITER ',' CSV HEADER'I tried both "copy" and "\copy". The first giving me a superuser error the latter giving me that syntax error. Any idea on how to fix it? make it work?
I'm executing the command via myPgAdmin's sql input field.
The only other question I have is concerning the importing of the columns via tablename(column2, column3 and so on. Is that the correct syntax for that?
Solution
\copy is a psql (commandline) command. It is not a regular SQL command. You will need to use COPY instead (but that requires the file to be present on the database server)
Context
StackExchange Database Administrators Q#23036, answer score: 10
Revisions (0)
No revisions yet.