Geo Joseph
Geo Joseph

Reputation: 55

Syntax error in "psql" , command not get executed

I am using timescaledb.

The doumentation I am following is Using PostgreSQL's COPY to migrate data from a csv file to timescale db. The name of csv file is test.csv.

I created the db named test , the name of table is test1. Table is a hypertable as per the timescaledb documentation.

The table's structure and csv files structure are the same.

While executing the following command in cmd I am not getting a result other than an addition of - symbol in the console command test-#

psql -d test -c "\COPY test1 FROM C:\Users\DEGEJOS\Downloads\test.csv CSV"

NO Response in Console

If I put ; after the command psql -d test -c "\COPY test1 FROM C:\Users\DEGEJOS\Downloads\test.csv CSV"; I am getting a syntax error at Line 1.

Syntax Error

How can I solve this error and insert data from csv file to db.?

Upvotes: 0

Views: 1075

Answers (1)

k_rus
k_rus

Reputation: 3219

You are trying to run psql with \COPY inside psql session, thus you get an error in the second call, since psql keyword does not exist in SQL. psql is an executable.

To follow the instructions from Timescale, you need to call the command directly in CMD. I.e, call:

psql -d test -c "\COPY test1 FROM C:\Users\DEGEJOS\Downloads\test.csv CSV"

If you are in C:\Users\DEGEJOS as in your screenshoot, it will look like:

C:\Users\DEGEJOS\psql -d test -c "\COPY test1 FROM C:\Users\DEGEJOS\Downloads\test.csv CSV"

Upvotes: 1

Related Questions