Bug #79003 JSON_QUOTE only accepts string arguments
Submitted: 28 Oct 2015 16:05 Modified: 30 Oct 2015 6:09
Reporter: Roland Bouman Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: JSON Severity:S4 (Feature request)
Version:5.7 OS:Any
Assigned to: CPU Architecture:Any
Triage: Needs Triage: D5 (Feature request)

[28 Oct 2015 16:05] Roland Bouman
json_quote only accepts string arguments. It would be much more convenient if it would automatically convert values other datatypes in the usual way to their string equivalent.

How to repeat:
mysql> select json_quote(0.1);
ERROR 3064 (HY000): Incorrect type for argument 1 in function json_quote.

Suggested fix:
Modify JSON_QUOTE to accept other value types than string types.
[28 Oct 2015 22:03] Roland Bouman
category JSON
[30 Oct 2015 6:09] Umesh Shastry
Hello Roland,

Thank you for the feature request.

[30 Oct 2015 9:53] Knut Anders Hatlen
Thanks for the feedback, Roland. This should be easy enough to change, if it's the right thing to do. Is there a particular use case you have in mind for this?

The reasoning behind requiring explicit casts of non-strings to a string type, was that JSON_QUOTE was believed to be most useful for strings. Since quoting numbers was believed to be a rare use case, we thought this minor inconvenience would be acceptable. The benefit is that an error is raised so that unintentional quoting of numbers is detected and can be corrected at an early stage.

If it turns out that quoting numbers is not such a rare use case after all, we should reconsider this decision.