Updated on 2024-05-14 GMT+08:00

JSON Functions

JSON function differences:

  1. For JSON functions and other character input parameter functions, if the input contains escape characters, you need to set the GUC parameter set standard_conforming_strings to off, which is different from MySQL by default. In this case, escape characters are compatible with MySQL. However, a warning alarm is generated for non-standard character input. Escape characters \t and \u, and escape digits are different from those in MySQL. If the GUC parameter is not set, the JSON_UNQUOTE() function is still compatible with MySQL and no alarm is reported.
  2. When processing an ultra-long number (the number contains more than 64 characters), the JSON function of GaussDB parses the number as a DOUBLE and uses scientific notation for counting. The input parameters of the non-JSON type are the same as those of MySQL. However, when input parameters of the JSON type are used, the JSON type is not completely compatible with MySQL. As a result, differences occur in this scenario. MySQL displays complete numbers. (When the number length exceeds 82, MySQL displays an incorrect result.) GaussDB still parses an ultra-long number into a double-precision value. Long numbers are stored using floating-point numbers. During calculation, precision loss occurs in both GaussDB and MySQL. Therefore, you are advised to use character strings to store long numbers.
    gaussdb=# select json_insert('[1, 4, 99999999999999999999999999999999999999999999999999999999999999999999999999]','$[6]',json_insert('[1,4]','$[5]',99999999999999999999999999999999999999999999999999999999999999999999999999));
             json_insert          
    ------------------------------
     [1, 4, 1e+74, [1, 4, 1e+74]]
    (1 row)
Table 1 JSON functions

No.

MySQL

GaussDB

Difference

1

JSON_APPEND()

Supported.

-

2

JSON_ARRAY()

Supported.

-

3

JSON_ARRAY_APPEND()

Supported.

-

4

JSON_ARRAY_INSERT()

Supported.

-

5

JSON_CONTAINS()

Supported.

-

6

JSON_CONTAINS_PATH()

Supported.

-

7

JSON_DEPTH()

Supported.

Return value difference: In GaussDB, int is returned. In MySQL, bigint is returned.

8

JSON_EXTRACT()

Supported.

-

9

JSON_INSERT()

Supported.

-

10

JSON_KEYS()

Supported.

-

11

JSON_LENGTH()

Supported.

Return value difference: In GaussDB, int is returned. In MySQL, bigint is returned.

12

JSON_MERGE()

Supported.

-

13

JSON_OBJECT()

Supported.

-

14

JSON_QUOTE()

Supported.

Return value difference: In GaussDB, JSON is returned. In MySQL, varchar or text is returned.

15

JSON_REMOVE()

Supported.

-

16

JSON_REPLACE()

Supported.

-

17

JSON_SEARCH()

Supported.

Return value difference: In GaussDB, text is returned. In MySQL, JSON is returned.

18

JSON_SET()

Supported.

-

19

JSON_TYPE()

Supported.

JSON values of the numeric type are identified as number, which is different from MySQL.

20

JSON_UNQUOTE()

Supported.

-

21

JSON_VALID()

Supported.

-