gluesql / gluesql

GlueSQL is quite sticky. It attaches to anywhere.

Home Page:https://gluesql.org/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AST Filter: Field without table name should refer to main table instead of joined one by default

gitmalong opened this issue · comments

let mut builder = table("a")
    .select()
    .left_join("b")
    .hash_executor(
        format!("b.a_id"),
        format!("a.id"),
    )
    .filter(col("year").eq(num(year)));

I found that the filter checks year against table b. I would have expected it to check against the main table a when no table is specified.

Thanks! This is not only for the AST builder, but also happens same in SQL.
e.g.

SELECT *
FROM a
LEFT JOIN b
WHERE id = a.id;

id without specifying table finds b table for the first.
Currently this implementation is intended behavior but I wonder other db cases.

e.g. in sqlite3, it returns parse error.
image