0

I am going through an SQL course that tasks me with the exercise of importing data from a CSV file, into an existing SQL database. The syntax has been described to me as follows:

COPY *table_name* FROM '*file path*' DELIMITER "," CSV HEADER;

However, this syntax results in a syntax error every time.

Execution finished with errors.
Result: near "COPY": syntax error
At line 1:
COPY

I guess this course is wrong, as there must be a way to do this and this is not the correct syntax to use. I looked up other possible syntax choices, including COPY INTO but that also produces an error. What would be the ideal syntax for this function?

  • 2
    SQL is not a standard language. Things that work in a database from one vendor do NOT work in a database made by a different vendor. What database does the course use? And which one are you using? For example, it looks like your copy command would work in PostgreSQL: https://stackoverflow.com/questions/17662631/how-to-copy-from-csv-file-to-postgresql-table-with-headers-in-csv-file https://stackoverflow.com/questions/2987433/how-to-import-csv-file-data-into-a-postgresql-table – Jerry Jeremiah May 25 '21 at 03:16
  • 1
    In case you are using PostgreSQL. here is the documentation for the COPY command from PostreSQL: https://www.postgresql.org/docs/10/sql-copy.html – Jerry Jeremiah May 25 '21 at 03:20
  • I see, well I was not aware of that. The course uses PostgreSQL, but I couldn't get the server to work so I was just using DB Browser for SQLite - assuming that it was a standard language. Now I see why this question wasn't really asked before - to many possible answers. Thanks for the direction and insight. – spareTimeCoder May 25 '21 at 03:21
  • 1
    Here is how SQLite does it: https://sqlite.org/csv.html Or you can import a CSV using SQLite's command line: https://sqlite.org/cli.html#importing_csv_files The import method also works with DB Browser http://cs-people.bu.edu/dgs/courses/cs105/problem_sets/import_sqlite.shtml https://www.sqlitetutorial.net/sqlite-import-csv/ – Jerry Jeremiah May 25 '21 at 03:32

0 Answers0