Megha
Megha

Reputation: 1

importing data from csv file in remote machine to postgresql table

How can i use copy command for bulk insertion of data into postgresql table from csv file present in remote machine using C#? I've a front end in C# using which i need to load data into postgresql table from csv file. The database is in remote server and the csv file is in my machine.

Upvotes: 0

Views: 1511

Answers (2)

Craig Ringer
Craig Ringer

Reputation: 324821

Assuming the CSV file is on the machine running the C# program, you need to use COPY ... FROM STDIN. This is difficult to use directly from client drivers, but most of them support their own interfaces on top.

I'm guessing you are using nPgSQL since you didn't bother to mention what client you're using. If so, you can use NpgsqlCopyIn.

Upvotes: 1

Bruno
Bruno

Reputation: 641

Not possible at all, unless you mount the remote machine on the postgres server. To copy postgres needs to be able to access the file locally.

You could try to scp the file from A to B, or parse the file yourself and do bulk inserts into postgres, ie: create table file (structure of the file); Read 100 lines insert into tabe file values (line 1) ,(line 2) ... ,line (100)

Upvotes: 0

Related Questions