From: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
---|---|
To: | Petr Jelinek <petr(at)2ndquadrant(dot)com> |
Cc: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, Josh Berkus <josh(at)agliodbs(dot)com>, Ryan Pedela <rpedela(at)datalanche(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Peter Geoghegan <pg(at)heroku(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Ilya Ashchepkov <koctep(at)gmail(dot)com> |
Subject: | Re: jsonb concatenate operator's semantics seem questionable |
Date: | 2015-05-20 18:41:08 |
Message-ID: | 20150520184108.GD5885@postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Petr Jelinek wrote:
> On 20/05/15 01:38, Jim Nasby wrote:
> >If we get this wrong now, we'll be stuck with it forever. At a minimum I
> >think we should use anything other than || until we can figure this out.
> >That leaves || available for whichever case we decide on.
>
> I am of strong opinion that concat should be shallow by default. Again it's
> how jquery works by default, it's how python's dict.update works and you can
> find this behavior in other languages as well when dealing with nested
> hashes. It's also how json would behave if you'd just did string
> concatenation (removing the outermost curly brackets) and parse it to json
> afterwards.
>
> I think this whole discussion shows primarily that it's by far not
> universally agreed if concatenation of json should be shallow or deep by
> default and AFAICS this is true even in javascript world so we don't really
> have where to look for precedents.
>
> Given the above I would vote to just provide the function and leave out the
> || operator for now.
+1 for providing just functions, not operators, for this JSON so-called
"concatenation".
But it is not really concatenation, is it? This is more like a "merge"
operation. I mean, if you told somebody that this operation is
concatenation
'xyz foo yxz' || 'bar' --> 'xyz bar yxz'
they would laugh at you pretty hard. But that's precisely what is
happening here:
alvherre=# select jsonb '{"a": 1, "b": 2, "c": 3}' || '{"b": 4}';
?column?
--------------------------
{"a": 1, "b": 4, "c": 3}
(1 fila)
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2015-05-20 18:41:49 | Re: GROUPING |
Previous Message | Alvaro Herrera | 2015-05-20 18:40:38 | Re: WIP: Enhanced ALTER OPERATOR |