Skip to content

Instantly share code, notes, and snippets.

@igstan
Created May 15, 2024 19:16
Show Gist options
  • Save igstan/6694deecaddf88b557e1b3037f066446 to your computer and use it in GitHub Desktop.
Save igstan/6694deecaddf88b557e1b3037f066446 to your computer and use it in GitHub Desktop.
SQL NULL & JSON NULL
SELECT
jsonb_set(
'{"deeply": {"nested": {"field": 1}}}'::jsonb,
'{deeply,nested,field}',
to_jsonb(NULL::int)
) AS with_null_arg,
jsonb_set(
'{"deeply": {"nested": {"field": 1}}}'::jsonb,
'{deeply,nested,field}',
to_jsonb(1234::int)
) AS sans_null_arg;
-- ┌───────────────┬─────────────────────────────────────────┐
-- │ with_null_arg │ sans_null_arg │
-- ├───────────────┼─────────────────────────────────────────┤
-- │ 𝗡𝗨𝗟𝗟 │ {"deeply": {"nested": {"field": 1234}}} │
-- └───────────────┴─────────────────────────────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment