バージョン
$ cat /etc/redhat-release
CentOS release 6.5 (Final)
$ psql --version
psql (PostgreSQL) 9.3.5
"-c"を使うやつ
psql DB名 -U ユーザ名 -A -F, -c "select * from hoge" > hoge.csv
良いところ
- 1コマンドでできる!
困ったこと:未解決
区切り文字をタブにする方法がわからなかった
psql DB名 -U ユーザ名 -A -F\t -c "select * from hoge" > hoge.csv
→区切り文字がない。
正規表現のNOT検索(!~)を使ったら、「!」で上手く動作しなかった
psql DB名 -U ユーザ名 -A -F, -c "select * from hoge where column !~ '[0-9]'"
→コンソールに「-bash: !~: event not found」って出る。
"-c"使わないやつ
$ psql DB名 -U ユーザ名
DB名-> \o hoge.csv
DB名-> \a
DB名-> \pset fieldsep '\t'
DB名-> select * from hoge where column !~ '[0-9]';
DB名-> \o
DB名-> \q
良いところ
- 区切り文字をタブにできた!
- 正規表現のNOT検索(!~)使えた!