The discussion in [1] pointed out that the existing documentation for the "jsonb || jsonb" concatenation operator is far short of reality: it fails to acknowledge that the operator will accept any cases other than two jsonb array inputs or two jsonb object inputs.
I'd about concluded that other cases were handled as if by wrapping non-array inputs in one-element arrays and then proceeding as for two arrays. That works for most scenarios, eg regression=# select '[3]'::jsonb || '{}'::jsonb; ?column? ---------- [3, {}] (1 row) regression=# select '3'::jsonb || '[]'::jsonb; ?column? ---------- [3] (1 row) regression=# select '3'::jsonb || '4'::jsonb; ?column? ---------- [3, 4] (1 row) However, further experimentation found a case that fails: regression=# select '3'::jsonb || '{}'::jsonb; ERROR: invalid concatenation of jsonb objects I wonder what is the point of this weird exception, and whether whoever devised it can provide a concise explanation of what they think the full behavior of "jsonb || jsonb" is. Why isn't '[3, {}]' a reasonable result here, if the cases above are OK? regards, tom lane [1] https://www.postgresql.org/message-id/flat/0d72b76d-ca2b-4263-8888-d6dfca861c51%40www.fastmail.com