Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sebastiaojuniordev/c5769d075bd40d3002f820525dd6e2d7 to your computer and use it in GitHub Desktop.

Select an option

Save sebastiaojuniordev/c5769d075bd40d3002f820525dd6e2d7 to your computer and use it in GitHub Desktop.

Revisions

  1. @stefanthoss stefanthoss created this gist Apr 29, 2016.
    11 changes: 11 additions & 0 deletions export-postgresql-table.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    psql -h hostname -U username -W -d database -t -A -F "," -c "SELECT * FROM table" > file.csv

    # Explanation of the used options:
    # -h Specifies the host name of the machine on which the server is running.
    # -U Connect to the database as a specific user.
    # -W Force psql to prompt for a password before connecting to a database.
    # -d Specifies the name of the database to connect to.
    # -t Turn off printing of column names and result row count footers, etc.
    # -A Switches to unaligned output mode.
    # -F Use separator as the field separator for unaligned output.
    # -c Specifies that psql is to execute one command string, command, and then exit.