Skip to content

A sequence of boolean expressions in parsed SQL is difficult to walk #21

@jessestimpson

Description

@jessestimpson

I'm attempting to walk the AST returned by SQL.Parser, and I'm finding the structure of a sequence of boolean expressions in a where clause to be counter-intuitive.

SQL to demonstrate: select id from events where timestamp > 1 and timestamp < 4;

Here's the current structure of the 'where' after Lexing and Parsing (metadata omitted for clarity)

{:where, _,
 [ {:<, _, [ {:and, _, [ {:>, _, [ {:timestamp, _, []}, {:numeric. _, [[], 49]} ]}, {:timestamp, _, []} ]}, {:numeric, _, [[], 52]} ]} ]
},

The AST above reads as:

((timestamp > 1) and timestamp) < 4

My expectation:

{:where, _,
 [ {:and, _ [ {:>, _, [ {:timestamp, _, []}, {:numeric, _, [[], 49]} ]}, {:<, _, [ {:timestamp, _, []}, {:numeric, _, [[], 52]} ]} ] } ]
}

This AST reads as:

(timestamp > 1) and (timestamp < 4)

Am I looking at the AST wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions