This implements `DROP [ COLUMN ] [ IF EXISTS ] column_name [ CASCADE ]`
sub-command of `ALTER TABLE`, which is what PostgreSQL supports https://www.postgresql.org/docs/12/sql-altertable.html
(except for the RESTRICT option)
Co-authored-by: Nickolay Ponomarev <asqueella@gmail.com>
Fixes#168 by enabling `DATE` and other keywords to be used as
identifiers when not followed by a string literal.
A "typed string" is our term for generalized version of `DATE '...'`/`TIME '...'`/
`TIMESTAMP '...'` literals, represented as `TypedString { data_type, value }`
in the AST.
Unlike DATE/TIME/TIMESTAMP literals, this is a non-standard extension
supported by PostgreSQL at least.
This is a port of MaterializeInc/materialize#3146
Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
Co-authored-by: Nickolay Ponomarev <asqueella@gmail.com>
This simplifies codes slightly, removing the need deal with the EOF case explicitly.
The clone kludge in `_ => self.expected("date/time field",
Token::Word(w.clone())))` will become unnecessary once we stop using
a separate match for the keywords, as suggested in
https://github.com/andygrove/sqlparser-rs/pull/193#issuecomment-641607194
Alter INTERVAL to support postgres syntax
This patch updates our INTERVAL implementation such that the Postgres
and Redshfit variation of the syntax is supported: namely that 'leading
field' is optional.
Fixes#177.
This patch provides an initial implemenation of LISTAGG[1]. Notably this
implemenation deviates from ANSI SQL by allowing both WITHIN GROUP and
the delimiter to be optional. We do so because Redshift SQL works this
way and this approach is ultimately more flexible.
Fixes#169.
[1] https://modern-sql.com/feature/listagg
Specifically, `FOREIGN KEY REFERENCES <foreign_table> (<referred_columns>)`
can now be followed by `ON DELETE <referential_action>` and/or by
`ON UPDATE <referential_action>`.
The Ident type was previously an alias for a String. Turn it into a full
fledged struct, so that the parser can preserve the distinction between
identifier value and quote style already made by the tokenizer's Word
structure.
The SQL standard requires that numeric literals with a decimal point,
like 1.23, are represented exactly, up to some precision. That means
that parsing these literals into f64s is invalid, as it is impossible
to represent many decimal numbers exactly in binary floating point (for
example, 0.3).
This commit parses all numeric literals into a new `Value` variant
`Number(String)`, removing the old `Long(u64)` and `Double(f64)`
variants. This is slightly less convenient for downstream consumers, but
far more flexible, as numbers that do not fit into a u64 and f64 are now
representable.
The note about WindowFrameBound::Following being only valid "in
WindowFrame::end_bound" was both
- confusing, as it was based on the ANSI SQL syntax the parser doesn't
adhere to -- though it sounded like a promise about the AST one could
expect to get from the parser
- and incomplete, as the reality is that the bounds validation the SQL
engine might want to perform is more complex. For example Postgres
documentation says <https://www.postgresql.org/docs/11/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS>:
> Restrictions are that frame_start cannot be UNBOUNDED FOLLOWING,
> frame_end cannot be UNBOUNDED PRECEDING, and the frame_end choice
> cannot appear earlier in the above list of frame_start and frame_end
> options than the frame_start choice does — for example RANGE BETWEEN
> CURRENT ROW AND offset PRECEDING is not allowed. But, for example,
> ROWS BETWEEN 7 PRECEDING AND 8 PRECEDING is allowed, even though it
> would never select any rows.
It used to consume the `RParen` closing the encompassing `OVER (`, even
when no window frame was parsed, which confused me a bit, even though
I wrote it initially.
After fixing that, I took the opportunity to reduce nesting and
duplication a bit.
To use the new helper effectively, a few related changes were required:
- Each of the parse_..._list functions (`parse_cte_list`,
`parse_order_by_expr_list`, `parse_select_list`) was replaced with a
version that parses a single element of the list (e.g. `parse_cte`),
with their callers now using
`self.parse_comma_separated(Parser::parse_<one_element>)?`
- `parse_with_options` now parses the WITH keyword and a separate
`parse_sql_option` function (named after the struct it produces) was
added to parse a single k=v option.
- `parse_list_of_ids` is gone, with the '.'-separated parsing moved to
`parse_object_name`.
Custom comma-separated parsing is still used in:
- parse_transaction_modes (where the comma separator is optional)
- parse_columns (allows optional trailing comma, before the closing ')')
I realized a moment too late that I'd missed a type name in
when removing the "SQL" prefix from types in ac555d7e8. As far as I can
tell, this was the only oversight.
The rationale here is the same as the last commit: since this crate
exclusively parses SQL, there's no need to restate that in every type
name. (The prefix seems to be an artifact of this crate's history as a
submodule of Datafusion, where it was useful to explicitly call out
which types were related to SQL parsing.)
This commit has the additional benefit of making all type names
consistent; over type we'd added some types which were not prefixed with
"SQL".