Last active
December 14, 2015 10:49
-
-
Save otkrsk/5075074 to your computer and use it in GitHub Desktop.
Pipe the output of a SQL query to a text file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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