2

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>())

1 Answer 1

2

JSON.json() or JSONB.jsonb(), e.g.:

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())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.