Skip to content

Commit

Permalink
[sql] Fix (SELECT * FROM ...) in subqueries (#8254)
Browse files Browse the repository at this point in the history
Currently it will select all columns in *all* tables in scope. We only
want to select from the things in the FROM clause.
  • Loading branch information
msullivan authored Jan 25, 2025
1 parent ea5afab commit 8b79e3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions edb/pgsql/resolver/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ def _lookup_column(
return [
(t, c)
for t in ctx.scope.tables
# Only look at the highest precedence level for
# *. That is, we take everything in our local FROM
# clauses but not stuff in enclosing queries, if we
# are a subquery.
if t.precedence == 0
for c in t.columns
if not c.hidden
]
Expand Down
13 changes: 13 additions & 0 deletions tests/test_sql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,19 @@ async def test_sql_query_access_policy_04(self):
res = await self.squery_values('SELECT * FROM ONLY "Content"')
self.assertEqual(len(res), 0)

async def test_sql_query_subquery_splat_01(self):
res = await self.squery_values(
'''
with "average_pages" as (select avg("pages") as "value" from "Book")
select pages from "Book"
where "Book".pages < (select * from "average_pages")
'''
)
self.assertEqual(
res,
[[206]],
)

async def test_sql_query_unsupported_01(self):
# test error messages of unsupported queries

Expand Down

0 comments on commit 8b79e3f

Please sign in to comment.