end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

sql select の結果を縦に表示 - mysqlはsql文末に「\G」postgresは実行前に「\x」

mysqlの「\G」は使用したことがありましたが、 postgresの「\x」は使用したことがなかった為、メモ

mysqlの場合

mysql> select kyoten_id, reg_name, reg_date from user_mst limit 3;
+-----------+-----------+---------------------+
| kyoten_id | reg_name  | reg_date            |
+-----------+-----------+---------------------+
|         1 | end0tknr1 | 2021-05-12 00:00:00 |
|         1 | end0tknr2 | 2021-05-12 00:00:00 |
|         1 | end0tknr5 | 2021-05-16 19:41:55 |
+-----------+-----------+---------------------+
3 rows in set (0.00 sec)

mysql> select kyoten_id, reg_name, reg_date from user_mst limit 3\G
*************************** 1. row ***************************
kyoten_id: 1
 reg_name: end0tknr1
 reg_date: 2021-05-12 00:00:00
*************************** 2. row ***************************
kyoten_id: 1
 reg_name: end0tknr2
 reg_date: 2021-05-12 00:00:00
*************************** 3. row ***************************
kyoten_id: 1
 reg_name: end0tknr5
 reg_date: 2021-05-16 19:41:55
3 rows in set (0.00 sec)

postgresの場合

postgres=> \x
Expanded display is off.
db_rear_hon=> select * from test_tbl limit 3;
 id | val 
----+-----
  0 | あ
  1 | 髙
  2 | ㎡
(3 rows)

postgres=> \x
Expanded display is on.
db_rear_hon=> select * from test_tbl limit 3;
-[ RECORD 1 ]
id  | 0
val | あ
-[ RECORD 2 ]
id  | 1
val | 髙
-[ RECORD 3 ]
id  | 2
val | ㎡