You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The goal of this project is to build a SQL lexer and parser capable of parsing SQL that conforms with the [ANSI SQL:2011](https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#_5_1_sql_terminal_character) standard but also making it easy to support custom dialects so that this crate can be used as a foundation for vendor-specific parsers.
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.
10
13
11
-
This parser is currently being used by the [DataFusion](https://github.com/andygrove/datafusion) query engine and [LocustDB](https://github.com/cswinter/LocustDB).
14
+
This parser is currently being used by the [DataFusion] query engine and
15
+
[LocustDB].
12
16
13
17
## Example
14
18
15
-
The current code is capable of parsing some trivial SELECT and CREATE TABLE statements.
SQL was first standardized in 1987, and revisions of the standard have been
46
+
published regularly since. Most revisions have added significant new features to
47
+
the language, and as a result no database claims to support the full breadth of
48
+
features. This parser currently supports most of the SQL-92 syntax, plus some
49
+
syntax from newer versions that have been explicitly requested, plus some MSSQL-
50
+
and PostgreSQL-specific syntax. Whenever possible, the [online SQL:2011
51
+
grammar][sql-2011-grammar] is used to guide what syntax to accept. (We will
52
+
happily accept changes that conform to the SQL:2016 syntax as well, but that
53
+
edition's grammar is not yet available online.)
54
+
55
+
Unfortunately, stating anything more specific about compliance is difficult.
56
+
There is no publicly available test suite that can assess compliance
57
+
automatically, and doing so manually would strain the project's limited
58
+
resources. Still, we are interested in eventually supporting the full SQL
59
+
dialect, and we are slowly building out our own test suite.
60
+
61
+
If you are assessing whether this project will be suitable for your needs,
62
+
you'll likely need to experimentally verify whether it supports the subset of
63
+
SQL that you need. Please file issues about any unsupported queries that you
64
+
discover. Doing so helps us prioritize support for the portions of the standard
65
+
that are actually used. Note that if you urgently need support for a feature,
66
+
you will likely need to write the implementation yourself. See the
67
+
[Contributing](#Contributing) section for details.
68
+
69
+
### Supporting custom SQL dialects
70
+
71
+
This is a work in progress, but we have some notes on [writing a custom SQL
72
+
parser](docs/custom_sql_parser.md).
73
+
36
74
## Design
37
75
38
-
This parser is implemented using the [Pratt Parser](https://tdop.github.io/) design, which is a top-down operator-precedence parser.
76
+
The core expression parser uses the [Pratt Parser] design, which is a top-down
77
+
operator-precedence (TDOP) parser, while the surrounding SQL statement parser is
78
+
a traditional, hand-written recursive descent parser. Eli Bendersky has a good
79
+
[tutorial on TDOP parsers][tdop-tutorial], if you are interested in learning
80
+
more about the technique.
39
81
40
-
I am a fan of this design pattern over parser generators for the following reasons:
82
+
We are a fan of this design pattern over parser generators for the following
83
+
reasons:
41
84
42
-
- Code is simple to write and can be concise and elegant (this is far from true for this current implementation unfortunately, but I hope to fix that using some macros)
85
+
- Code is simple to write and can be concise and elegant
43
86
- Performance is generally better than code generated by parser generators
44
87
- Debugging is much easier with hand-written code
45
-
- It is far easier to extend and make dialect-specific extensions compared to using a parser generator
46
-
47
-
## Supporting custom SQL dialects
48
-
49
-
This is a work in progress but I started some notes on [writing a custom SQL parser](docs/custom_sql_parser.md).
88
+
- It is far easier to extend and make dialect-specific extensions
89
+
compared to using a parser generator
50
90
51
91
## Contributing
52
92
53
-
Contributors are welcome! Please see the [current issues](https://github.com/andygrove/sqlparser-rs/issues) and feel free to file more!
54
-
55
-
Please run [cargo fmt](https://github.com/rust-lang/rustfmt#on-the-stable-toolchain) to ensure the code is properly formatted.
93
+
Contributions are highly encouraged!
94
+
95
+
Pull requests that add support for or fix a bug in a feature in the SQL
96
+
standard, or a feature in a popular RDBMS, like Microsoft SQL Server or
97
+
PostgreSQL, will almost certainly be accepted after a brief review. For
98
+
particularly large or invasive changes, consider opening an issue first,
99
+
especially if you are a first time contributor, so that you can coordinate with
100
+
the maintainers. CI will ensure that your code passes `cargo test`,
101
+
`cargo fmt`, and `cargo clippy`, so you will likely want to run all three
102
+
commands locally before submitting your PR.
103
+
104
+
If you are unable to submit a patch, feel free to file an issue instead. Please
105
+
try to include:
106
+
107
+
* some representative examples of the syntax you wish to support or fix;
108
+
* the relevant bits of the [SQL grammar][sql-2011-grammar], if the syntax is
109
+
part of SQL:2011; and
110
+
* links to documentation for the feature for a few of the most popular
111
+
databases that support it.
112
+
113
+
Please be aware that, while we strive to address bugs and review PRs quickly, we
114
+
make no such guarantees for feature requests. If you need support for a feature,
115
+
you will likely need to implement it yourself. Our goal as maintainers is to
116
+
facilitate the integration of various features from various contributors, but
117
+
not to provide the implementations ourselves, as we simply don't have the
0 commit comments