[MDEV-32692] JSON_OBJECT creates invalid json for zerofill columns Created: 2023-11-06  Updated: 2023-11-06  Resolved: 2023-11-06

Status: Closed
Project: MariaDB Server
Component/s: N/A
Affects Version/s: 10.11.5
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Nils Reibold Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates MDEV-30962 JSON_OBJECT function generates "malfo... Confirmed

 Description   

CREATE TABLE `test` (
`ID` smallint(4) unsigned zerofill NOT NULL AUTO_INCREMENT
)

SELECT JSON_OBJECT('ID',ID) FROM test

An example Output would be

{ID: 0001}

, which does not seem to be a valid JSON-String. Maybe it would be possible to treat zerofill as a String?



 Comments   
Comment by Alice Sherepa [ 2023-11-06 ]

Thank you for the report!
This is the same as MDEV-30962, as a workaround you could cast id as char or int:

MariaDB [test]> CREATE TABLE t ( id smallint(4) unsigned zerofill NOT NULL AUTO_INCREMENT primary key ) ;
Query OK, 0 rows affected (0,034 sec)
 
MariaDB [test]> insert into t values (),(),();
Query OK, 3 rows affected (0,012 sec)
Records: 3  Duplicates: 0  Warnings: 0
 
MariaDB [test]> SELECT JSON_OBJECT('id',id) FROM t;
+----------------------+
| JSON_OBJECT('id',id) |
+----------------------+
| {"id": 0001}         |
| {"id": 0002}         |
| {"id": 0003}         |
+----------------------+
3 rows in set (0,000 sec)
 
MariaDB [test]> select json_valid(JSON_OBJECT('id',id)) from t;
+----------------------------------+
| json_valid(JSON_OBJECT('id',id)) |
+----------------------------------+
|                                0 |
|                                0 |
|                                0 |
+----------------------------------+
3 rows in set (0,001 sec)
 
MariaDB [test]> select json_valid(JSON_OBJECT('id',cast(id as char))) from t;
+------------------------------------------------+
| json_valid(JSON_OBJECT('id',cast(id as char))) |
+------------------------------------------------+
|                                              1 |
|                                              1 |
|                                              1 |
+------------------------------------------------+
3 rows in set (0,001 sec)

Generated at Thu Feb 08 10:33:16 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.