On 26 February 2015 at 15:09, Dmitry Dolgov <9erthali...@gmail.com> wrote:

> Hi, Thom.
>
> > Would this support deleting "type" and the value 'dd'
>
> With this patch you can delete them one by one:
>
>  select '{"a": 1, "b": 2, "c": {"type": "json", "stuff": "test"}, "d":
> ["aa","bb","cc","dd"]}'::jsonb - '{c, type}'::text[] - '{d, -1}'::text[];
>                              ?column?
> -------------------------------------------------------------------
>  {"a": 1, "b": 2, "c": {"stuff": "test"}, "d": ["aa", "bb", "cc"]}
> (1 row)
>

Doesn't work for me:

# select '{"a": 1, "b": 2, "c": {"type": "json", "stuff": "test"}, "d":
["aa","bb","cc","dd"]}'::jsonb - '{c, type}'::text[] - '{d, -1}'::text[];
ERROR:  operator does not exist: jsonb - text[]
LINE 1: ...ff": "test"}, "d": ["aa","bb","cc","dd"]}'::jsonb - '{c, typ...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might
need to add explicit type casts.


> > Is there a way to take the json:
> > '{"a": 1, "b": 2, "c": {"type": "json", "stuff": "test"}, "d":
> ["aa","bb","cc","dd"]}'
> > and add "ee" to "d" without replacing it?
>
> No, looks like there is no way to add a new element to array with help of
> this patch. I suppose this feature can be implemented easy enough inside
> the "jsonb_concat" function:
>
>  select '{"a": 1, "b": 2, "c": {"type": "json", "stuff": "test"}, "d":
> ["aa","bb","cc","dd"]}'::jsonb || '{"d": ["ee"]}'::jsonb
>
> but I'm not sure, that it will be the best way.
>

Yeah, I think that may be problematic.  I agree with Josh that there's
probably no sane mix of operators for this, as I would expect your example
to replace "d": ["aa","bb","cc","dd"] with "d": ["ee"] rather than append
to it.  Hmm... unless we used a + operator, but then I'm not sure what
should happen in the instance of '{"d": ["aa"]}' + '{"d": "bb"}'.

-- 
Thom

Reply via email to