Skip to content

Commit

Permalink
Fix empty array literals in SQL adapter (#6806)
Browse files Browse the repository at this point in the history
Apparently the `elements` field gets omitted from pg_query's output
when there aren't elements.
  • Loading branch information
msullivan authored Feb 9, 2024
1 parent f0c3889 commit 95b8f6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion edb/pgsql/parser/ast_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _list(
builder: Builder,
mapper: Callable[[T], U] = _ident,
) -> List[U]:
return [mapper(builder(n, ctx)) for n in node[name]]
return [mapper(builder(n, ctx)) for n in node.get(name, [])]


def _maybe_list(
Expand Down
7 changes: 7 additions & 0 deletions tests/test_sql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,13 @@ async def test_sql_query_32(self):
)
self.assert_shape(res, 3, ['a'])

res = await self.scon.fetch(
'''
SELECT unnest(ARRAY[]::int8[]) a
'''
)
self.assertEqual(len(res), 0)

res = await self.scon.fetch(
'''
SELECT *, unnested_b + 1 computed
Expand Down

0 comments on commit 95b8f6d

Please sign in to comment.