Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
79 changes: 69 additions & 10 deletions src/alasqlparser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -1128,28 +1128,87 @@ UnionClause

UnionOp
: UNION
{ $$ = {op: 'union'}; }
{
// Save and reset queries for nested SELECT using stack pattern
if(!yy.queriesStack) yy.queriesStack = [];
yy.queriesStack.push(yy.queries || []);
yy.queries = [];
$$ = {op: 'union'};
}
| UNION ALL
{ $$ = {op: 'unionall'}; }
{
if(!yy.queriesStack) yy.queriesStack = [];
yy.queriesStack.push(yy.queries || []);
yy.queries = [];
$$ = {op: 'unionall'};
}
| EXCEPT
{ $$ = {op: 'except'}; }
{
if(!yy.queriesStack) yy.queriesStack = [];
yy.queriesStack.push(yy.queries || []);
yy.queries = [];
$$ = {op: 'except'};
}
| INTERSECT
{ $$ = {op: 'intersect'}; }
{
if(!yy.queriesStack) yy.queriesStack = [];
yy.queriesStack.push(yy.queries || []);
yy.queries = [];
$$ = {op: 'intersect'};
}
| UNION CORRESPONDING
{ $$ = {op: 'union', corresponding: true}; }
{
if(!yy.queriesStack) yy.queriesStack = [];
yy.queriesStack.push(yy.queries || []);
yy.queries = [];
$$ = {op: 'union', corresponding: true};
}
| UNION ALL CORRESPONDING
{ $$ = {op: 'unionall', corresponding: true}; }
{
if(!yy.queriesStack) yy.queriesStack = [];
yy.queriesStack.push(yy.queries || []);
yy.queries = [];
$$ = {op: 'unionall', corresponding: true};
}
| EXCEPT CORRESPONDING
{ $$ = {op: 'except', corresponding: true}; }
{
if(!yy.queriesStack) yy.queriesStack = [];
yy.queriesStack.push(yy.queries || []);
yy.queries = [];
$$ = {op: 'except', corresponding: true};
}
| INTERSECT CORRESPONDING
{ $$ = {op: 'intersect', corresponding: true}; }
{
if(!yy.queriesStack) yy.queriesStack = [];
yy.queriesStack.push(yy.queries || []);
yy.queries = [];
$$ = {op: 'intersect', corresponding: true};
}
;

UnionableSelect
: SelectWithoutOrderOrLimit
{ $$ = $1; }
{
// Restore parent queries from stack and assign current queries to nested SELECT
if(yy.queriesStack && yy.queriesStack.length > 0) {
if(yy.queries && yy.queries.length > 0) {
$1.queries = yy.queries;
}
yy.queries = yy.queriesStack.pop();
}
$$ = $1;
}
| ParenthesizedSelect
{ $$ = $1; }
{
// Restore parent queries from stack and assign current queries to nested SELECT
if(yy.queriesStack && yy.queriesStack.length > 0) {
if(yy.queries && yy.queries.length > 0) {
$1.queries = yy.queries;
}
yy.queries = yy.queriesStack.pop();
}
$$ = $1;
}
;

OrderClause
Expand Down
71 changes: 62 additions & 9 deletions src/alasqlparser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading