0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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)

1 Comment

Nonsense, COPY ... FROM STDIN is for exactly this purpose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.