6
6
[ ![ Coverage Status] ( https://coveralls.io/repos/github/sqlparser-rs/sqlparser-rs/badge.svg?branch=main )] ( https://coveralls.io/github/sqlparser-rs/sqlparser-rs?branch=main )
7
7
[ ![ Gitter Chat] ( https://badges.gitter.im/sqlparser-rs/community.svg )] ( https://gitter.im/sqlparser-rs/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge )
8
8
9
- The goal of this project is to build a SQL lexer and parser capable of parsing
10
- SQL that conforms with the [ ANSI/ISO SQL standard] [ sql-standard ] while also
11
- making it easy to support custom dialects so that this crate can be used as a
12
- foundation for vendor-specific parsers.
13
-
14
- This parser is currently being used by the [ DataFusion] query engine,
15
- [ LocustDB] , [ Ballista] and [ GlueSQL] .
16
-
17
- This crate provides only a syntax parser, and tries to avoid applying
18
- any SQL semantics, and accepts queries that specific databases would
19
- reject, even when using that Database's specific ` Dialect ` . For
20
- example, ` CREATE TABLE(x int, x int) ` is accepted by this crate, even
21
- though most SQL engines will reject this statement due to the repeated
22
- column name ` x ` .
23
-
24
- This crate avoids semantic analysis because it varies drastically
25
- between dialects and implementations. If you want to do semantic
26
- analysis, feel free to use this project as a base
9
+ This crate contains a lexer and parser for SQL that conforms with the
10
+ [ ANSI/ISO SQL standard] [ sql-standard ] and other dialects. This crate
11
+ is used as a foundation for SQL query engines, vendor-specific
12
+ parsers, and various SQL analysis.
27
13
28
14
## Example
29
15
@@ -51,11 +37,27 @@ This outputs
51
37
AST : [Query (Query { ctes : [], body : Select (Select { distinct : false , projection : [UnnamedExpr (Identifier (" a" )), UnnamedExpr (Identifier (" b" )), UnnamedExpr (Value (Long (123 ))), UnnamedExpr (Function (Function { name : ObjectName ([" myfunc" ]), args : [Identifier (" b" )], over : None , distinct : false }))], from : [TableWithJoins { relation : Table { name : ObjectName ([" table_1" ]), alias : None , args : [], with_hints : [] }, joins : [] }], selection : Some (BinaryOp { left : BinaryOp { left : Identifier (" a" ), op : Gt , right : Identifier (" b" ) }, op : And , right : BinaryOp { left : Identifier (" b" ), op : Lt , right : Value (Long (100 )) } }), group_by : [], having : None }), order_by : [OrderByExpr { expr : Identifier (" a" ), asc : Some (false ) }, OrderByExpr { expr : Identifier (" b" ), asc : None }], limit : None , offset : None , fetch : None })]
52
38
```
53
39
54
- ## Command line
55
- To parse a file and dump the results as JSON:
56
- ```
57
- $ cargo run --features json_example --example cli FILENAME.sql [--dialectname]
58
- ```
40
+
41
+ ## Features
42
+
43
+ The following optional [ crate features] ( https://doc.rust-lang.org/cargo/reference/features.html ) are available:
44
+
45
+ * ` serde ` : Adds [ Serde] ( https://serde.rs/ ) support by implementing ` Serialize ` and ` Deserialize ` for all AST nodes.
46
+ * ` visitor ` : Adds a ` Visitor ` capable of recursively walking the AST tree.
47
+
48
+
49
+ ## Syntax vs Semantics
50
+
51
+ This crate provides only a syntax parser, and tries to avoid applying
52
+ any SQL semantics, and accepts queries that specific databases would
53
+ reject, even when using that Database's specific ` Dialect ` . For
54
+ example, ` CREATE TABLE(x int, x int) ` is accepted by this crate, even
55
+ though most SQL engines will reject this statement due to the repeated
56
+ column name ` x ` .
57
+
58
+ This crate avoids semantic analysis because it varies drastically
59
+ between dialects and implementations. If you want to do semantic
60
+ analysis, feel free to use this project as a base.
59
61
60
62
## SQL compliance
61
63
@@ -81,10 +83,21 @@ that are actually used. Note that if you urgently need support for a feature,
81
83
you will likely need to write the implementation yourself. See the
82
84
[ Contributing] ( #Contributing ) section for details.
83
85
84
- ### Supporting custom SQL dialects
86
+ ## Command line
87
+
88
+ This crate contains a CLI program that can parse a file and dump the results as JSON:
89
+ ```
90
+ $ cargo run --features json_example --example cli FILENAME.sql [--dialectname]
91
+ ```
92
+
93
+ ## Users
94
+
95
+ This parser is currently being used by the [ DataFusion] query engine,
96
+ [ LocustDB] , [ Ballista] and [ GlueSQL] .
97
+
98
+ If your project is using sqlparser-rs feel free to make a PR to add it
99
+ to this list.
85
100
86
- This is a work in progress, but we have some notes on [ writing a custom SQL
87
- parser] ( docs/custom_sql_parser.md ) .
88
101
89
102
## Design
90
103
@@ -103,6 +116,11 @@ reasons:
103
116
- It is far easier to extend and make dialect-specific extensions
104
117
compared to using a parser generator
105
118
119
+ ### Supporting custom SQL dialects
120
+
121
+ This is a work in progress, but we have some notes on [ writing a custom SQL
122
+ parser] ( docs/custom_sql_parser.md ) .
123
+
106
124
## Contributing
107
125
108
126
Contributions are highly encouraged! However, the bandwidth we have to
0 commit comments