# select array[1, 2, 3] || NULL; +----------+ | ?column? | +----------+ | {1,2,3} | +----------+ (1 row) # select '{あ, い, う}' :: text[] || NULL; +------------+ | ?column? | +------------+ | {あ,い,う} | +------------+ (1 row)

逆に明示的に
# select array[1, 2, 3] ||NULL :: int; +--------------+ | ?column? | +--------------+ | {1,2,3,NULL} | +--------------+ (1 row) # select '{あ, い, う}' :: text[] ||NULL :: text; +-----------------+ | ?column? | +-----------------+ | {あ,い,う,NULL} | +-----------------+ (1 row)

上と同じ結果は「NULL
# select array[1, 2, 3] ||'{NULL}' :: int[]; +--------------+ | ?column? | +--------------+ | {1,2,3,NULL} | +--------------+ (1 row) # select '{あ, い, う}' :: text[] ||'{NULL}' :: text[]; +-----------------+ | ?column? | +-----------------+ | {あ,い,う,NULL} | +-----------------+ (1 row)

ここまでは何となく認識してましたが、今日の本題は
# select case when to_char(now(), 'Dy') = 'Sat' then '土曜日' end; +------+ | case | +------+ | | +------+ (1 row) -- 上が空文字でなくNULLである確認 ↓ # select (case when to_char(now(), 'Dy') = 'Sat' then '土曜日' end) is null; +----------+ | ?column? | +----------+ | t | +----------+ (1 row)

こういう
# select '{月, 火, 水}' :: text[] || case when to_char(now(), 'Dy') = 'Sat' then '土' end; +-----------------+ | ?column? | +-----------------+ | {月,火,水,NULL} | +-----------------+ (1 row)
あれ、余計な
# select '{月, 火, 水}' :: text[] || (case when to_char(now(), 'Dy') = 'Sat' then '土'else NULL :: text end); +-----------------+ | ?column? | +-----------------+ | {月,火,水,NULL} | +-----------------+ (1 row)

う~、普段のように「値があれば配列に加え、NULL
# select '{月, 火, 水}' :: text[] || (case when to_char(now(), 'Dy') = 'Sat' then'{土}' :: text[] end); +------------+ | ?column? | +------------+ | {月,火,水} | +------------+ (1 row) # select array[1, 2, 3] || (case when to_char(now(), 'Dy') = 'Sat' thenarray[4] end); +----------+ | ?column? | +----------+ | {1,2,3} | +----------+ (1 row)

CASE
# select '{月, 火, 水}' :: text[] || (case when to_char(now(), 'Dy') = 'Fri' then'{土}' :: text[] end); +---------------+ | ?column? | +---------------+ | {月,火,水,土} | +---------------+ (1 row) # select array[1, 2, 3] || (case when to_char(now(), 'Dy') = 'Fri' thenarray[4] end); +-----------+ | ?column? | +-----------+ | {1,2,3,4} | +-----------+ (1 row)

他にも