Skip to content

Fix #624: preserve duplicate output column names in query results#722

Open
RamiNoodle733 wants to merge 1 commit intosimonw:mainfrom
RamiNoodle733:fix/issue-624
Open

Fix #624: preserve duplicate output column names in query results#722
RamiNoodle733 wants to merge 1 commit intosimonw:mainfrom
RamiNoodle733:fix/issue-624

Conversation

@RamiNoodle733
Copy link

@RamiNoodle733 RamiNoodle733 commented Mar 8, 2026

Fixes #624

Summary

When a query returns duplicate column names (for example joining two tables with the same field names), Database.query() and related helpers used dict(zip(...)), which silently overwrote earlier values.

This change preserves all values by suffixing duplicate keys as _2, _3, etc.

Changes

  • Added _row_to_dict() helper to safely map row values to unique dictionary keys
  • Updated Database.query(), Queryable.rows_where(), and Table.search() to use it
  • Added regression test covering duplicate output columns

Validation

  • pytest -q tests/test_query.py tests/test_rows.py
  • ruff check sqlite_utils/db.py tests/test_query.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query with duplicate output column names drop/overwrites duplicate colums

1 participant