Commit graph

752 commits

Author SHA1 Message Date
mz
a53f1d26ef
Support SQLite CREATE VIRTUAL TABLE (#209)
`CREATE VIRTUAL TABLE .. USING <module_name> (<module_args>)`

https://www.sqlite.org/lang_createvtab.html
2020-06-28 04:31:33 +03:00
mz
0c83e5d9e8
Support SQLite's WITHOUT ROWID in CREATE TABLE (#208)
Per https://sqlite.org/lang_createtable.html

Co-authored-by: mashuai <mashuai@bytedance.com>
2020-06-26 15:11:46 +03:00
Nickolay Ponomarev
0c82be5c3b Follow-up to the recent release (CHANGELOG and the bench crate) 2020-06-26 15:00:12 +03:00
Andy Grove
1946791302 (cargo-release) start next development iteration 0.5.2-alpha.0 2020-06-25 20:46:29 -06:00
Andy Grove
05f8992a2f (cargo-release) version 0.5.1 2020-06-25 20:46:18 -06:00
Daniël Heres
15d5f71646
Add CREATE TABLE AS support (#206)
We parse it as a regular `CREATE TABLE` statement
followed by an `AS <query>`, which is how BigQuery works:
https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_table_statement


ANSI SQL and PostgreSQL only support a plain list of columns
after the table name in a CTAS
    `CREATE TABLE t (a) AS SELECT a FROM foo`

We currently only allow specifying a full schema with data
types, or omitting it altogether.

https://www.postgresql.org/docs/12/sql-createtableas.html
https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#as-subquery-clause


Finally, when no schema is specified, we print empty parens after a
plain `CREATE TABLE t ();` as required by PostgreSQL, but skip them
in a CTAS: `CREATE TABLE t AS ...`. This affects serialization only,
the parser allows omitting the schema in a regular `CREATE TABLE` too
since the first release of the parser:
7d27abdfb4/src/sqlparser.rs (L325-L332)

Co-authored-by: Nickolay Ponomarev <asqueella@gmail.com>
2020-06-23 16:30:22 +03:00
Jovansonlee Cesar
26361fd854
Implement ALTER TABLE DROP COLUMN (#148)
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>
2020-06-16 23:39:52 +03:00
mz
faeb7d440a
Implement ALTER TABLE ADD COLUMN and RENAME (#203)
Based on sqlite grammar
https://www.sqlite.org/lang_altertable.html
2020-06-16 22:52:37 +03:00
Daniël Heres
fab6e28271
Output DataType capitalized (#202)
This makes it consistent with other output which also prints keywords capitalized.
2020-06-13 16:18:44 +03:00
Daniël Heres
b24dbe513c
Replace FromStr with normal parser function for FileFormat (#201)
The previous version accepted quoting file format keywords
(`STORED AS "TEXTFILE"`) and was inconsistent with the
way WindowFrameUnits was parsed.
2020-06-13 15:38:01 +03:00
Daniël Heres
68afa2a764
Make FileFormat case insensitive (#200) 2020-06-12 18:10:44 +03:00
Taehoon Moon
a0f076acda
Make the cli example print JSON (#197)
...via the new json_example feature - to make it easier to try out the parser without coding.
2020-06-12 16:38:59 +03:00
Daniël Heres
f4fbd9b6b3
Take slice as input for parse_keywords (#199) 2020-06-12 02:10:17 +03:00
Max Countryman
6cdd4a146d
Support general "typed string" literals (#187)
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>
2020-06-12 00:04:43 +03:00
Daniël Heres
34548e890b
Change Word::keyword to a enum (#193)
This improves performance and paves the way to future API enhancements as discussed in the PR https://github.com/andygrove/sqlparser-rs/pull/193
2020-06-11 22:00:35 +03:00
Nickolay Ponomarev
0fe3a8ec39
Use Token::EOF instead of Option<Token> (#195)
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
2020-06-10 14:05:17 +03:00
Taehoon Moon
2f1015339a
Add serde support to AST structs and enums (#196)
Apply serde to AST structs and enums to be serializable/deserializable.
serde support is optional, can be activated by feature named "serde".
2020-06-10 12:53:52 +03:00
Nickolay Ponomarev
d9a7491d9a Various follow-ups to recent pushes
- Update CHANGELOG
- Update `.gitignore` for the build directory of the benchmark crate
- Remove src/lib from the recently added benchmark crate per
  https://github.com/andygrove/sqlparser-rs/pull/190#pullrequestreview-425835379
2020-06-10 09:40:42 +03:00
Max Countryman
846c52f450
Allow omitting units after INTERVAL (#184)
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.
2020-06-10 09:32:13 +03:00
Daniël Heres
d842f495db
Add line and column number to TokenizerError (#194)
Addresses https://github.com/andygrove/sqlparser-rs/issues/179 for tokenize errors
2020-06-10 09:15:44 +03:00
Nickolay Ponomarev
10b0b7f884
Update CHANGELOG (#192)
Also remove a comment with a trailing space, which rustfmt doesn't like
2020-06-07 20:43:44 +03:00
Daniël Heres
a42121de52
Use binary search to speed up matching keywords (#191) 2020-06-07 20:25:10 +03:00
Max Countryman
af54eb02b2
Rework github actions, add code coverage (#186)
This reworks our GitHub Actions workflow to include code coverage via
tarpaulin.

Fixes #164.
2020-06-07 20:15:31 +03:00
Daniël Heres
6e6fae73a0
Add benchmarks using cargo bench / criterion (#190) 2020-06-07 16:46:55 +03:00
Daniël Heres
d32df527e6
Accept &str in Parse::parse_sql (#182)
It is more generic to accept a `&str` than a `String` in an API,
and avoids having to convert a string to a `String` when not
needed, avoiding a copy.
2020-06-03 23:31:41 +03:00
Daniël Heres
b4699bd4a7
Support bitwise and, or, xor (#181)
Operator precedence is coming from:

https://cloud.google.com/bigquery/docs/reference/standard-sql/operators
2020-06-03 19:02:05 +03:00
Daniël Heres
00dc490f72
Support the string concat operator (#178)
The selected precedence is based on BigQuery documentation, where it is equal to `*` and `/`:

https://cloud.google.com/bigquery/docs/reference/standard-sql/operators
2020-06-02 21:24:30 +03:00
Max Countryman
5f3c1bda01
Provide LISTAGG implementation (#174)
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
2020-05-30 18:50:17 +03:00
QP Hou
418b9631ce
add nulls first/last support to order by expression (#176)
Following `<sort specification list>` from the standard https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#_10_10_sort_specification_list
2020-05-30 17:05:15 +03:00
Nickolay Ponomarev
c918ff042d
Merge pull request #173 from alex-dukhno/create-schema
Support `CREATE SCHEMA schema_name` and `DROP SCHEMA schema_name`.

Both ANSI SQL and Posgres define a number of options for the CREATE SCHEMA statement.
They also support including other CREATE statements as part of the schema definition,
rather than separate statements. This PR supports neither.
2020-05-28 21:05:34 +03:00
Alex Dukhno
91f769e460 added create and drop schema 2020-05-28 19:50:16 +03:00
Nickolay Ponomarev
b28dd82838
Merge pull request #172 from nickolay/pr/readme
documentation updates
2020-05-27 19:49:50 +03:00
Nickolay Ponomarev
1cf9e5ecef Update README: we support bits and pieces from other dialects too 2020-05-27 19:45:18 +03:00
Nickolay Ponomarev
a2f4996bdd Update README to point to SQL:2016, instead of 2011
This was discussed in #125, but we forgot to update the README at the time.
2020-05-27 19:45:18 +03:00
Nickolay Ponomarev
8d5eaf95b3 Update CHANGELOG 2020-05-27 19:44:59 +03:00
Christoph Müller
98f97d09db
Add support for "on delete cascade" column option (#170)
Specifically, `FOREIGN KEY REFERENCES <foreign_table> (<referred_columns>)`
can now be followed by `ON DELETE <referential_action>` and/or by
`ON UPDATE <referential_action>`.
2020-05-27 18:24:23 +03:00
Nickolay Ponomarev
789fcc8521
Merge pull request #167 from mashuai/add_index_support
Adds support for the most common forms of CREATE INDEX, and for DROP INDEX:

	CREATE [ UNIQUE ] INDEX [ IF NOT EXISTS ]
	    <index_name>
	    ON <table_name>
	    ( col_name [, ...] )

	DROP INDEX <index_name>
2020-05-27 05:13:06 +03:00
Nickolay Ponomarev
320d2f2d05 Update CHANGELOG.md and a fix last-minute review nit 2020-05-27 05:04:22 +03:00
mashuai
5aacc5ebcd add create index and drop index support 2020-05-27 09:27:57 +08:00
Nickolay Ponomarev
2644bc4ac7
Merge pull request #171 from nickolay/master
Fix GitHub CI failures.
2020-05-26 21:47:25 +03:00
Nickolay Ponomarev
8406a938d5 Port the changes made to travis configuration in #159 to GitHub workflows
This should fix the build failures due to unavailable components, e.g.

error: component 'rustfmt' for target 'x86_64-unknown-linux-gnu' is unavailable for download for channel nightly
Sometimes not all components are available in any given nightly.
2020-05-26 21:35:12 +03:00
Nickolay Ponomarev
f614481133
Merge pull request #165 from nickolay/pr/unterminated-string-literal
Report an error on unterminated string literals (and more)
2020-05-26 06:42:35 +03:00
Nickolay Ponomarev
7d60bfd866 Update CHANGELOG.md 2020-05-10 21:50:06 +03:00
Nickolay Ponomarev
327e6cd9f1 Report an error for unterminated string literals
...updated the TODOs regarding single-quoted literals parsing while at it.
2020-05-10 21:21:01 +03:00
Nickolay Ponomarev
40853fe412 Fix a recently implemented clippy lint
https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
"Import with single component use path such as `use cratename;`
is not necessary, and thus should be removed."
2020-05-10 21:16:25 +03:00
Alex Dukhno
5ad578e3e5
Implement CREATE TABLE IF NOT EXISTS (#163)
A non-standard feature supported at least by Postgres

https://www.postgresql.org/docs/12/sql-createtable.html
2020-04-21 16:28:02 +03:00
Nickolay Ponomarev
06865113d7 Update comments (follow-up to PR #158) 2020-04-20 05:43:57 +03:00
Nickolay Ponomarev
af852e78f6
Merge pull request #158 from mjibson/offset-rows
Add support for OFFSET without the ROWS keyword (a MySQL quirk, documented at https://dev.mysql.com/doc/refman/8.0/en/select.html)

Teach the parser to remember which variant it saw (ROWS/ROW/none).
2020-04-20 05:38:04 +03:00
Nickolay Ponomarev
5fe9060d4e
Merge pull request #162 from alex-dukhno/derive-defaul-for-generic-dialect
derive default for GenericDialect
2020-04-20 05:13:12 +03:00
Matt Jibson
c0b0b5924d Add support for OFFSET with the ROWS keyword
MySQL doesn't support the ROWS part of OFFSET. Teach the parser to
remember which variant it saw, including just ROW.
2020-04-19 20:06:08 -06:00