Re: mogrify and indent features for jsonb

From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: Thom Brown <thom(at)linux(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:09:06
Message-ID: CA+q6zcVDoJ9diPVrOPtd8Tb2RHrHRfRn=WGZg6FAFUEmozA2-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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)

> 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.

On 26 February 2015 at 01:13, Josh Berkus <josh(at)agliodbs(dot)com> wrote:

> On 02/25/2015 03:13 AM, Thom Brown wrote:
> > Can you think of a reasonable syntax for doing that via operators? I
> > can imagine that as a json_path function, i.e.:
> >
> > jsonb_add_to_path(jsonb, text[], jsonb)
> >
> > or where the end of the path is an array:
> >
> > jsonb_add_to_path(jsonb, text[], text|int|float|bool)
> >
> > But I simply can't imagine an operator syntax which would make it
> clear
> > what the user intended.
> >
> >
> > No, there probably isn't a sane operator syntax for such an operation.
> > A function would be nice. I'd just want to avoid hacking away at arrays
> > by exploding them, adding a value then re-arraying them and replacing
> > the value.
>
> Well, anyway, that doesn't seem like a reason to block the patch.
> Rather, it's a reason to create another one for 9.6 ...
>
>
> --
> Josh Berkus
> PostgreSQL Experts Inc.
> http://pgexperts.com
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2015-02-26 15:11:50 Re: pgaudit - an auditing extension for PostgreSQL
Previous Message David Steele 2015-02-26 15:02:32 Re: pgaudit - an auditing extension for PostgreSQL