Thread: Single Row Mode in psql

Single Row Mode in psql

From
Christopher Manning
Date:
I'm using psql to extract data from a redshift (based on postgres) instance, but psql/libpq collects the result in memory before writing it to a file and causes out of memory problems for large results. Using COPY TO STDOUT or FETCH_COUNT isn't an option since redshift doesn't support those.

[Single Row Mode is available in postgres 9.2](http://www.postgresql.org/docs/9.2/static/libpq-single-row-mode.html) but [it doesn't look like](http://www.postgresql.org/docs/9.2/static/app-psql.html) you can tell psql to use it when writing to a file (using --output).

Is it currently possible to have psql --output to a file using single row mode?

Thank you,
Christopher

P.S. The ruby-pg gem supports single row mode: https://bitbucket.org/ged/ruby-pg/src/de1cdb0f7ba625ad7cec02bb871ae8fdf7de68c8/ext/pg_connection.c?at=default#cl-1514 but it has the overhead of being a ruby script instead of psql supporting it.