Re: mogrify and indent features for jsonb

From: Thom Brown <thom(at)linux(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: mogrify and indent features for jsonb
Date: 2015-02-26 15:25:11
Message-ID: CAA-aLv4WnpWjNoDrWAi3whu7AHGqMf9jQQ0KVt-S=R-YvZPgKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 26 February 2015 at 15:09, Dmitry Dolgov <9erthalion6(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-02-26 15:56:38 Re: Precedence of standard comparison operators
Previous Message David Steele 2015-02-26 15:11:50 Re: pgaudit - an auditing extension for PostgreSQL