diff --git a/core/sqlSyntaxParser.js b/core/sqlSyntaxParser.js index 6b93248..ff02948 100644 --- a/core/sqlSyntaxParser.js +++ b/core/sqlSyntaxParser.js @@ -4349,9 +4349,11 @@ case 1320: }; if ($$[$0-1]) { - this.$.primary.alias = $$[$0-1].alias; - parser.addTablePrimary({ subQueryAlias: $$[$0-1].alias }); - parser.addSubqueryAliasLocation($$[$0-1].location, $$[$0-1].alias, $$[$0-2].identifierChain); + if(this.$.primary){ + this.$.primary.alias = $$[$0-1].alias; + parser.addTablePrimary({ subQueryAlias: $$[$0-1].alias }); + parser.addSubqueryAliasLocation($$[$0-1].location, $$[$0-1].alias, $$[$0-2].identifierChain); + } } var keywords = []; @@ -4451,10 +4453,12 @@ break; case 1355: var subQuery = parser.getSubQuery($$[$0]); - subQuery.columns.forEach(function (column) { - parser.expandIdentifierChain({ wrapper: column }); - delete column.linked; + if(subQuery){ + subQuery.columns.forEach(function (column) { + parser.expandIdentifierChain({ wrapper: column }); + delete column.linked; }); + } parser.popQueryState(subQuery); this.$ = subQuery; diff --git a/jison/sql_main.jison b/jison/sql_main.jison index e8f6c71..96ddb14 100755 --- a/jison/sql_main.jison +++ b/jison/sql_main.jison @@ -2958,9 +2958,11 @@ TablePrimary }; if ($2) { - $$.primary.alias = $2.alias; - parser.addTablePrimary({ subQueryAlias: $2.alias }); - parser.addSubqueryAliasLocation($2.location, $2.alias, $1.identifierChain); + if($$.primary){ + $$.primary.alias = $2.alias; + parser.addTablePrimary({ subQueryAlias: $2.alias }); + parser.addSubqueryAliasLocation($2.location, $2.alias, $1.identifierChain); + } } var keywords = []; @@ -3127,10 +3129,12 @@ TableSubQueryInner : PushQueryState SubQuery { var subQuery = parser.getSubQuery($2); - subQuery.columns.forEach(function (column) { - parser.expandIdentifierChain({ wrapper: column }); - delete column.linked; + if(subQuery){ + subQuery.columns.forEach(function (column) { + parser.expandIdentifierChain({ wrapper: column }); + delete column.linked; }); + } parser.popQueryState(subQuery); $$ = subQuery; }