Skip to content
This repository was archived by the owner on Jun 7, 2026. It is now read-only.
This repository was archived by the owner on Jun 7, 2026. It is now read-only.

Wrong AST in self-joined query #17

Closed

Description

@staabm

I have the feeling the AST for a query like SELECT a.email, b.adaid FROM ada a LEFT JOIN ada b ON a.adaid=b.adaid is not correct.

        $queryString = 'SELECT a.email, b.adaid FROM ada a LEFT JOIN ada b ON a.adaid=b.adaid';

        // returns a Generator. will not parse anything if you don't iterate over it
        $commands = $parser->parse($queryString);

        foreach ($commands as list($command)) {
            // Parser does not throw exceptions. this allows to parse partially invalid code and not fail on first error
            if ($command instanceof SelectCommand) {
                $from = $command->getFrom();
                var_dump(get_class($from));
            }
        }

only output:

SqlFtw\Sql\Dml\TableReference\OuterJoin

I am wondering why the ast does not contain a TableReferenceTable in addition to the Join.
Also: I don't think OuterJoin is correct in this case.

Activity

  1. paranoiq commented on Feb 18, 2023

    @paranoiq
    Member

    hi. in SQL syntax JOINs are considered binary operators (simillarly to e.g. + in expressions). in this case operator OUTER JOIN has a left operand a and right operand b. if you inspect the OuterJoin object, there is $joinSide property saying what side the outer join is (LEFT|RIGHT) and both sides $left and $right are TableReferenceTable. one for a and the other for b:

    image

    btw, there are three types of expression trees in SQL:

    • value expressions like e.g. 1 + foo(3),
    • table/join expressions, and
    • union/query expressions
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions