|
User defined variables work as expected:
SET @i=10, @d=1.5; SELECT JSON_OBJECT('int_variable', @i, 'int_literal', 20, 'decimal_variable', @d, 'decimal_literal', 2.6 );
|
Query OK, 0 rows affected (0.00 sec)
|
|
+-----------------------------------------------------------------------------------------------------+
|
| JSON_OBJECT('int_variable', @i, 'int_literal', 20, 'decimal_variable', @d, 'decimal_literal', 2.6 ) |
|
+-----------------------------------------------------------------------------------------------------+
|
| {"int_variable": 10, "int_literal": 20, "decimal_variable": 1.5, "decimal_literal": 2.6} |
|
+-----------------------------------------------------------------------------------------------------+
|
|
|
still repeatable on 10.2-10.4:
set names utf8;
|
DELIMITER @@;
|
CREATE PROCEDURE test()
|
BEGIN
|
DECLARE d DECIMAL(2,1) UNSIGNED DEFAULT 1.5;
|
SELECT JSON_OBJECT('decimal_variable', d, 'decimal_literal', 2.6);
|
END@@
|
|
DELIMITER ;@@
|
CALL test;
|
|
10.2 2b660fb4c212973ba0
|
MariaDB [test]> CALL test;
|
+------------------------------------------------------------+
|
| JSON_OBJECT('decimal_variable', d, 'decimal_literal', 2.6) |
|
+------------------------------------------------------------+
|
| {"decimal_variable": "1.5", "decimal_literal": 2.6} |
|
+------------------------------------------------------------+
|
1 row in set (0.001 sec)
|
|
|
|
On MariaDB 10.4 (i.e. 10.4.31 which is the only one i've tested this behaviour on), there is a bit of a quirk with this bug.
Running
DELIMITER ;;
|
CREATE OR REPLACE PROCEDURE test()
|
BEGIN
|
DECLARE d DECIMAL(2,1) UNSIGNED DEFAULT 1.4;
|
SELECT JSON_OBJECT('int_variable', @e, 'decimal_variable', d, 'int_literal', 20, 'decimal_literal', 2.6 );
|
END;;
|
DELIMITER ;
|
CALL test;
|
without having touched the @e session variable in that session returns the desired result:
+----------------------------------------------------------------------------------------------------+
|
| JSON_OBJECT('int_variable', @e, 'decimal_variable', d, 'int_literal', 20, 'decimal_literal', 2.6 ) |
|
+----------------------------------------------------------------------------------------------------+
|
| {"int_variable": null, "decimal_variable": 1.4, "int_literal": 20, "decimal_literal": 2.6} |
|
+----------------------------------------------------------------------------------------------------+
|
However, if you then set @e = 1 (and even if you then set it back to null), you once again run into the bug:
+----------------------------------------------------------------------------------------------------+
|
| JSON_OBJECT('int_variable', @e, 'decimal_variable', d, 'int_literal', 20, 'decimal_literal', 2.6 ) |
|
+----------------------------------------------------------------------------------------------------+
|
| {"int_variable": null, "decimal_variable": "1.4", "int_literal": 20, "decimal_literal": 2.6} |
|
+----------------------------------------------------------------------------------------------------+
|
I find this very strange.
Leaving out the session variable altogether and creating the stored procedure as
DELIMITER ;;
|
CREATE OR REPLACE PROCEDURE test()
|
BEGIN
|
DECLARE d DECIMAL(2,1) UNSIGNED DEFAULT 1.4;
|
SELECT JSON_OBJECT('decimal_variable', d, 'int_literal', 20, 'decimal_literal', 2.6 );
|
END;;
|
DELIMITER ;
|
CALL test;
|
once again exhibits the original bug:
+--------------------------------------------------------------------------------+
|
| JSON_OBJECT('decimal_variable', d, 'int_literal', 20, 'decimal_literal', 2.6 ) |
|
+--------------------------------------------------------------------------------+
|
| {"decimal_variable": "1.4", "int_literal": 20, "decimal_literal": 2.6} |
|
+--------------------------------------------------------------------------------+
|
|