skip to Main Content

I was creating table name "tripsdata" in SQL query tool, which is done successfully. Now I have to insert values into the table and I used the below syntax :

LOAD data INFILE 'tripsdata.csv' 
INTO TABLE tripsdata
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"' LINES TERMINATED BY 'n'
IGNORE 1 ROWS;

It keeps giving me error – "ERROR: syntax error at or near "data"
LINE 2: LOAD data INFILE ‘tripsdata.csv’ "

Can you share the error and rectification?

tried what I mentioned above. I want to create this table using SQL query:

2

Answers


  1. LOAD DATA is a MySQL command. PostgresSQL uses COPY. I suspect what you’re trying to do is import a CSV file while skipping the header row. You can do that with the FORMAT CSV and HEADER ON options:

    COPY country 
    FROM '/path/to/tripsdata.csv' 
    (FORMAT CSV,HEADER ON);
    
    Login or Signup to reply.
  2. You can as well try this query:

    COPY tripsdata FROM 'tripsdata.csv' WITH CSV HEADER;

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search