Skip to content

Error message inaccurately says query "requires table-qualified reference" #6974

@philrz

Description

@philrz

The following query already has table-qualified references, so the error messages seem inaccurate.

$ echo -e '{"x": 1, "id": 1}\n{"x": 2, "id": 2}' > a.json &&
  echo -e '{"y": 10, "id": 1}\n{"y": 20, "id": 2}' > b.json &&
  super -s -dynamic -c "SELECT a.x FROM 'a.json' AS a JOIN 'b.json' AS b ON a.id = b.id;"

join on dynamic column "a" requires table-qualified reference at line 1, column 53:
SELECT a.x FROM 'a.json' AS a JOIN 'b.json' AS b ON a.id = b.id;
                                                    ~~~~
join on dynamic column "b" requires table-qualified reference at line 1, column 60:
SELECT a.x FROM 'a.json' AS a JOIN 'b.json' AS b ON a.id = b.id;
                                                           ~~~~
join on dynamic column "a" requires table-qualified reference at line 1, column 8:
SELECT a.x FROM 'a.json' AS a JOIN 'b.json' AS b ON a.id = b.id;
       ~~~

Details

Repro is with super commit f597295.

I bumped into this while working on the query in #6971 and encountering error messages like the ones above before realizing that the input data was wrapped in a top-level JSON array.

The query works as expected if we drop the -dynamic.

$ super -version
Version: v0.3.0-139-gf5972950e

$ super -s -c "SELECT a.x FROM 'a.json' AS a JOIN 'b.json' AS b ON a.id = b.id;"
{x:1}
{x:2}

Claude's take

I happened to be showing this one to Claude, and here's what it had to say, should this help save anyone time:

When you write a SQL JOIN using table-qualified column references like a.id or b.id, the compiler processes the name in two steps: first it tries to find a field named a in the input, and only if that fails does it try to interpret a as a table name and id as the column within it.

The problem is that when both sides of the join have dynamic (unknown) schemas, the first step fails with an error instead of just quietly moving on to the second step. That error gets reported immediately and the compiler never reaches the second step — even though the second step would have succeeded.

The result is a misleading error message. The compiler complains that your reference requires a table-qualified form, when in fact your reference is already table-qualified. The compiler just never got far enough to notice.

The fix is small: when the first step fails and the reference has two parts (table + column), don't give up — proceed to the second step. The error should only fire for truly unqualified single-word references like id on its own, where there's genuinely no way to tell which side of the join it came from.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions