Extensible SQL Lexer and Parser for Rust
Find a file
Andy Grove 87a576563b Save
2018-09-03 10:31:04 -06:00
examples Save 2018-09-03 10:31:04 -06:00
src Remove some non ANSI SQL support 2018-09-03 10:25:05 -06:00
.gitignore roughing out classic pratt parser 2018-02-08 07:49:24 -07:00
Cargo.toml replace with code from datafusion 2018-09-03 09:56:39 -06:00
LICENSE.TXT replace with code from datafusion 2018-09-03 09:56:39 -06:00
README.md Save 2018-09-03 10:31:04 -06:00

SQL Parser

The goal of this project is to build a SQL lexer and parser capable of parsing ANSI SQL:2011 (or 2016 if I can get access to the specification for free).

The current code is capable of parsing some simple SELECT and CREATE TABLE statements.

let sql = "SELECT a, b, 123, myfunc(b) \
    FROM table_1 \
    WHERE a > b AND b < 100 \
    ORDER BY a DESC, b";

let ast = Parser::parse_sql(sql.to_string()).unwrap();

println!("AST: {:?}", ast);

This outputs

AST: SQLSelect { projection: [SQLIdentifier("a"), SQLIdentifier("b"), SQLLiteralLong(123), SQLFunction { id: "myfunc", args: [SQLIdentifier("b")] }], relation: Some(SQLIdentifier("table_1")), selection: Some(SQLBinaryExpr { left: SQLBinaryExpr { left: SQLIdentifier("a"), op: Gt, right: SQLIdentifier("b") }, op: And, right: SQLBinaryExpr { left: SQLIdentifier("b"), op: Lt, right: SQLLiteralLong(100) } }), order_by: Some([SQLOrderBy { expr: SQLIdentifier("a"), asc: false }, SQLOrderBy { expr: SQLIdentifier("b"), asc: true }]), group_by: None, having: None, limit: None }