Skip to content

Instantly share code, notes, and snippets.

View GuyKomari's full-sized avatar
🎯
Focusing

Guy Komari GuyKomari

🎯
Focusing
View GitHub Profile
/**
* Helper function that builds a PostgreSQL jsonb_set function that also deeply creates missing objects
*
* Usage:
* 1. jsonbSetDeep(target = "my_field", path = arrayOf("depth1","depth2"), newJsonValue = "[]")
* returns -
* jsonb_set(
* CASE
* WHEN my_field IS NULL THEN '{"depth1": {}}'
* WHEN my_field -> 'depth1' IS NULL THEN jsonb_set(my_field, array['depth1'], '{}')