Nikhil Benesch
9e33cea9b8
Standardize BinaryOp and UnaryOp nodes
...
These were previously called "BinaryExpr" and "Unary"; besides being
inconsistent, it's also not correct to say "binary expression" or "unary
expression", as it's the operators that have arities, not the
expression. Adjust the naming of the variants accordingly.
2019-06-10 23:02:17 -04:00
Andy Grove
b379480b7a
Merge pull request #79 from benesch/license
...
Standardize license headers
2019-06-10 19:39:12 -06:00
Nikhil Benesch
ce171c2a3d
Support VALUES and parenthesized SELECTs as top-level statements
2019-06-10 11:11:26 -04:00
Nikhil Benesch
b841dccc2c
Properly handle mixed implicit and explicit joins
...
Parse a query like
SELECT * FROM a NATURAL JOIN b, c NATURAL JOIN d
as the SQL specification requires, i.e.:
from: [
TableReference {
relation: TableFactor::Table("a"),
joins: [Join {
relation: TableFactor::Table("b"),
join_operator: JoinOperator::Natural,
}]
},
TableReference {
relation: TableFactor::Table("c"),
joins: [Join {
relation: TableFactor::Table("d"),
join_operator: JoinOperator::Natural,
}]
}
]
Previously we were parsing such queries as
relation: TableFactor::Table("a"),
joins: [
Join {
relation: TableFactor::Table("b"),
join_operator: JoinOperator::Natural,
},
Join {
relation: TableFactor::Table("c"),
join_operator: JoinOperator::Implicit,
},
Join {
relation: TableFactor::Table("d"),
join_operator: JoinOperator::Natural,
},
]
which did not make the join hierarchy clear.
2019-06-10 11:11:25 -04:00
Nickolay Ponomarev
518c8833d2
Merge pull request #110 from nickolay/pr/cleanups
...
Minor code clean-ups
2019-06-09 20:24:13 +03:00
Nikhil Benesch
2d1e05e21d
Merge pull request #103 from benesch/intervals
...
Support interval literals
2019-06-09 12:41:57 -04:00
Nikhil Benesch
2798ddf5fd
Support interval literals
2019-06-09 12:37:57 -04:00
Nickolay Ponomarev
99768711dc
Fix redundant closures in tests
...
We don't have the tests checked by clippy on CI, despite [passing the
`--all-targets`](5536cd1f9e/.travis.yml (L46)
),
but VSCode+RLS display warnings for these.
See: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
2019-06-09 17:05:19 +03:00
Nikhil Benesch
5536cd1f9e
Merge pull request #106 from offscale/transactions
...
Transaction support
2019-06-09 01:35:05 -04:00
Nikhil Benesch
7e96d81b47
Merge pull request #93 from benesch/col-constr-order
...
Parse column constraints in any order
2019-06-09 00:36:51 -04:00
Agustin Chiappe Berrini
582b25add6
Add basic support for transaction statements
...
Co-authored-by: Samuel Marks <807580+SamuelMarks@users.noreply.github.com>
Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
2019-06-09 00:36:20 -04:00
Nikhil Benesch
ffa1c8f853
Parse column constraints in any order
...
CREATE TABLE t (a INT NOT NULL DEFAULT 1 PRIMARY KEY) is as valid as
CREATE TABLE t (a INT DEFAULT 1 PRIMARY KEY NOT NULL).
2019-06-08 12:13:55 -04:00
Nikhil Benesch
ccbd048dda
Test that redundant nesting is supported
...
SELECT * FROM (((SELECT 1))) is just as valid as
SELECT * FROM (SELECT 1). Add a test to ensure that we can parse the
first form.
Addresses a comment from #100 .
2019-06-07 23:54:56 -04:00
Nikhil Benesch
5f9f17de8a
Merge pull request #100 from benesch/nested-joins
...
Support nested joins
2019-06-07 22:37:53 -04:00
Nikhil Benesch
525f4d7501
Fix precedence of unary NOT
...
get_next_precedence deals with left-binding power, not right binding
power. Therefore, when it encounters a standalone NOT operator (i.e., a
"NOT" token that is not followed by "BETWEEN", "LIKE", or "IN"), it
should return 0, because unary NOT is not an infix operator, it's a
prefix operator, and therefore it has no left-binding power.
2019-06-06 17:20:07 -04:00
Nikhil Benesch
e78cf0483e
Standardize license headers
...
Standardize the license header, removing the Grove Enterprise copyright
notice where it exists per #58 . Also add a CI check to ensure that files
without license headers don't get merged.
Fix #58 .
2019-06-04 10:54:12 -04:00
Nikhil Benesch
8fbf82deb0
Support nested joins
...
Fix #83 .
2019-06-04 10:25:07 -04:00
Nikhil Benesch
ed3ed26bb1
Support parsing dates, times, and timestamps as strings
2019-06-04 00:12:09 -04:00
Nikhil Benesch
11fc833433
Merge pull request #96 from benesch/extract
...
Support EXTRACT function-like operator
2019-06-04 00:07:23 -04:00
Nikhil Benesch
4c2722280d
Merge pull request #98 from benesch/col-names
...
Support column names in more places
2019-06-04 00:00:07 -04:00
Nikhil Benesch
9abcac350e
Support aliasing columns
...
A table alias can specify new names for the columns within the aliased
table, in addition to a new name for the table itself.
2019-06-03 23:51:23 -04:00
Nikhil Benesch
73ed685879
Support views with explicit column names
...
A `CREATE VIEW` statement may provide names for its columns that
override the names of the columns derived from the view's query.
2019-06-03 23:50:23 -04:00
Nikhil Benesch
fdbf64c64d
Merge pull request #94 from benesch/empty-create-table
...
Support CREATE TABLE with no columns
2019-06-03 23:44:18 -04:00
Nikhil Benesch
d484756182
Support EXTRACT function-like operator
...
The EXTRACT function, for extracting components of a date from a
timestamp, has special syntax: `EXTRACT(<field> FROM <timestamp>)`.
2019-06-03 23:37:39 -04:00
Nikhil Benesch
a594375966
Merge pull request #97 from benesch/update
...
Support UPDATE statements
2019-06-03 23:32:23 -04:00
Nikhil Benesch
69f0082db6
Support arbitrary WITH options for CREATE [TABLE|VIEW]
...
Both Postgres and MSSQL accept this syntax, though the particular
options they accept differ.
2019-06-03 13:32:13 -04:00
Nikhil Benesch
b12fb34f3d
Merge pull request #95 from benesch/hex-literals
...
Support hexadecimal string literals
2019-06-03 11:49:25 -04:00
Nikhil Benesch
b8ba188191
Merge pull request #91 from benesch/from-values
...
Improve VALUES-related syntax parsing
2019-06-03 11:44:52 -04:00
Nikhil Benesch
eba3983268
Support hexadecimal string literals
2019-06-03 11:33:51 -04:00
Nikhil Benesch
7aff70772b
Merge pull request #90 from benesch/exists
...
Support EXISTS subqueries
2019-06-03 11:29:04 -04:00
Nikhil Benesch
14e07ebdda
Support arbitrary INSERT sources
...
INSERT takes arbitrary queries as sources, not just VALUES clauses. For
example, `INSERT INTO foo SELECT * FROM bar` is perfectly valid.
2019-06-03 11:27:21 -04:00
Nikhil Benesch
9420070a0d
Support VALUES clauses in FROM
...
VALUES clauses are not just valid in INSERT statements. They're also
valid (basically) anywhere table expressions are accepted, like in FROM
clauses.
2019-06-03 11:26:45 -04:00
Nikhil Benesch
975106b207
Support EXISTS subqueries
...
Fix #5 .
2019-06-03 11:14:24 -04:00
Nikhil Benesch
a3aaa49a7e
Merge pull request #89 from benesch/sqlfunction-struct
...
Extract a SQLFunction struct
2019-06-03 11:09:27 -04:00
Nikhil Benesch
1ddef7aa71
Merge pull request #92 from benesch/decimal-dec
...
Parse DECIMAL and DEC aliases for NUMERIC type
2019-06-03 11:08:18 -04:00
Nikhil Benesch
1cef68e510
Support UPDATE statements
...
Fix #10 .
2019-06-03 00:21:23 -04:00
Nikhil Benesch
b3a2a6be48
Support CREATE TABLE with no columns
...
This is weird, but supported by PostgreSQL.
2019-06-02 23:50:16 -04:00
Nikhil Benesch
054a59df12
Extract a SQLFunction struct
...
This variant is getting rather large, and it's useful downstream to be
able to pass around SQLFunction nodes without reinventing the wheel.
2019-06-02 23:00:28 -04:00
Nikhil Benesch
38fc920d7c
Parse DECIMAL and DEC aliases for NUMERIC type
2019-06-02 22:40:18 -04:00
Nickolay Ponomarev
d0f2de06ed
Refactor parse_joins, pt.2: implicit/cross/natural joins
...
- reduce duplication in the handling of implicit/cross joins and make
the flow of data slightly clearer by returning the `join` instead of
pushing it and exiting early.
(I wanted the block that currently returns `join` to return one of
JoinOperator::* tags, so that `parse_table_factor` and the construction
of the `Join` struct could happen after we've parsed the JOIN keywords,
but that seems impossible.)
- move the check for the NATURAL keyword into the block that deals with
INNER/OUTER joins that support constraints (and thus can be preceded
by "NATURAL")
- add a check for NATURAL not followed by a known join type with a test
- add more tests for NATURAL joins (we didn't have any), and fix
whitespace bug in `to_string()` that was uncovered (we emitted an
extra space: `foo NATURAL JOIN bar `)
2019-06-03 02:44:03 +03:00
Nickolay Ponomarev
ebb82b8c8f
Merge pull request #65 from nickolay/pr/ddl-improvements
...
* Rewrite parsing of `ALTER TABLE ADD CONSTRAINT`
* Support constraints in CREATE TABLE
* Change `Value::Long()` to be unsigned, use u64 consistently
* Allow trailing comma in CREATE TABLE
2019-06-02 20:53:21 +03:00
Nikhil Benesch
5847a16fff
Merge pull request #85 from benesch/clippy
...
Enable Clippy and rustfmt in CI
2019-06-02 10:51:28 -04:00
Nikhil Benesch
1cc9d2d6f5
Merge pull request #82 from benesch/not-prec
...
Fix the precedence of NOT LIKE
2019-06-02 10:49:49 -04:00
Nickolay Ponomarev
0407ed2b57
Allow trailing comma in CREATE TABLE
...
At least MSSQL supports it, not sure about others.
2019-06-02 13:54:16 +03:00
Nickolay Ponomarev
8569a61fd0
Rename AlterOperation -> AlterTableOperation
...
Since other ALTER statements will have separate sub-commands.
2019-06-02 13:54:16 +03:00
Nickolay Ponomarev
aab0c36443
Support parsing constraints in CREATE TABLE
...
<table element> ::= ... | <table constraint definition> | ...
https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#table-element-list
2019-06-02 13:54:16 +03:00
Nickolay Ponomarev
c69a1881c7
Change ALTER TABLE constraints parsing
...
- merge PrimaryKey and UniqueKey variants
- support `CHECK` constraints, removing the separate `Key` struct
- make `CONSTRAINT constraint_name` optional
- remove `KEY` without qualifiers (wasn't parsed and there doesn't
appear to be such a thing)
- change `UNIQUE KEY` -> `UNIQUE`
- change `REMOVE CONSTRAINT` -> `DROP CONSTRAINT` and note its parsing
is not implemented
Spec:
- ANSI SQL: see <table constraint definition> in https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#_11_6_table_constraint_definition
- Postgres: look for "and table_constraint is:" in https://www.postgresql.org/docs/11/sql-altertable.html
2019-06-02 13:54:11 +03:00
Nickolay Ponomarev
93c9000102
[mssql] Support single-quoted column aliases
2019-06-02 13:48:14 +03:00
Nikhil Benesch
90bcf55a6a
Fix the precedence of NOT LIKE
...
NOT LIKE has the same precedence as the LIKE operator. The parser was
previously assigning it the precedence of the unary NOT operator. NOT
BETWEEN and NOT IN are treated similarly, as they are equivalent, from a
precedence perspective, to NOT LIKE.
The fix for this requires associating precedences with sequences of
tokens, rather than single tokens, so that "NOT LIKE" and "NOT <expr>"
can have different preferences. Perhaps surprisingly, this change is not
very invasive.
An alternative I considered involved adjusting the tokenizer to lex
NOT, NOT LIKE, NOT BETWEEN, and NOT IN as separate tokens. This broke
symmetry in strange ways, though, as NotLike, NotBetween, and NotIn
gained dedicated tokens, while LIKE, BETWEEN, and IN remained as
stringly identifiers.
Fixes #81 .
2019-06-01 02:52:18 -04:00
Justin Haug
2d00ea7187
Add lateral derived support
2019-05-31 18:10:25 -04:00