Skip to content

Instantly share code, notes, and snippets.

@tanish-kr
Last active January 16, 2019 08:23
Show Gist options
  • Save tanish-kr/3c82067a0aebc66029e84592a6da6a3e to your computer and use it in GitHub Desktop.
Save tanish-kr/3c82067a0aebc66029e84592a6da6a3e to your computer and use it in GitHub Desktop.
PosgtreSQLでコマンドラインからSQL実行
  • やりたいこと mysqlだと -e オプションに相当
mysql -u user db -e 'SELECT * FROM tbl LIMIT 10'

https://www.postgresql.jp/document/9.0/html/app-psql.html

-c : commandを実行

psql -d db -U user -c 'SELECT * FROM tbl LIMIT 10'
  • CSVで出力
psql -d db -U user -c 'SELECT * FROM tbl LIMIT 10' -A -F, -o data.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment