Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit 5cccb5c

Browse files
Make sure the correct values are returned from a postgres record (#173)
Co-authored-by: Tom Christie <[email protected]>
1 parent 9ed76b3 commit 5cccb5c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

databases/backends/postgres.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def __init__(
9494
self._column_map_int[idx] = (idx, datatype)
9595
self._column_map_full[str(column[0])] = (idx, datatype)
9696

97+
def values(self) -> typing.ValuesView:
98+
return self._row.values()
99+
97100
def __getitem__(self, key: typing.Any) -> typing.Any:
98101
if len(self._column_map) == 0: # raw query
99102
return self._row[tuple(self._row.keys()).index(key)]

tests/test_databases.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@ async def test_results_support_column_reference(database_url):
278278
assert results[0][custom_date.c.published] == today
279279

280280

281+
@pytest.mark.parametrize("database_url", DATABASE_URLS)
282+
@async_adapter
283+
async def test_result_values_allow_duplicate_names(database_url):
284+
"""
285+
The values of a result should respect when two columns are selected
286+
with the same name.
287+
"""
288+
async with Database(database_url) as database:
289+
async with database.transaction(force_rollback=True):
290+
query = "SELECT 1 AS id, 2 AS id"
291+
row = await database.fetch_one(query=query)
292+
293+
assert list(row.keys()) == ["id", "id"]
294+
assert list(row.values()) == [1, 2]
295+
296+
281297
@pytest.mark.parametrize("database_url", DATABASE_URLS)
282298
@async_adapter
283299
async def test_fetch_one_returning_no_results(database_url):

0 commit comments

Comments
 (0)