Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: fix support for quoted alias
  • Loading branch information
Capo93 committed May 6, 2020
commit 42efe32c247b5874ae8d66b0d99385c0e1f63168
14 changes: 11 additions & 3 deletions src/sqlParser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ UNION return 'UNION'
[a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]* return 'IDENTIFIER'
\. return 'DOT'
['"][a-zA-Z_\u4e00-\u9fa5][a-zA-Z0-9_\u4e00-\u9fa5]*["'] return 'QUOTED_IDENTIFIER'
[`].+[`] return 'QUOTED_IDENTIFIER'
([`])(?:(?=(\\?))\2.)*?\1 return 'QUOTED_IDENTIFIER'

<<EOF>> return 'EOF'
. return 'INVALID'
Expand Down Expand Up @@ -285,8 +285,7 @@ selectExprAliasOpt
;

string
: QUOTED_IDENTIFIER { $$ = { type: 'String', value: $1 } }
| STRING { $$ = { type: 'String', value: $1 } }
: STRING { $$ = { type: 'String', value: $1 } }
;
number
: NUMERIC { $$ = { type: 'Number', value: $1 } }
Expand Down Expand Up @@ -328,6 +327,14 @@ identifier_list
: identifier { $$ = { type: 'IdentifierList', value: [ $1 ] } }
| identifier_list ',' identifier { $$ = $1; $1.value.push($3); }
;
quoted_identifier
: QUOTED_IDENTIFIER { $$ = { type: 'Identifier', value: $1 } }
| quoted_identifier DOT QUOTED_IDENTIFIER { $$ = $1; $1.value += '.' + $3 }
;
quoted_identifier_list
: quoted_identifier { $$ = { type: 'IdentifierList', value: [ $1 ] } }
| quoted_identifier_list ',' quoted_identifier { $$ = $1; $1.value.push($3); }
;
case_expr_opt
: { $$ = null }
| expr { $$ = $1 }
Expand All @@ -353,6 +360,7 @@ simple_expr_prefix
simple_expr
: literal { $$ = $1 }
| identifier { $$ = $1 }
| quoted_identifier { $$ = $1 }
| function_call { $$ = $1 }
| simple_expr_prefix { $$ = $1 }
| '(' expr_list ')' { $$ = { type: 'SimpleExprParentheses', value: $2 } }
Expand Down
10 changes: 8 additions & 2 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,13 @@ describe('select grammar support', function() {
`);
});

it('bugfix table alias2', function() {
it('bugfix table alias2', function () {
testParser('select a.* from a t1 join b t2 on t1.a = t2.a')
})
});

it('support quoted alias: multiple alias and orderby support', function () {
testParser('select a as `A A`, b as `B B` from z');
testParser('select a as `A A` from z order by `A A` desc');
testParser('select a as `A A`, b as `B B` from z group by `A A`, `B B` order by `A A` desc');
});
});