Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use 'COPY' command(PostgreSQL) in windows cli?

Tags:

postgresql

Trying to use 'copy' command of PostgreSQL in windows cli command:

COPY myTable FROM value.txt (DELIMITER('|'));

I can't find 'copy' executable file in bin directory.

Can you let me know how can I run 'copy' command in cli?

Added: My windows application is going to use the 'Copy' feature. Need to run it directly from Application.

Thanks in advance.

I could manage to see my required result with following approach.

psql.exe -f copy.sql -p 5433 -U user -s postgres

copy.sql
\copy TARGET_TABLE FROM source.txt (DELIMITER('#')); 
like image 302
Sigularity Avatar asked Dec 18 '15 04:12

Sigularity


People also ask

What is copy command in Postgres?

The PostgreSQL \copy command is a meta-command available from the psql interactive client tool. You can use \copy to import data into a table on your RDS for PostgreSQL DB instance.

How do I COPY output from PostgreSQL?

The easiest but the most efficient way to export data from a Postgres table to a CSV file is by using the COPY command. COPY command generates a CSV file on the Database Server. You can export the entire table or the results of a query to a CSV file with the COPY TO command.


1 Answers

You have the right command (COPY), but you need to begin an interactive session with Postgres if you want use the COPY command from the Windows command line.

psql -U username yourdb

This should leave you at a prompt looking like the following:

yourdb=#

Now you can use the COPY command and it should work:

COPY myTable FROM value.txt (DELIMITER('|'))

The problem you were having is that COPY is not a Windows executable program, it is a Postgres command which is only understood by Postgres.

like image 65
Tim Biegeleisen Avatar answered Oct 11 '22 14:10

Tim Biegeleisen