Created
May 16, 2018 21:07
-
-
Save carlosayam/f75f51c71cd11564f06971864c9cdcef to your computer and use it in GitHub Desktop.
best way to get csv output from postgresql in psql via \i example.sql
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
\set somevar1 '\'2018-01-01\'' | |
\set somevar2 '\'2017-01-01\'' | |
\echo Starting | |
\pset fieldsep ',' | |
\pset format unaligned | |
\pset null '(null)' | |
\o 'your-output.csv' | |
-- here your query | |
select | |
field1, field2 | |
from a_table; | |
\o | |
\echo finished |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment