From e2893a3e5387f3b63f9f5765b7e4e7a4fb684a4a Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Tue, 28 Jan 2025 17:28:39 -0800 Subject: [PATCH] [sql] Fix native SQL protocol on old postgres versions (#8268) I broke it in #8256 by adding a RangeSubselect without an alias. --- edb/pgsql/ast.py | 5 +++++ edb/pgsql/resolver/__init__.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/edb/pgsql/ast.py b/edb/pgsql/ast.py index b683edba82b..345f3e7faa3 100644 --- a/edb/pgsql/ast.py +++ b/edb/pgsql/ast.py @@ -972,6 +972,11 @@ class WindowDef(ImmutableBase): class RangeSubselect(PathRangeVar): """Subquery appearing in FROM clauses.""" + # Before postgres 16, an alias is always required on selects from + # a subquery. Try to catch that with the typechecker by getting + # rid of the default value. + alias: Alias + lateral: bool = False subquery: Query diff --git a/edb/pgsql/resolver/__init__.py b/edb/pgsql/resolver/__init__.py index b3304b6c7a4..6dc622a955f 100644 --- a/edb/pgsql/resolver/__init__.py +++ b/edb/pgsql/resolver/__init__.py @@ -149,7 +149,10 @@ def resolve( val=expr.construct_row_expr(columns, ctx=ctx) ) ], - from_clause=[pgast.RangeSubselect(subquery=e)], + from_clause=[pgast.RangeSubselect( + subquery=e, + alias=pgast.Alias(aliasname='r'), + )], ctes=e.ctes, ) e.ctes = []