2

I tried to import csv file data into postgres table. Running the following line as pgscript in pgAdmin

\copy users_page_rank FROM E'C:\\Users\\GamulinN\\Desktop\\users page rank.csv' DELIMITER ';' CSV

it returned an error:

[ERROR    ] 1.0: syntax error, unexpected character

Does anyone know what could be wrong here? I checked this post but couldn't figure out what's the problem.

Community
  • 1
  • 1
Niko Gamulin
  • 63,517
  • 91
  • 213
  • 274

1 Answers1

6

To import file into postgres with COPY you need one of the following:

1) Connect with psql to the DB and run your comand:

\copy users_page_rank FROM E'C:\\Users\\GamulinN\\Desktop\\users page rank.csv' DELIMITER ';' CSV

It will copy the file from current computer to the table. Details here.

2) Connect with any tool to the DB and run this SQL script:

COPY users_page_rank FROM E'C:\\Users\\GamulinN\\Desktop\\users page rank.csv' DELIMITER ';' CSV

It will copy the file from the server with postgres to the table. Details here. (With this command you can only COPY from files in postgresql data directory. So you will need to transfer files there first.)

Igor Romanchenko
  • 22,798
  • 7
  • 40
  • 38