Comments - JSON_OBJECTAGG

1 year, 4 months ago Norman Rice

How is this resulting JSON in the example what we would want? -- {"1":"Hello", "1":"World", "2":"This"} --

  • The attribute '1' is repeated. That's not valid.
  • In cases where parsers are a bit more lenient, they probably discard the 'Hello', and override it with 'World'.

A more useful JSON result would be: -- {"1":["Hello","World"], "2":"This"} --

Or, if the function is expanded to take an additional third parameter JSON_OBJECTAGG(key, value,optional_keyfield_for_duplicate_values):

-- select * from t1; +------+-------+------+

abc

+------+-------+------+

1HelloA
1WorldB
2Thisnull

+------+-------+------+

SELECT JSON_OBJECTAGG(a, b, c) FROM t1; +---------------------------------------------+

JSON_OBJECTAGG(a, b, c)

+---------------------------------------------+

{"1":["A":"Hello","B":"World"], "2":"This"}

+---------------------------------------------+

--

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.