Last active
May 11, 2017 20:44
-
-
Save justinbaker999/48cdf513cea9f3ce2b11d067c01bb36f to your computer and use it in GitHub Desktop.
Export a query from postgres as CSV
This file contains hidden or 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
#! /usr/bin/env bash | |
# export a query as a csv | |
# $1 DB name | |
# $2 query ex: "SELECT * from tablename" | |
# $3 output file, ex: output.csv | |
# | |
# ./csvexport.sh users "SELECT * from users" users.csv | |
# | |
psql -d $1 -P format=unaligned -P tuples_only -P fieldsep=\, -c "$2" > $3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment