by aleyan on 5/1/21, 1:53 PM with 26 comments
by btown on 5/3/21, 6:24 AM
Of course, if you're adding this to a few dozen rows, then you might need to jump into SQL to do this at scale. And then you run into the wonderful situations described in the article. I've had to write the following a great many times:
config = jsonb_set(coalesce(config, '{}'::jsonb), '{"some","key","path"}', to_jsonb(something::text))
Or this, which is great if you need to set a top-level key to something static; the || operator just mixes the two together similar to Object.assign: config = coalesce(config, '{}'::jsonb) || '{"foo": "bar"}'::jsonb
And honestly, the syntax, especially the second one, isn't half bad once you get used to it. That said, the syntax from the article is amazing, and it will go a long way towards people reaching for Postgres even when their data model has a lot of unknowns.by gerdesj on 5/3/21, 12:50 AM
SELECT j->'k' FROM t;
UPDATE t SET j = f(j, '{"k"}', '"v"');
... and the provided solution into this: SELECT j['k'] FROM t;
UPDATE t SET j['k'] = '"v"';
I think I understand what a binary JSON column might be but by stripping variables and function names down to the minimum, both of these constructs look a bit heavy on the quotes and brackets (parenthesis.) There are squiggly brackets and square ones, single and double quotes. A lack of a colon is clearly an oversight.I think I understand now: the function "jsonb_set on a "'@thing@'" is to become a magic result by inference with enough syntax on a variable.
I think I may have some way to go before I achieve enlightenment 8)
by SPBS on 5/3/21, 6:52 AM
by tester756 on 5/3/21, 10:36 AM
by da39a3ee on 5/3/21, 11:29 AM
I am really really unconvinced that any teams should be reviewing patches by email like this when we have excellent PR-based workflows and interfaces. I know these people are 1000x better C programmers than me, but I think they are wrong and being unreceptive to improved technologies on this one.
by spaetzleesser on 5/2/21, 11:34 PM
SELECT jsonb_column.key FROM table; UPDATE table SET jsonb_column.key = '"value"';
by fractal618 on 5/2/21, 11:13 PM