🐈

postgresqlでtsv出力する

2023/03/20に公開

メモメモ

#!/bin/bash

cat <<__SQL__ > /tmp/hoge.sql
\o /tmp/hoge.json.tmp
\a
\f '\t'
SELECT * FROM hoge;
\o
__SQL__

psql $DB_URI < /tmp/hoge.sql
  
cat /tmp/hoge.json.tmp | awk '/^{/ {print}' > /tmp/hoge.json
rm /tmp/hoge.json.tmp

-o: 出力先を決める
-f: 区切り文字の決定
-a: toggle between unaligned and aligned output mode

Discussion