gluesql icon indicating copy to clipboard operation
gluesql copied to clipboard

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

Open gitmalong opened this issue 2 years ago • 1 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.

gitmalong avatar Sep 20 '23 15:09 gitmalong

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

panarch avatar Oct 29 '23 06:10 panarch