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
2 changes: 1 addition & 1 deletion src/syntax/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ export interface FromTable extends PGNode {
export interface FromStatement extends PGNode {
type: 'statement';
statement: SelectStatement;
alias: string;
alias?: string;
lateral?: true;
columnNames?: Name[] | nil;
db?: null | nil;
Expand Down
4 changes: 2 additions & 2 deletions src/syntax/select.ne
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ stb_table -> table_ref stb_opts:? {% x => {
} %}


# Selects on subselects MUST have an alias
stb_statement -> %kw_lateral:? selection_paren stb_opts {% x => track(x, {
# Selects on subselects CAN have an alias
stb_statement -> %kw_lateral:? selection_paren stb_opts:? {% x => track(x, {
type: 'statement',
statement: unwrap(x[1]),
...x[0] && { lateral: true },
Expand Down
14 changes: 13 additions & 1 deletion src/syntax/select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ describe('Select statements', () => {
checkInvalid('select (*) from test');
checkInvalid('select ("*") from test');
checkInvalid('select * from (test)');
checkInvalid('select * from (select id from test)'); // <== missing alias
checkInvalid('select * from sum(DISTINCT whatever)');

checkSelect('select * from (select id from test) d', {
Expand All @@ -366,6 +365,19 @@ describe('Select statements', () => {
}]
})

checkSelect('select * from (select id from test)', {
type: 'select',
columns: columns({ type: 'ref', name: '*' }),
from: [{
type: 'statement',
statement: {
type: 'select',
from: [tbl('test')],
columns: columns({ type: 'ref', name: 'id' }),
},
}]
})

checkSelect(['select * from test group by grp', 'select * from test group by (grp)'], {
type: 'select',
columns: columns({ type: 'ref', name: '*' }),
Expand Down