LoginSignup
0
0

More than 5 years have passed since last update.

psql検索結果をファイル書き出ししたい

Last updated at Posted at 2016-09-08

バージョン

$ 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検索(!~)使えた!
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0