Skip to content

Commit

Permalink
let numeric in the DEMAULT.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Botchkov committed May 30, 2021
1 parent 904edfd commit 9c518e4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions mysql-test/suite/json/r/json_table.result
Expand Up @@ -57,14 +57,14 @@ Jeans {"color": "blue", "price": 50} blue
select * from t1 right join json_table(t1.item_props,'$' columns( color varchar(100) path '$.color')) as T on 1;
ERROR 42S22: Unknown column 't1.item_props' in 'JSON_TABLE argument'
DROP TABLE t1;
select * from JSON_TABLE( '[ {"xa": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default '101' on empty, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt;
select * from JSON_TABLE( '[ {"xa": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default 101 on empty, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt;
a b
101 11
101 111
2 22
2 222
3 NULL
select * from JSON_TABLE( '[ {"xa": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default '202' on error, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt;
select * from JSON_TABLE( '[ {"xa": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default 202 on error, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt;
a b
NULL 11
NULL 111
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/suite/json/t/json_table.test
Expand Up @@ -30,9 +30,9 @@ select * from t1 right join json_table(t1.item_props,'$' columns( color varchar(

DROP TABLE t1;

select * from JSON_TABLE( '[ {"xa": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default '101' on empty, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt;
select * from JSON_TABLE( '[ {"xa": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default 101 on empty, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt;

select * from JSON_TABLE( '[ {"xa": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default '202' on error, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt;
select * from JSON_TABLE( '[ {"xa": 1, "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default 202 on error, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt;

select * from JSON_TABLE( '[ {"a": [1, 2], "b": [11,111]}, {"a": 2, "b": [22,222]}, {"a":3}]', '$[*]' COLUMNS( a INT PATH '$.a' default '101' on empty, NESTED PATH '$.b[*]' COLUMNS (b INT PATH '$'))) as jt;

Expand Down
23 changes: 22 additions & 1 deletion sql/sql_yacc.yy
Expand Up @@ -1324,6 +1324,7 @@ End SQL_MODE_ORACLE_SPECIFIC */
TEXT_STRING
NCHAR_STRING
json_text_literal
json_text_literal_or_num

%type <lex_str_ptr>
opt_table_alias_clause
Expand Down Expand Up @@ -11550,6 +11551,26 @@ json_text_literal:
}
;

json_text_literal_or_num:
json_text_literal
| NUM
{
Lex->json_table->m_text_literal_cs= NULL;
}
| LONG_NUM
{
Lex->json_table->m_text_literal_cs= NULL;
}
| DECIMAL_NUM
{
Lex->json_table->m_text_literal_cs= NULL;
}
| FLOAT_NUM
{
Lex->json_table->m_text_literal_cs= NULL;
}
;

join_table_list:
derived_table_list { MYSQL_YYABORT_UNLESS($$=$1); }
;
Expand Down Expand Up @@ -11672,7 +11693,7 @@ json_on_response:
{
$$.m_response= Json_table_column::RESPONSE_NULL;
}
| DEFAULT json_text_literal
| DEFAULT json_text_literal_or_num
{
$$.m_response= Json_table_column::RESPONSE_DEFAULT;
$$.m_default= $2;
Expand Down

0 comments on commit 9c518e4

Please sign in to comment.