diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result index 3bee1e06abb..9f874d6264e 100644 --- a/mysql-test/suite/json/r/json_table.result +++ b/mysql-test/suite/json/r/json_table.result @@ -1216,6 +1216,7 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp # # MDEV-27898 CREATE VIEW AS SELECT FROM JSON_TABLE column requires global privileges # +# Beginning of 10.11 tests create view v1 as (select * from json_table('[{"a":"1"}]', '$[*]' columns(a int path '$.a') ) as jt); create user u1@localhost; @@ -1228,4 +1229,55 @@ connection default; DROP VIEW v2; DROP VIEW v1; DROP USER u1@localhost; -# End of 10.11 tests +# +# MDEV-34081: View containing JSON_TABLE does not return JSON +# +CREATE OR REPLACE VIEW test_view AS SELECT * FROM JSON_TABLE(' +[ + { + "caption": "First Element", + "value": 1 + }, + { + "caption": "Second Element", + "value": 2 + } +] +', '$[*]' COLUMNS( +caption VARCHAR(200) PATH '$.caption', +whole_block JSON PATH '$')) t; +SELECT * FROM test_view; +caption whole_block +First Element { + "caption": "First Element", + "value": 1 + } +Second Element { + "caption": "Second Element", + "value": 2 + } +SELECT * FROM JSON_TABLE(' +[ + { + "caption": "First Element", + "value": 1 + }, + { + "caption": "Second Element", + "value": 2 + } +] +', '$[*]' COLUMNS( +caption VARCHAR(200) PATH '$.caption', +whole_block JSON PATH '$')) t; +caption whole_block +First Element { + "caption": "First Element", + "value": 1 + } +Second Element { + "caption": "Second Element", + "value": 2 + } +DROP VIEW test_view; +# End of 10.11 test diff --git a/mysql-test/suite/json/t/json_table.test b/mysql-test/suite/json/t/json_table.test index bbb6db9cc7b..aac9005cbd6 100644 --- a/mysql-test/suite/json/t/json_table.test +++ b/mysql-test/suite/json/t/json_table.test @@ -1046,6 +1046,8 @@ COLUMNS --echo # MDEV-27898 CREATE VIEW AS SELECT FROM JSON_TABLE column requires global privileges --echo # +--echo # Beginning of 10.11 tests + create view v1 as (select * from json_table('[{"a":"1"}]', '$[*]' columns(a int path '$.a') ) as jt); @@ -1063,4 +1065,42 @@ DROP VIEW v2; DROP VIEW v1; DROP USER u1@localhost; ---echo # End of 10.11 tests +--echo # +--echo # MDEV-34081: View containing JSON_TABLE does not return JSON +--echo # + +CREATE OR REPLACE VIEW test_view AS SELECT * FROM JSON_TABLE(' +[ + { + "caption": "First Element", + "value": 1 + }, + { + "caption": "Second Element", + "value": 2 + } +] +', '$[*]' COLUMNS( + caption VARCHAR(200) PATH '$.caption', + whole_block JSON PATH '$')) t; + +SELECT * FROM test_view; + +SELECT * FROM JSON_TABLE(' +[ + { + "caption": "First Element", + "value": 1 + }, + { + "caption": "Second Element", + "value": 2 + } +] +', '$[*]' COLUMNS( + caption VARCHAR(200) PATH '$.caption', + whole_block JSON PATH '$')) t; + +DROP VIEW test_view; + +--echo # End of 10.11 test diff --git a/sql/json_table.cc b/sql/json_table.cc index bb126f36b85..d3a81cc61d1 100644 --- a/sql/json_table.cc +++ b/sql/json_table.cc @@ -970,8 +970,9 @@ int Json_table_column::print(THD *thd, Field **f, String *str) (*f)->sql_type(column_type); - if (str->append(column_type) || - ((*f)->has_charset() && m_explicit_cs && + if ((m_format_json ? str->append(STRING_WITH_LEN(" JSON ")) : str->append(column_type))) + return 1; + if (((*f)->has_charset() && m_explicit_cs && (str->append(STRING_WITH_LEN(" CHARSET ")) || str->append(&m_explicit_cs->cs_name) || (Charset(m_explicit_cs).can_have_collate_clause() && diff --git a/sql/json_table.h b/sql/json_table.h index f588b6e08b0..01b97377e4a 100644 --- a/sql/json_table.h +++ b/sql/json_table.h @@ -167,6 +167,7 @@ public: { m_on_error.m_response= RESPONSE_NOT_SPECIFIED; m_on_empty.m_response= RESPONSE_NOT_SPECIFIED; + m_format_json= false; } int print(THD *tnd, Field **f, String *str); };