Correctly find references to aliased columns

This commit is contained in:
Simon Binder 2019-07-25 17:44:59 +02:00
parent 82f84732d0
commit 6c84013cfa
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 14 additions and 1 deletions

View File

@ -83,8 +83,12 @@ class ColumnResolver extends RecursiveVisitor<void> {
final column =
ExpressionColumn(name: name, expression: resultColumn.expression);
availableColumns.add(column);
usedColumns.add(column);
// make this column available if there is no other with the same name
if (!availableColumns.any((c) => c.name == name)) {
availableColumns.add(column);
}
}
}

View File

@ -58,4 +58,13 @@ void main() {
),
);
});
test('resolves sub-queries', () {
final engine = SqlEngine()..registerTable(demoTable);
final context = engine.analyze(
'SELECT d.*, (SELECT id FROM demo WHERE id = d.id) FROM demo d;');
expect(context.errors, isEmpty);
});
}