Skip to content

ts-plugin flags UNION branches as ambiguous column #294

Description

@tiagolauer

The language-service plugin flags plain UNION queries as ambiguous:

select id from users union select id from posts
       ^^ ambiguous column: id

Since UNION branches must be column-compatible, sharing column names is the normal case, which makes this a squiggle on nearly every UNION. The shape type-locked in tests/union.test-d.ts reproduces it identically, and the core types the query cleanly (first-branch shape, per the README).

Root cause: findSources (ts-plugin/src/sql-context.cts:348-392) regex-scans every from/join in the whole statement, pooling both branches' tables into one scope. ts-plugin/src/diagnostics.cts:368-375 then counts the first SELECT list's columns against the pooled scope and reports anything found twice as ambiguous. Each branch needs its own scope, or UNION statements need to be skipped entirely under the "not reported on, instead of reported wrongly" policy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions