user101289
user101289

Reputation: 10422

Syntax error in COPY FROM thrown by postgres

I'm trying to import data from a pipe-delimited text file into my Postgres data_master table. My command looks like this:

COPY data_master FROM '/Users/me/Documents/DATA/39079.txt' 
    WITH FORMAT csv, 
    DELIMITER '|', 
    HEADER TRUE;

Here's the error:

temp=# COPY data_master FROM '/Users/me/Documents/DATA/39079.txt' WITH FORMAT csv, DELIMITER '|', HEADER TRUE;
ERROR:  syntax error at or near "FORMAT"
LINE 1: .../me/Documents/DATA/39079.txt' WITH FORMAT csv...
                                              ^
temp=# show server_version;
-[ RECORD 1 ]--+-----
server_version | 10.1

From the docs this seems like a valid syntax for the command. What did I do wrong?

EDIT: I tried this after removing the commas as well, with the same results:

temp=# COPY data_master FROM '/Users/me/Documents/DATA/39079.txt' WITH FORMAT CSV DELIMITER '|' HEADER TRUE;
ERROR:  syntax error at or near "FORMAT"
LINE 1: .../me/Documents/DATA/39079.txt' WITH FORMAT CSV...
                                              ^

Upvotes: 2

Views: 149

Answers (1)

Thom Brown
Thom Brown

Reputation: 2029

The syntax following WITH should be in parentheses.

COPY data_master FROM '/Users/me/Documents/DATA/39079.txt' 
  WITH (
    FORMAT csv, 
    DELIMITER '|', 
    HEADER TRUE
  );

Upvotes: 2

Related Questions