何かと便利な配列処理
Oracleと比べて便利と感じることいくつかありますが、PostgreSQLの配列の扱いがラクチンです。
array()関数で配列化し、array_to_string()関数で文字列化
-- 検証データ
myposdb=# select * from weather where wdate >= current_date-3 order by wdate
myposdb-# ;
wdate | weather
------------+---------
2022-10-12 | 晴
2022-10-13 | 雨
2022-10-14 | 曇
(3 rows)
-- array()関数で配列化
myposdb=# select
myposdb-# array(
myposdb(# select weather from weather where wdate >= current_date-3 order by wdate
myposdb(# );
array
------------
{晴,雨,曇}
(1 row)
-- array_to_string()関数で文字列化
myposdb=# select
myposdb-# pg_catalog.array_to_string(
myposdb(# ARRAY(
myposdb(# select weather from weather where wdate >= current_date-3 order by wdate
myposdb(# )
myposdb(# ,',')
myposdb-# ;
array_to_string
-----------------
晴,雨,曇
(1 row)
myposdb=#