Skip to content

fix: add table qualification to filters_idx WHERE clause to resolve ambiguous column errors in reverse join#368

Merged
halconel merged 5 commits intoepoch8:feat/offsetsfrom
halconel:Looky-7769/offsets
Jan 27, 2026
Merged

fix: add table qualification to filters_idx WHERE clause to resolve ambiguous column errors in reverse join#368
halconel merged 5 commits intoepoch8:feat/offsetsfrom
halconel:Looky-7769/offsets

Conversation

@halconel
Copy link
Copy Markdown
Contributor

Problem

When using join_keys with filters_idx, SQL queries with JOIN failed with:

psycopg2.errors.AmbiguousColumn: column reference "id" is ambiguous

The sql_apply_filters_idx_to_subquery function used sa.column(i) without table qualification, which worked for simple SELECT queries but failed for JOIN queries with multiple tables sharing column names.

Solution

Added optional tbl parameter to sql_apply_filters_idx_to_subquery:

  • When tbl is provided → use tbl.c[i] (qualified column name)
  • When tbl=None → use sa.column(i) (backward compatibility)

Updated all call sites to pass table reference.

What this fixes

✅ Reverse join now works correctly with join_keys and filters_idx
✅ Solves LEFT JOIN issues with asynchronously updated tables
✅ Maintains backward compatibility

@halconel halconel merged commit 5fc089e into epoch8:feat/offsets Jan 27, 2026
37 checks passed
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.

1 participant