Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-32005

JSON functions do not work with BIT fields

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.6.15, 10.11.5
    • 10.6, 10.11, 11.1
    • JSON
    • None
    • Ubuntu

    Description

      If a BIT(1) field is put into various JSON-functions, e.g. JSON_OBJECT, the charset of the JSON is inconsequent and it returns invalid JSON.

      Example script:

      CREATE TABLE t1(text_field VARCHAR(50), bool_field BIT(1) NOT NULL DEFAULT 0);
      INSERT INTO t1(text_field, bool_field) VALUES ('Some Umlauts with TRUE: äöü', 1), ('Also some Umlauts, but with FALSE: äöü', 0);
      SELECT JSON_OBJECT('text_field', text_field, 'bool_field', bool_field) FROM t1;
      

      Output:

       
      +--------------------------------------------------------------------------------+
      | json_object('text_field', text_field, 'bool_field', bool_field)                |
      +--------------------------------------------------------------------------------+
      | {"text_field": "Some Umlauts with TRUE: ���", "bool_field": \u0001}               |
      | {"text_field": "Also some Umlauts, but with FALSE: ���", "bool_field": \u0000}    |
      +--------------------------------------------------------------------------------+
      

      Workaround

      SELECT JSON_OBJECT('text_field', text_field, 'bool_field', CASE WHEN bool_field THEN true ELSE false END) FROM t1;
      

      Output:

      +----------------------------------------------------------------------------------------------------+
      | json_object('text_field', text_field, 'bool_field', CASE WHEN bool_field THEN true ELSE false END) |
      +----------------------------------------------------------------------------------------------------+
      | {"text_field": "Some Umlauts with TRUE: äöü", "bool_field": true}                                  |
      | {"text_field": "Also some Umlauts, but with FALSE: äöü", "bool_field": false}                      |
      +----------------------------------------------------------------------------------------------------+
      2 rows in set (0.001 sec)
      

      Attachments

        Activity

          People

            rucha174 Rucha Deodhar
            vdg@plan-bee.ch Walter van der Geest
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.