Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concat jsonb || jsonbjsonb #12180

Closed
Tracked by #7714
xiangjinwu opened this issue Sep 8, 2023 · 1 comment · Fixed by #12502
Closed
Tracked by #7714

concat jsonb || jsonbjsonb #12180

xiangjinwu opened this issue Sep 8, 2023 · 1 comment · Fixed by #12502
Assignees
Labels
component/func-expr Support a SQL function or operator good first issue Good for newcomers
Milestone

Comments

@xiangjinwu
Copy link
Contributor

xiangjinwu commented Sep 8, 2023

https://www.postgresql.org/docs/15/functions-json.html#:~:text=jsonb%20%7C%7C%20jsonb%20%E2%86%92%20jsonb

Concatenates two jsonb values. Concatenating two arrays generates an array containing all the elements of each input. Concatenating two objects generates an object containing the union of their keys, taking the second object's value when there are duplicate keys. All other cases are treated by converting a non-array input into a single-element array, and then proceeding as for two arrays. Does not operate recursively: only the top-level array or object structure is merged.

'["a", "b"]'::jsonb || '["a", "d"]'::jsonb → ["a", "b", "a", "d"]`
'{"a": "b"}'::jsonb || '{"c": "d"}'::jsonb → {"a": "b", "c": "d"}
'[1, 2]'::jsonb || '3'::jsonb → [1, 2, 3]
'{"a": "b"}'::jsonb || '42'::jsonb → [{"a": "b"}, 42]

To append an array to another array as a single entry, wrap it in an additional layer of array, for example:

'[1, 2]'::jsonb || jsonb_build_array('[3, 4]'::jsonb) → [1, 2, [3, 4]]
@github-actions github-actions bot added this to the release-1.2 milestone Sep 8, 2023
@xiangjinwu xiangjinwu added component/func-expr Support a SQL function or operator good first issue Good for newcomers labels Sep 8, 2023
@taytzehao
Copy link
Contributor

I would like to take this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/func-expr Support a SQL function or operator good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants