diff --git a/src/sqlParser.jison b/src/sqlParser.jison index ee5b329..7cff3e8 100644 --- a/src/sqlParser.jison +++ b/src/sqlParser.jison @@ -585,6 +585,6 @@ index_hint ; table_factor : identifier partitionOpt aliasOpt index_hint_list_opt { $$ = { type: 'TableFactor', value: $1, partition: $2, alias: $3.alias, hasAs: $3.hasAs, indexHintOpt: $4 } } - | '(' selectClause ')' aliasOpt { $$ = { type: 'SubQuery', value: $2, alias: $4.alias, hasAs: $4.hasAs } } + | '(' selectClause ')' aliasOpt { $$ = { type: 'TableFactor', value: { type: 'SubQuery', value: $2 }, alias: $4.alias, hasAs: $4.hasAs} } | '(' table_references ')' { $$ = $2; $$.hasParentheses = true } ; diff --git a/test/main.test.js b/test/main.test.js index 558d133..834d3f1 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -397,4 +397,18 @@ describe('select grammar support', function() { testParser('select a as `A|A` from b limit 2;'); testParser('select a as `A A` from b limit 2;'); }); + + it('bugfix table alias', function() { + testParser(` + SELECT stime, A.names, B.names FROM ( + SELECT stime, names FROM iaas_data.iaas_d3c0d0681cc1900 + ) AS A LEFT JOIN ( + SELECT stime, names FROM iaas_data.iaas_1071f89feaa0e100 + ) AS B ON A.stime = B.stime + `); + }); + + it('bugfix table alias2', function() { + testParser('select a.* from a t1 join b t2 on t1.a = t2.a') + }) });