[MDEV-12789] JSON_KEYS returns duplicate keys twice Created: 2017-05-12 Updated: 2017-08-10 Resolved: 2017-08-08 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | JSON |
| Affects Version/s: | 10.2.5 |
| Fix Version/s: | 10.2.8 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Anders Karlsson | Assignee: | Alexey Botchkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Linux CentOS 6.5 |
||
| Description |
|
When there are multiple attributes in a JSON object with the same name, which is allowed but discouraged in JSON, JSON_KEYS returns one entry for each duplicate:
MySQL 5.7 returns just the single key:
Multiple values for a single key are discouraged, but I think MySQL has the correct behavior as the JSON_KEYS function should return an array of the keys, and although "c1" in the example above exists twice in the object, it is the same key. |
| Comments |
| Comment by Elena Stepanova [ 2017-05-13 ] | ||||||||||||||||||||||||||||||||
|
But should JSON_KEYS return keys or unique keys, according to the standard? If it's just keys, and while duplicate keys are only discouraged but not prohibited, MariaDB behavior seems justified – there are indeed two keys "c1", so it returns two. | ||||||||||||||||||||||||||||||||
| Comment by Anders Karlsson [ 2017-05-15 ] | ||||||||||||||||||||||||||||||||
|
That is a valid point, but I'm not sure there is a good standard. MySQL works differently returning just 1 key. Now, my reasoning for voting for the MySQL behavior is that even though there are two keys, there is actually just 1 value, i.e. you can not access the second or following values with the same key. So if there is just 1 value there is in essence only one key/value pair. I tested how Jansson and PHP treats this, and PHP ignores the duplicates although stick with the last, instead of the first, value. | ||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-05-15 ] | ||||||||||||||||||||||||||||||||
|
I have no opinion on the subject, so I'm assigning it to holyfoot to consult with serg and decide what's best. Just please note that if you decide to change it, some other functions need to be changed accordingly, so they provide consistent results. For example,
| ||||||||||||||||||||||||||||||||
| Comment by michiv [ 2017-06-22 ] | ||||||||||||||||||||||||||||||||
|
That's not a bug. | ||||||||||||||||||||||||||||||||
| Comment by Anders Karlsson [ 2017-06-22 ] | ||||||||||||||||||||||||||||||||
|
michiv: In your example, John is not a key but a value. Multiple values are fine. For example, if we have a class of students, this is valid and is not in contradiction to what I am looking for here:
The following is the situation I am looking at:
In the last example, which on the two "name" attributes, when I ask for it, do we want? The first, the second or both. | ||||||||||||||||||||||||||||||||
| Comment by Alexey Botchkov [ 2017-08-08 ] | ||||||||||||||||||||||||||||||||
|
http://lists.askmonty.org/pipermail/commits/2017-August/011360.html |