简体   繁体   中英

Coalesce jsonArrayAgg to empty array in jOOQ

What is the equivalent for coalesce in the new jOOQ 3.14 SQL/JSON supporting version (in PostgreSQL)?

select coalesce(json_agg(t.*), '[]'::json)
from (select 'test' as mycol where 1 = 2) t;

The following unfortunately fails with the error "COALESCE types json and uuid[] cannot be matched".

coalesce(jsonArrayAgg(mycol), emptyArray<type>())

JSON.json() or JSONB.jsonb() , eg:

coalesce(jsonArrayAgg(mycol), inline(json("[]")))
coalesce(jsonbArrayAgg(mycol), inline(jsonb("[]")))

But you can also use the jsonArray() or jsonbArray() constructors:

coalesce(jsonArrayAgg(mycol), jsonArray())
coalesce(jsonbArrayAgg(mycol), jsonbArray())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM