@@ -209,7 +209,7 @@ int yyerror(YYLTYPE* llocp, SQLParserResult* result, yyscan_t scanner, const cha
209209%type <table> join_clause table_ref_name_no_alias
210210%type <expr> expr operand scalar_expr unary_expr binary_expr logic_expr exists_expr extract_expr cast_expr
211211%type <expr> function_expr between_expr expr_alias param_expr
212- %type <expr> column_name literal int_literal num_literal string_literal bool_literal
212+ %type <expr> column_name literal int_literal num_literal string_literal bool_literal date_literal
213213%type <expr> comp_expr opt_where join_condition opt_having case_expr case_list in_expr hint
214214%type <expr> array_expr array_index null_literal
215215%type <limit> opt_limit opt_top
@@ -1031,6 +1031,7 @@ literal:
10311031 | bool_literal
10321032 | num_literal
10331033 | null_literal
1034+ | date_literal
10341035 | param_expr
10351036 ;
10361037
@@ -1056,6 +1057,19 @@ null_literal:
10561057 NULL { $$ = Expr::makeNullLiteral(); }
10571058 ;
10581059
1060+ date_literal :
1061+ DATE STRING {
1062+ int day{0 }, month{0 }, year{0 }, chars_parsed{0 };
1063+ // If the whole string is parsed, chars_parsed points to the terminating null byte after the last character
1064+ if (sscanf($2 , " %4d-%2d-%2d%n" , &day, &month, &year, &chars_parsed) != 3 || $2 [chars_parsed] != 0 ) {
1065+ free ($2 );
1066+ yyerror (&yyloc, result, scanner, " Found incorrect date format. Expected format: YYYY-MM-DD" );
1067+ YYERROR ;
1068+ }
1069+ $$ = Expr::makeDateLiteral($2 );
1070+ }
1071+ ;
1072+
10591073param_expr :
10601074 ' ?' {
10611075 $$ = Expr::makeParameter(yylloc.total_column);
0 commit comments