Skip to content

CTE/WITH .. UNION ALL confuses name resolution in WHERE #1509

Closed

Description

@FauxFaux

Describe the bug
A construction like:

with x as (
  select a from baz
  union all
  select a from bar
)
select a 
from x
where a=1

..gives the error:

Plan("No field named 'x.a'. Valid fields are 'baz.a'.")

Explicitly specifying where x.a gives the same error, so that is resolving correctly?

Writing the query as where baz.a=1 instead gives:

Plan("No field named 'baz.a'. Valid fields are 'x.a'.")

To Reproduce
Steps to reproduce the behavior:

❯ create table bar as select 1 as a;
❯ create table baz as select 1 as a;
❯ with x as (select a from baz union all select a from bar) select a from x;
+---+
| a |
+---+
| 1 |
| 1 |
+---+
❯ with x as (select a from baz union all select a from bar) select a from x where a=1;
Plan("No field named 'x.a'. Valid fields are 'baz.a'.")

Expected behavior
I believe SELECT a FROM x WHERE a=1 should function as if x was a single table containing a column named a, as shown in non-filtered select in the reproduction steps above.

Additional context
This isn't something to do with memory tables; it happens to my Parquet EXTERNAL tables too.

The error messaging here isn't great for my parquet files, which already use dotted notation, like select "address.line1" from address, now we have "address.address.line1".

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions