Skip to content

fix: infer a column selected through a joined CTE from the source that has a wildcard - #6558

Merged
max-sixty merged 4 commits into
mainfrom
fix/issue-6557
Nov 15, 2026
Merged

max-sixty merged 4 commits into
mainfrom
fix/issue-6557

Conversation

@prql-bot

Copy link
Copy Markdown
Collaborator

Selecting an inferred column from a CTE that joins two tables failed with Table ["default_db", "x"] does not have wildcard. when only the second table had a wildcard. Since #5581, lineage_of_table_decl replaced a CTE input with its source tables during resolution, so every source shared the CTE's input name and inference charged the column to the first one (x). The CTE is now the input during resolution again, so inference goes from the CTE's own declaration to the source that has the wildcard (y), and the query compiles to SELECT zz FROM t.

#5581's purpose, debug lineage reporting source tables for CTE inputs, moves to pl_to_lineage. That function now replaces each CTE input with its source tables, keeping the input's id and name, and recurses through nested CTEs. The existing CTE lineage tests and the debug_lineage snapshots pass unchanged.

When both joined tables have wildcards, the column is ambiguous. That case compiled on main by charging the first source, which is what makes test_column_inference_with_into (#4723) pass. The fix keeps that behaviour explicitly: inference charges the first wildcard source instead of raising the old "could be any of" error. The CTE selects all of each source's columns, so the SQL is the same. Without the CTE, the same query reports Ambiguous name; whether the CTE form should report it too is left as is.

The error messages in infer_table_column now print the table as default_db.x rather than ["default_db", "x"].

Tests:

  • test_infer_column_through_joined_cte uses the query from the issue. It fails on main with the "does not have wildcard" error and passes with this change.
  • test_nested_cte_lineage_traces_to_source_tables covers recursion through a CTE built on another CTE.
  • task prqlc:test passes: 796 tests.

Closes #6557 — automated triage

prql-bot and others added 2 commits November 15, 2026 07:38
@max-sixty
max-sixty merged commit 05d0373 into main Nov 15, 2026
36 checks passed
@max-sixty
max-sixty deleted the fix/issue-6557 branch November 15, 2026 08:00
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.

Selecting an inferred column through a joined CTE fails with "does not have wildcard"

2 participants