Write A Query Result To File
Generally when writing a query in psql
a statement will be terminated with a semicolon. An alternative approach is to end it with a \g
instead. This will also send the query to the Postgres server for execution.
If a filename is included after the \g
, then the result of the query will be written to that file instead of output to the psql
session.
If we cat
that file, we can see the query result.
See man psql
for more details.
Last updated