Search code examples
postgresqlpsqlpostgresql-copy

Split a big postgres table into multiple csv


I am using following psql query to connect to a remote host and split a big table into multiple csv files.

psql -h xx -p xx -U xx -d xx -c "\COPY (select * from table) TO program 'split --lines 1000' (format csv)

I am not getting what mistake I am making here.


Solution

  • Have you tried using STDOUT?

    $ psql -d db -c "COPY (SELECT * FROM t) TO STDOUT CSV " | split -1000