Quick question (I hope!): if I use \i to feed an input file into psql, can I get the output from the queries to be saved into a file? If so, how? Thanks!!
PostgreSQL doesn't have a SPOOL command. You can direct output to a file using COPY (as you've discovered) or by using psql. Psql is a command-line tool. It's not a re-implementation of Oracle's SPOOL.
PostgreSQL provides two distinct ways to store binary data. Binary data can be stored in a table using the data type bytea or by using the Large Object feature which stores the binary data in a separate table in a special format and refers to that table by storing a value of type oid in your table.
Based on the documentation, the \o
is for directing output to a file.
Using \o
, as recommended by others, is a good solution. Just for fun, though, another way to do this would be to pipe the input file to psql
from the command line, rather than using the \i
command. Then you could re-direct the output to another file. For example:
psql < input.sql > output.txt
This has some interesting side effects. For example, if you have timing turned on (\timing on
), then using \o
would not cause the timing results to be piped to the output file, but re-direction would. Same thing with \echo
statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With