Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/syntax/main.ne
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ statement_noprep
| functions_statements


selection -> select_statement {% unwrap %}

any_selection -> select_statement {% unwrap %}
| select_values {% unwrap %}
| with_statement {% unwrap %}
| with_recursive_statement {% unwrap %}
| union_statement {% unwrap %}

selection -> lparen selection rparen {% get(1) %}
| any_selection {% get(0) %}

selection_paren -> lparen selection rparen {% get(1) %}
87 changes: 87 additions & 0 deletions src/syntax/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,4 +1060,91 @@ describe('Select statements', () => {
type: 'skip locked',
}
});

checkSelect("(select * from foo)",
{
type: 'select',
"columns": [
{
"expr": {
"name": "*",
"type": "ref"
}
}
],
"from": [
{
"name": {
"name": "foo"
},
"type": "table"
}
]
}
);

const testSubselect: SelectStatement = {
type: 'select',
"columns": [
{
"expr": {
"name": "*",
"type": "ref"
}
}
],
"from": [
{
"alias": "a",
"statement": {
"columns": [
{
"expr": {
"name": "*",
"type": "ref"
}
}
],
"from": [
{
"name": {
"name": "bar"
},
"type": "table"
}
],
"type": "select",
},
"type": "statement"
}
]
};

checkSelect(`
select * from (
select * from bar
) a`,
testSubselect
);

checkSelect(`
select * from (
(
select * from bar
)
) a`,
testSubselect
);

checkSelect(`
select * from (
(
(
select * from bar
)
)
) a`,
testSubselect
);

});