Commit graph

1680 commits

Author SHA1 Message Date
Nickolay Ponomarev
5ba9912a9d Merge remote-tracking branch 'upstream/master' 2019-03-08 17:29:54 +03:00
Andy Grove
aa1f0faad4 (cargo-release) start next development iteration 0.2.5-alpha.0 2019-03-08 07:28:37 -07:00
Andy Grove
30de48c840 (cargo-release) version 0.2.4 2019-03-08 07:28:29 -07:00
Andy Grove
4a355e6ddc
Merge pull request #42 from andygrove/revert-37-keywords
Revert "Rework keyword/identifier parsing"
2019-03-08 07:28:07 -07:00
Andy Grove
43f4c6875f
Revert "Rework keyword/identifier parsing" 2019-03-08 07:27:27 -07:00
Andy Grove
391c53d5c9 (cargo-release) start next development iteration 0.2.4-alpha.0 2019-03-08 07:20:19 -07:00
Andy Grove
6580bf10c0 (cargo-release) version 0.2.3 2019-03-08 07:20:08 -07:00
Andy Grove
75e2c0a64f
Merge pull request #37 from nickolay/keywords
Rework keyword/identifier parsing
2019-03-08 07:19:34 -07:00
Andy Grove
7c9f62962d
Merge branch 'master' into keywords 2019-03-08 06:24:24 -07:00
Andy Grove
8c1d6a67fa (cargo-release) start next development iteration 0.2.3-alpha.0 2019-03-08 06:15:48 -07:00
Andy Grove
15704f1fbe (cargo-release) version 0.2.2 2019-03-08 06:15:37 -07:00
Andy Grove
73f55fe1bb
Merge pull request #36 from nickolay/strings
Clean up string-related variants in Token and Value
2019-03-08 06:14:59 -07:00
Andy Grove
ff897b9086
Merge pull request #38 from nickolay/remove-duplicate-tests
Remove sqlparser_generic.rs/sqlparser_postgres.rs duplication
2019-03-08 06:09:25 -07:00
Nickolay Ponomarev
0621f8d43c Merge https://github.com/nickolay/sqlparser-rs/pull/1 from benesch/materialized 2019-03-08 15:49:53 +03:00
Nickolay Ponomarev
f30ab89ad2 Re-run cargo fmt 2019-03-08 15:46:40 +03:00
Nikhil Benesch
23a0fc79f5
Support CREATE MATERIALIZED VIEW 2019-03-07 13:14:33 -05:00
Nickolay Ponomarev
52e0f55b6f Support UNION/EXCEPT/INTERSECT 2019-02-11 05:14:36 +03:00
Nickolay Ponomarev
533775c0da Support CHAR synonym for CHARACTER
https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#character-string-type
2019-02-11 05:14:34 +03:00
Nickolay Ponomarev
23a0d032bd Support NUMERIC without precision or scale
https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#exact-numeric-type
2019-02-11 05:13:48 +03:00
Nickolay Ponomarev
54c9ca8619 Support unary + / - 2019-02-11 05:13:48 +03:00
Nickolay Ponomarev
786b1cf18a Support BETWEEN 2019-02-11 05:13:48 +03:00
Nickolay Ponomarev
264319347d Support IN 2019-02-11 05:13:48 +03:00
Nickolay Ponomarev
bed03abe44 Support AS and qualified wildcards in SELECT 2019-02-11 05:13:48 +03:00
Nickolay Ponomarev
bf0c07bb1b Support basic CTEs (WITH)
Some unsupported features are noted as TODOs.
2019-02-11 05:13:48 +03:00
Nickolay Ponomarev
f958e9d3cf TBD fixup multiline comment tokenization 2019-02-11 05:13:48 +03:00
Nickolay Ponomarev
028c613c3f Support comments in the tokenizer 2019-02-07 05:34:38 +03:00
Nickolay Ponomarev
35dd9342e2 Support national string literals (N'...')
Widely used in MS SQL and specified in ANSI.
2019-02-07 05:34:33 +03:00
Nickolay Ponomarev
b9f4b503b6 Support different quoting styles for delimited identifiers
The dialect information is from https://en.wikibooks.org/wiki/SQL_Dialects_Reference/Data_structure_definition/Delimited_identifiers
2019-02-07 05:34:29 +03:00
Nickolay Ponomarev
b3693bfa63 Simplify quoted identifier tokenization 2019-02-07 05:34:26 +03:00
Nickolay Ponomarev
2e9da53ed3 Small CLI app that can be used to test parsing an external SQL file 2019-02-07 05:34:16 +03:00
Nickolay Ponomarev
577e634f3c Update README to the recent changes in the AST 2019-02-07 05:34:16 +03:00
Nickolay Ponomarev
0c0cbcaff4 Support basic CREATE VIEW 2019-02-07 05:34:12 +03:00
Nickolay Ponomarev
346d1ff2e4 Improve error messages in parse_create()
By not swallowing the Err from parse_data_type().

Also switch to `match` to enable parsing table-level constraints in this
loop later.
2019-02-07 05:34:09 +03:00
Nickolay Ponomarev
a0f625b949 Simplify parse_create() a little
Don't need the duplicate `columns.push()` + we advance the tokenizer,
so no need to peek first.
2019-02-07 05:34:06 +03:00
Nickolay Ponomarev
89602dc044 Fix a typo in parse_value error message 2019-02-07 05:34:03 +03:00
Nickolay Ponomarev
b716ffb937 Simplify JOIN USING (columns)
...by reusing `parse_column_names` instead of extracting identifiers
out of the `parse_expr_list`s result.
2019-02-07 05:34:00 +03:00
Nickolay Ponomarev
05a70a358a Assert when an unknown keyword was passed to parse_keyword()
This happens all the time when I forget to check that the keyword I wanted
to use is actually listed in keywords.rs, this should help with debugging.
2019-02-07 05:33:57 +03:00
Nickolay Ponomarev
6b107065ac Switch some tests to verified_select_stmt
(the tests affected by "unboxing" in the previous commits.)
2019-02-07 05:33:54 +03:00
Nickolay Ponomarev
e3b981a0e2 Don't Box<ASTNode> in SQLSelect
Instead change ASTNode::SQLSubquery to be Box<SQLSelect>
2019-02-07 05:33:51 +03:00
Nickolay Ponomarev
c5bbfc33fd Don't Box<ASTNode> in SQLStatement
This used to be needed when it was a variant in the ASTNode enum itself.
2019-02-07 05:33:46 +03:00
Nickolay Ponomarev
3619e89e9c Remove Box<> from SQLOrderByExpr
It was probably copied from somewhere else when most types were variants
in ASTNode, and needed Box<> to prevent recursion in the ASTNode definition.
2019-02-07 05:33:43 +03:00
Nickolay Ponomarev
9967031cba Move TableFactor to be a separate enum
ASTNode can now be renamed SQLExpression, as it represents a node in
the "expression" part of the AST -- other nodes have their own types.
2019-02-07 05:33:41 +03:00
Nickolay Ponomarev
e0ceacd1ad Store original, quoted form in SQLIdent
Also move more things to use SQLIdent instead of String in the hope of
making it a newtype eventually.

Add tests that quoted identifiers round-trip parsing/serialization correctly.
2019-02-07 05:33:12 +03:00
Nickolay Ponomarev
07790fe4c4 Improve DELETE FROM parsing (4.4/4.4)
Store (and parse) `table_name: SQLObjectName` instead of
`relation: Option<Box<ASTNode>>`, which can be an arbitrary expression.

Also remove the `Option<>`: the table name is not optional in any dialects
I'm familiar with. While the FROM keyword itself _is_ optional in some
dialects, there are more things to implement for those dialects, see
https://stackoverflow.com/a/4484271/1026
2019-02-07 05:31:51 +03:00
Nickolay Ponomarev
f5bd9c398f Simplify by avoiding SQLCompoundIdentifier (4.3/4.4)
...instead make `parse_compound_identifier()` return the underlying
Vec<> directly, and rename it to `parse_list_of_ids()`, since it's
used both for parsing compound identifiers and lists of identifiers.
2019-02-07 05:31:47 +03:00
Nickolay Ponomarev
39e98cb11a Rename parse_tablename -> parse_object_name (4.2/4.4)
...to match the name of the recently introduced `SQLObjectName` struct
and to avoid any reservations about using it with multi-part names of
objects other than tables (as in the `type_name` case).
2019-02-07 05:31:44 +03:00
Nickolay Ponomarev
523f086be7 Introduce SQLObjectName struct (4.1/4.4)
(To store "A name of a table, view, custom type, etc., possibly
multi-part, i.e. db.schema.obj".)

Before this change

  - some places used `String` for this (these are updated in this commit)

  - while others (notably SQLStatement::SQLDelete::relation, which is
    the reason for this series of commits) relied on
    ASTNode::SQLCompoundIdentifier (which is also backed by a 
    Vec<SQLIdent>, but, as a variant of ASTNode enum, is not convenient
    to use when you know you need that specific variant).
2019-02-07 05:31:40 +03:00
Nickolay Ponomarev
215820ef66 Stricter parsing for subqueries (3/4)
This makes the parser more strict when handling SELECTs nested
somewhere in the main statement:

1) instead of accepting SELECT anywhere in the expression where an
   operand was expected, we only accept it inside parens. (I've added a
   test for the currently supported syntax, <scalar subquery> in ANSI
   SQL terms)

2) instead of accepting any expression in the derived table context:
   `FROM ( ... )` - we only look for a SELECT subquery there.

Due to #1, I had to swith the 'ansi' test from invoking the expression
parser to the statement parser.
2019-02-07 05:31:36 +03:00
Nickolay Ponomarev
82dc581639 Fix precedence for the NOT operator (2/4)
I checked the docs of a few of the most popular RDBMSes, and it seems
there's consensus that the precedence of `NOT` is higher than `AND`,
but lower than `IS NULL`.

Postgresql[1], Oracle[2] and MySQL[3] docs say that explicitly.

T-SQL docs[4] do mention it's higher than `AND`, and while they don't
explicitly mention IS NULL, this snippet:

    select * from (select 1 as a)x
    where (not x.a) is null

...is a parsing error, while the following works like IS NOT NULL:

    select * from (select 1 as a)x
    where not x.a is null

sqlite doesn't seem to mention `NOT` precedence, but I assume it works
similarly.

[1] https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-OPERATORS
[2] https://docs.oracle.com/cd/B19306_01/server.102/b14200/conditions001.htm#i1034834
[3] https://dev.mysql.com/doc/refman/8.0/en/operator-precedence.html
[4] https://docs.microsoft.com/en-us/sql/t-sql/language-elements/operator-precedence-transact-sql?view=sql-server-2017
2019-02-07 05:24:55 +03:00
Nickolay Ponomarev
29db619792 Stop losing parens when roundtripping (1/4)
Before this change an expression like `(a+b)-(c+d)` was parsed correctly
(as a Minus node with two Plus nodes as children), but when serializing
back to an SQL string, it came up as a+b-c+d, since we don't store
parens in AST and don't attempt to insert them when necessary during
serialization. The latter would be hard, and we already had an SQLNested
enum variant, so I changed the code to wrap the AST node for the
parenthesized expression in it.
2019-02-07 05:24:54 +03:00