Mridul-Acharya
Mridul-Acharya

Reputation: 11

import data from csv file in Postgres

ERROR:  could not open file "C:\Program Files\PostgreSQL\10\data\Data_copy\student.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.
SQL state: 58P01

Upvotes: 0

Views: 3858

Answers (2)

pifor
pifor

Reputation: 7892

The error message says it all.

If you use SQL COPY command the file to be loaded must be accessible on database server side.

If this is not possible you can use psql CLI \copy command from the client side because it can access a file on client side.

Example:

$ cat t.csv
1,ONE
2,TWO
3,THREE

In psql:

# \d t
                     Table "public.t"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 x      | integer |           |          | 
 y      | text    |           |          | 


# \copy t from 't.csv' delimiter ',';
COPY 3

# select * from t;
 x |   y   
---+-------
 1 | ONE
 2 | TWO
 3 | THREE
(3 rows)

Upvotes: 2

Wize
Wize

Reputation: 1090

Using psql run the following command

\copy students from 'C:\Program Files\PostgreSQL\10\data\Data_copy\student.csv' csv;

Upvotes: 0

Related Questions