Skip to content

Commit 87a5765

Browse files
committed
Save
1 parent 5bac9fd commit 87a5765

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
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).
44

5-
The current code was copied from DataFusion and has some non-standard SQL support and only a subset of ANSI SQL currently.
5+
The current code is capable of parsing some simple SELECT and CREATE TABLE statements.
66

7-
The current code is capable of parsing some simple SELECT and CREATE TABLE statements.
7+
```rust
8+
let sql = "SELECT a, b, 123, myfunc(b) \
9+
FROM table_1 \
10+
WHERE a > b AND b < 100 \
11+
ORDER BY a DESC, b";
12+
13+
let ast = Parser::parse_sql(sql.to_string()).unwrap();
14+
15+
println!("AST: {:?}", ast);
16+
```
17+
18+
This outputs
19+
20+
```rust
21+
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 }
22+
```

examples/parse_select.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
extern crate sqlparser;
2+
3+
use sqlparser::sqlparser::*;
4+
5+
fn main() {
6+
7+
let sql = "SELECT a, b, 123, myfunc(b) \
8+
FROM table_1 \
9+
WHERE a > b AND b < 100 \
10+
ORDER BY a DESC, b";
11+
12+
let ast = Parser::parse_sql(sql.to_string()).unwrap();
13+
14+
println!("AST: {:?}", ast);
15+
}

0 commit comments

Comments
 (0)