Skip to content

Instantly share code, notes, and snippets.

@mjumbewu
Created July 24, 2018 19:05
Show Gist options
  • Save mjumbewu/3daace7d8a98caba55032ba0bcb1e834 to your computer and use it in GitHub Desktop.
Save mjumbewu/3daace7d8a98caba55032ba0bcb1e834 to your computer and use it in GitHub Desktop.
Shell script to dump a CSV file from a database table
#!/bin/sh -e
table=$1
psql -U $DBUSER -h $DBHOST -p $DBPORT $DBNAME -c \
"COPY (SELECT * FROM $table) TO STDOUT WITH CSV HEADER"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment