0

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:

3
  • 2
    PostgreSQL uses COPY not LOAD Commented Sep 22, 2023 at 12:04
  • 1
    Here's the link to the manual, with all the different statements. And LOAD is not one one them: postgresql.org/docs/current/sql-commands.html Commented Sep 22, 2023 at 12:10
  • 1
    COPY doesn't have a SKIP or IGNORE N ROWS option. Is the actual problem how to ignore the header row? In that case you need to use HEADER ON. If you want to match header and column names, HEADER MATCH Commented Sep 22, 2023 at 12:13

3 Answers 3

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);
Sign up to request clarification or add additional context in comments.

Comments

0

You can as well try this query:

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

Comments

0

Thank you!

I tried this and the error pertains - "ERROR: could not open file "/path/to/tripsdata.csv" for reading: No such file or directory HINT: COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy."

Comments

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.