Importing CSV Data into a Postgres Table: A Comprehensive Guide

Feedback

Question:

Attempting to import data from
csv file
into
postgres table
by executing 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

Is there anyone who has knowledge of what may be amiss in this situation? I reviewed this post but was unable to identify the issue.


Solution:

To import a file into Postgres using

COPY

, you must have one of the following options available.

Connect to the DB by using

psql

and execute your command.

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

The file will be transferred from the current computer to the
table. Details
location.

2) Establish a connection with the DB using any tool and execute the provided SQL script.

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

The command will copy the file from the postgres server to the table. More information can be found here. (This command specifically allows for the copying of

COPY

from files in the postgresql data directory. Therefore, it is necessary to transfer the files to that location beforehand.)

Frequently Asked Questions