Skip to content

Instantly share code, notes, and snippets.

@justinbaker999
Last active May 11, 2017 20:44
Show Gist options
  • Save justinbaker999/48cdf513cea9f3ce2b11d067c01bb36f to your computer and use it in GitHub Desktop.
Save justinbaker999/48cdf513cea9f3ce2b11d067c01bb36f to your computer and use it in GitHub Desktop.
Export a query from postgres as CSV
#! /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