Skip to content

Instantly share code, notes, and snippets.

@otkrsk
Last active December 14, 2015 10:49
Show Gist options
  • Save otkrsk/5075074 to your computer and use it in GitHub Desktop.
Save otkrsk/5075074 to your computer and use it in GitHub Desktop.
Pipe the output of a SQL query to a text file.
PostgreSQL
----------
After logging in to the PSQL console:
db=> \o /path/to/where/you/want/the/file/saved
db=> the sql query
db=>
Output is saved, though there is no feedback from the console.
MySQL
-----
SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment