1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

psqlで1回のクエリだけ\x (expanded output) する

Last updated at Posted at 2021-12-28

MySQLの \G のように1回のクエリだけexpand形式にする方法。

psql 10以降の場合

SQLの末尾に \gx をつければ良い。

postgres=# select * from t1 \gx
-[ RECORD 1 ]-----
id   | 1
name | hoge
-[ RECORD 2 ]-----
id   | 2
name | moge

psql 9以前の場合

~/.psqlrc

\set G '\\set QUIET 1\\x\\g\\x\\set QUIET 0'

と書いておく。そしてpsqlで

select * from t1 :G

のように末尾に :G をつけてクエリすると

-[ RECORD 1 ]
id   | 1
name | yamada
-[ RECORD 2 ]
id   | 2
name | tanaka

のようにexpand形式で表示される。

https://stackoverflow.com/questions/9604723/alternate-output-format-for-psql#comment77313864_9605093 より。

ちなみに、端末の幅が足りれば表形式、足りなければexpand形式の表示にする\x autoという設定もある。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?