Skip to content

Commit

Permalink
Fix pg_get_serial_sequence in SQL adapter (#7581)
Browse files Browse the repository at this point in the history
  • Loading branch information
aljazerzen authored Jul 19, 2024
1 parent 0dd18b1 commit 2a065c1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions edb/pgsql/resolver/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ def eval_FuncCall(
span=expr.span,
)

if fn_name == "pg_get_serial_sequence":
# we do not expose sequences, so any calls to this function returns NULL
return pgast.NullConstant()

if fn_name == "to_regclass":
arg = require_a_string_literal(expr, fn_name, ctx)
return to_regclass(arg, ctx=ctx)
Expand Down Expand Up @@ -306,6 +310,8 @@ def cast_to_regclass(param: pgast.BaseExpr, ctx: Context) -> pgast.BaseExpr:
"""

expr = eval(param, ctx=ctx)
if isinstance(expr, pgast.NullConstant):
return pgast.NullConstant()
if isinstance(expr, pgast.StringConstant):
return to_regclass(expr.val, ctx=ctx)
if isinstance(expr, pgast.NumericConstant):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_sql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,23 @@ async def test_sql_query_static_eval_04(self):
)
self.assertEqual(res, [[11]])

async def test_sql_query_static_eval_05(self):
# pg_get_serial_sequence always returns NULL, we don't expose sequences

res = await self.squery_values(
'''
SELECT
CAST(
CAST(
pg_catalog.pg_get_serial_sequence('a', 'b')
AS REGCLASS
)
AS OID
)
'''
)
self.assertEqual(res, [[None]])

async def test_sql_query_be_state(self):
con = await self.connect(database=self.con.dbname)
try:
Expand Down

0 comments on commit 2a065c1

Please sign in to comment.