Commit graph

294 commits

Author SHA1 Message Date
Dmitry Patsura
66a3082cb6
feat: Support FETCH (cursors) (#510) 2022-06-04 14:24:36 -04:00
Riccardo Azzolini
d19c6c323c
Fix escaping of trailing quote in quoted identifiers (#505)
* Generalize EscapeSingleQuoteString to arbitrary quote character

* Fix escaping of trailing quote in quoted identifiers

* Add new tests instead of modifying existing tests
2022-05-27 06:25:24 -04:00
Riccardo Azzolini
901f5b974f
Distinguish between tables and nullary functions in FROM (#506) 2022-05-25 16:01:13 -04:00
Dmitry Patsura
2c0886d9fe
feat: Support escaped string literals (PostgreSQL) (#502)
* feat: Support escaped string literals (PostgreSQL)

Signed-off-by: Dmitry Patsura <talk@dmtry.me>

* lint

* escape ', \r, \t

* Update src/ast/value.rs

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

* Update src/tokenizer.rs

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

* test: two slashes

* remove dead code

* test: parsing error

* support generic dialect too (for DF)

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
2022-05-25 14:42:14 -04:00
Andrew Lamb
11046f66e7
Correct typo: indexs to indexes (#492) 2022-05-22 15:03:48 -04:00
Poonai
ed86c6d53d
add support for postgres composite types (#466)
* add support for postgres composite types

Signed-off-by: password <rbalajis25@gmail.com>

* fix composite test for bigdecimal feature

Signed-off-by: password <rbalajis25@gmail.com>
2022-05-09 15:12:22 -04:00
Maciej Obuchowski
6d057ef4df
set: allow dots in variables by moving to ObjectName (#484)
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
2022-05-09 14:21:20 -04:00
Dmitry Patsura
e68bdae5f2
feat: Allow ArrayIndex for GenericDialect (#480)
* feat: Allow ArrayIndex for GenericDialect

* test array index with generic dialect too
2022-05-04 20:20:45 -04:00
Maciej Skrzypkowski
7fc6361fe8
Add Redshift dialect, handle square brackets properly (#471)
* Redshift square bracket handling

We need to detect `[` or `"` for Redshift quotes around indentifier and at the same time exclude
treating JSON paths as indentifer

* RedshiftSqlDialect documentation update

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

* Renamed _chars to chars

* Fixed warnings

* Missing license

Co-authored-by: Maciej Skrzypkowski <maciej.skrzypkowski@satoricyber.com>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
2022-05-04 11:11:00 -04:00
Maciej Obuchowski
525ba527bb
snowflake: add qualify expression (#465)
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
2022-04-29 14:11:11 -04:00
George Andronchik
0924870d11
Support global,local, on commit for create temporary table (#456)
* feat: add global,local / on commit for create temp tables

* chore: minor refactor

* chore: clippy fix
2022-04-22 07:58:39 -04:00
Poonai
d035784bdf
Add support for postgres json operators ->, ->>, #>, and #>> (#458)
* add support for postgres json selection

Signed-off-by: password <rbalajis25@gmail.com>

* fix clippy

Signed-off-by: password <rbalajis25@gmail.com>

* add support for postgres `#>` and `#>>` json operator

* fix clippy

Signed-off-by: poonai <rbalajis25@gmail.com>

* resolve comments

Signed-off-by: password <rbalajis25@gmail.com>
2022-04-19 15:46:56 -04:00
slhmy
8f207db059
Support 'SET ROLE' statement (#455) 2022-04-13 14:45:53 -04:00
Runji Wang
bfd416d978
Add support for more postgres COPY options (#446)
* implement parsing COPY statement

* support COPY option syntax before PostgreSQL version 9.0

Signed-off-by: Runji Wang <wangrunji0408@163.com>

* update COPY tests

Signed-off-by: Runji Wang <wangrunji0408@163.com>

* improve docs for COPY

Signed-off-by: Runji Wang <wangrunji0408@163.com>

* test and fix AS in COPY

Signed-off-by: Runji Wang <wangrunji0408@163.com>

* recover original test cases

* fix cargo clippy
2022-04-03 06:37:12 -04:00
slhmy
fd8f2df10d
Support Update Set From statement (#450) 2022-04-02 06:34:59 -04:00
Matthew Turner
b68e9a3801
Add support for COPY TO (#441)
* Start adding COPY TO

* Fix statement and add tests

* Merge copy statements

* Remove extra line

* Clippy

* Cleanup
2022-03-22 18:21:44 -04:00
Poonai
12a3e97ef3
add support for SAVEPOINT statement (#438) 2022-03-13 03:29:26 -04:00
Simon Liu
3f5619446f
Support for ClickHouse array types (e.g. [1,2,3]) (#429) 2022-03-08 11:44:32 -05:00
gamife
1da49c15c7
Support array expressions such as ARRAY[1,2] , foo[1] and INT[][] (#419)
* feat: add array expression

* test: add back the the existing test

Co-authored-by: gamife <gamife9886@gmail.com>
2022-02-17 07:21:11 -05:00
Markus Westerlind
34fedf311d
fix: Handle double quotes inside quoted identifiers correctly (#411)
* fix: Handle double quotes inside quoted identifiers correctly

This fixes #410 for standard SQL, however I don't know enough about other dialects to know if they
handle this differently. May need more extensive testing as well.

* refactor: Make quoted identifier parsing a seperate function

* test: Check that quoted identifier tokenization works

Added `pretty_assertions` so that the `assert_eq!` in the tokenization is readable

* test: Check that quoted identifiers work in mysql

* chore: cargo clippy
2022-02-07 10:05:17 -05:00
Poonai
2614576dbf
Add support for FROM <filename>, DELIMITER, and CSV HEADER options for COPY command (#409)
* add additional options for copy command

Signed-off-by: password <rbalajis25@gmail.com>

* cargo fmt

Signed-off-by: password <rbalajis25@gmail.com>
2022-02-07 06:33:28 -05:00
Simon Liu
60ad78dafc
Enable map access for function, add ClickHouse dialect (#382)
* 1 Add ClickHouse dialects.
2 Enable map access for function.

* 1 Fixed compilation errors.
2 Modify the code according to @alamb's comments.

* Fixed compilation errors.
2021-12-21 16:16:30 -05:00
Zach Hamlin
9569d1b215
feat: comment and alter column support (#381)
* feat: add support for postgresql comment keyword

* feat: add alter column and rename constraint
2021-12-17 12:19:08 -05:00
Poonai
4c121a92a6
support for session transaction and transaction snapshot. (#379)
* add support for snapshot id in set transaction

Signed-off-by: poonai <rbalajis25@gmail.com>

* add support for default session transaction characteristics

Signed-off-by: poonai <rbalajis25@gmail.com>

* add additional assertion for parse_set_transaction test

Signed-off-by: poonai <rbalajis25@gmail.com>

* Fix clippy

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
2021-12-14 15:13:12 -05:00
Guillaume Balaine
d498887a5d
Enable map access for numbers, multiple nesting levels (#356)
* enable integer keys for map access

* enable map access for number keys

* Add tests for string based map access

* MapAccess: unbox single quoted strings to always display double quoted strings for map access

* cargo fmt

* cargo clippy

* Fix compilation with nostd by avoiding format!

* fix codestyle

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
2021-09-24 14:22:12 -04:00
Alex Vasilev
77d90d3b85
Support minimum display width for integer data types (#337)
* Support minimum display width for integers

* make fmt happy, updated docstrings
2021-08-29 07:13:10 -04:00
Andy Grove
5ebc06b20c Update links to reflect repository move to sqlparser-rs GitHub org 2021-08-20 17:03:06 -06:00
b41sh
80759a4deb support regex match 2021-08-13 19:50:14 +08:00
Francis Du
07342d5853
Support parsing multiple show variables. (#290)
* feat: support parsing multiple show variables.

* fix: fix fmt error
2021-02-09 21:03:49 +01:00
Stephen Carman
8a214f9919
Implement Hive QL Parsing (#235) 2021-02-04 12:53:20 -07:00
Nickolay Ponomarev
4128dfe1db Introduce tests/test_utils/mod.rs and use it consistently
To share helper macros between various tests/* we added a new module
(tests/macros/mod.rs). This made the prologue to be used in tests quite
long and a little weird:
```
#[macro_use]
#[path = "macros/mod.rs"]
mod macros;
use sqlparser::test_utils::*;
```

This simplifies it to:
```
#[macro_use]
mod test_utils;
use test_utils::*;
```
- and switches all existing tests to the new prologue simultaneously...

...while fixing a few other inconsistencies and adding a few comments
about the way `test_utils` work.
2020-10-12 06:52:00 +03:00
Alex Dukhno
1ac208307c
Support IF NOT EXISTS for CREATE SCHEMA (#276)
This is a Postgres-specific clause: https://www.postgresql.org/docs/12/sql-createschema.html

Also add a test for `DROP SCHEMA IF EXISTS schema_name`, which is already supported in the parser.
2020-10-02 17:35:20 +03:00
Alex Dukhno
926b03a31d
Add parsing for PostgreSQL math operators (#267) 2020-09-30 05:29:31 +03:00
Nickolay Ponomarev
9371652446 Fix "unused stmt" warning in tests, with default features 2020-07-29 02:08:17 +03:00
Steven
8020b2e5f0
Add Postgres-specific PREPARE, EXECUTE and DEALLOCATE (#243)
Adds top-statements PREPARE, EXECUTE and DEALLOCATE for Postgres-specific feature prepared statement.
2020-07-28 12:01:52 +03:00
Max Countryman
8cc7702a8c
update branch references to main (#215)
* update branch references to `main`

* ensure we point to ballista-compute

* update a couple of links to point to ballista-compute
2020-07-02 21:31:54 +02: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
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
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
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
Robert Grimm
b1cbc55128
Turn type Ident into struct Ident
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.
2019-10-20 00:16:41 -04:00
Nikhil Benesch
b8fe800da5
Fix merge skew with number literals 2019-09-02 09:37:38 -04:00
Nikhil Benesch
e9c5567b04
Merge pull request #135 from andygrove/show-columns
Support MySQL `SHOW COLUMNS` statement
2019-09-02 07:40:57 -04:00
Nikhil Benesch
a0aca824e8
Optionally parse numbers into BigDecimals
With `--features bigdecimal`, parse numbers into BigDecimals instead of
leaving them as strings.
2019-09-01 13:21:49 -04:00
Nikhil Benesch
b5621c0fe8
Don't lose precision when parsing decimal fractions
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.
2019-09-01 13:21:30 -04:00
Nikhil Benesch
e1ded184f8
Support SHOW <var> and SET <var> 2019-09-01 13:20:37 -04:00
Nikhil Benesch
ac555d7e86
Remove "SQL" prefix from types
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".
2019-06-25 13:11:11 -04:00
Nikhil Benesch
cf655ad1a6
Remove "sql" prefix from module names
Since this crate only deals with SQL parsing, the modules are understood
to refer to SQL and don't need to restate that explicitly.
2019-06-24 12:56:26 -04:00
Nikhil Benesch
646d1e13ca
Rename ASTNode to Expr
The ASTNode enum was confusingly named. In the past, the name made
sense, as the enum contained nearly all of the nodes in the AST, but
over time, pieces have been split into different structs, like
SQLStatement and SQLQuery. The ASTNode enum now contains only contains
expression nodes, so Expr is a better name.

Also rename the UnnamedExpression and ExpressionWithAlias variants
of SQLSelectItem to UnnamedExpr and ExprWithAlias, respectively, to
match the new shorthand for the word "expression".
2019-06-19 00:00:59 -04:00
Andy Grove
b379480b7a
Merge pull request #79 from benesch/license
Standardize license headers
2019-06-10 19:39:12 -06:00