Skip to content

Commit cd8998f

Browse files
Merge branch 'main' into postgres-regression-1
2 parents 7779f7c + 31e1942 commit cd8998f

25 files changed

+403
-55
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ $ cargo run --features json_example --example cli FILENAME.sql [--dialectname]
159159

160160
## Users
161161

162-
This parser is currently being used by the [DataFusion] query engine, [LocustDB],
163-
[Ballista], [GlueSQL], [Opteryx], [Polars], [PRQL], [Qrlew], [JumpWire], [ParadeDB], [CipherStash Proxy],
164-
and [GreptimeDB].
162+
This parser is currently being used by the [DataFusion] query engine,
163+
[LocustDB], [Ballista], [GlueSQL], [Opteryx], [Polars], [PRQL], [Qrlew],
164+
[JumpWire], [ParadeDB], [CipherStash Proxy], [Readyset] and [GreptimeDB].
165165

166166
If your project is using sqlparser-rs feel free to make a PR to add it
167167
to this list.
@@ -282,3 +282,4 @@ licensed as above, without any additional terms or conditions.
282282
[`GenericDialect`]: https://docs.rs/sqlparser/latest/sqlparser/dialect/struct.GenericDialect.html
283283
[CipherStash Proxy]: https://github.com/cipherstash/proxy
284284
[GreptimeDB]: https://github.com/GreptimeTeam/greptimedb
285+
[Readyset]: https://github.com/readysettech/readyset

src/ast/ddl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ impl fmt::Display for ColumnOption {
20402040
Ok(())
20412041
}
20422042
Unique(constraint) => {
2043-
write!(f, "UNIQUE")?;
2043+
write!(f, "UNIQUE{:>}", constraint.index_type_display)?;
20442044
if let Some(characteristics) = &constraint.characteristics {
20452045
write!(f, " {characteristics}")?;
20462046
}

src/ast/dml.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ pub struct Insert {
7979
pub on: Option<OnInsert>,
8080
/// RETURNING
8181
pub returning: Option<Vec<SelectItem>>,
82+
/// OUTPUT (MSSQL)
83+
/// See <https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql>
84+
pub output: Option<OutputClause>,
8285
/// Only for mysql
8386
pub replace_into: bool,
8487
/// Only for mysql
@@ -203,6 +206,11 @@ impl Display for Insert {
203206
SpaceOrNewline.fmt(f)?;
204207
}
205208

209+
if let Some(output) = &self.output {
210+
write!(f, "{output}")?;
211+
SpaceOrNewline.fmt(f)?;
212+
}
213+
206214
if let Some(settings) = &self.settings {
207215
write!(f, "SETTINGS {}", display_comma_separated(settings))?;
208216
SpaceOrNewline.fmt(f)?;
@@ -289,6 +297,9 @@ pub struct Delete {
289297
pub selection: Option<Expr>,
290298
/// RETURNING
291299
pub returning: Option<Vec<SelectItem>>,
300+
/// OUTPUT (MSSQL)
301+
/// See <https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql>
302+
pub output: Option<OutputClause>,
292303
/// ORDER BY (MySQL)
293304
pub order_by: Vec<OrderByExpr>,
294305
/// LIMIT (MySQL)
@@ -314,6 +325,10 @@ impl Display for Delete {
314325
indented_list(f, from)?;
315326
}
316327
}
328+
if let Some(output) = &self.output {
329+
SpaceOrNewline.fmt(f)?;
330+
write!(f, "{output}")?;
331+
}
317332
if let Some(using) = &self.using {
318333
SpaceOrNewline.fmt(f)?;
319334
f.write_str("USING")?;
@@ -367,6 +382,9 @@ pub struct Update {
367382
pub selection: Option<Expr>,
368383
/// RETURNING
369384
pub returning: Option<Vec<SelectItem>>,
385+
/// OUTPUT (MSSQL)
386+
/// See <https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql>
387+
pub output: Option<OutputClause>,
370388
/// SQLite-specific conflict resolution clause
371389
pub or: Option<SqliteOnConflict>,
372390
/// LIMIT
@@ -396,6 +414,10 @@ impl Display for Update {
396414
f.write_str("SET")?;
397415
indented_list(f, &self.assignments)?;
398416
}
417+
if let Some(output) = &self.output {
418+
SpaceOrNewline.fmt(f)?;
419+
write!(f, "{output}")?;
420+
}
399421
if let Some(UpdateTableFromKind::AfterSet(from)) = &self.from {
400422
SpaceOrNewline.fmt(f)?;
401423
f.write_str("FROM")?;
@@ -717,11 +739,11 @@ impl Display for MergeUpdateExpr {
717739
}
718740
}
719741

720-
/// A `OUTPUT` Clause in the end of a `MERGE` Statement
742+
/// An `OUTPUT` clause on `MERGE`, `INSERT`, `UPDATE`, or `DELETE` (MSSQL).
721743
///
722744
/// Example:
723745
/// OUTPUT $action, deleted.* INTO dbo.temp_products;
724-
/// [mssql](https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql)
746+
/// <https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql>
725747
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
726748
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
727749
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]

src/ast/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ pub enum Expr {
11311131
/// ```sql
11321132
/// TRIM([BOTH | LEADING | TRAILING] [<expr> FROM] <expr>)
11331133
/// TRIM(<expr>)
1134-
/// TRIM(<expr>, [, characters]) -- only Snowflake or Bigquery
1134+
/// TRIM(<expr>, [, characters]) -- PostgreSQL, DuckDB, Snowflake, BigQuery, Generic
11351135
/// ```
11361136
Trim {
11371137
/// The expression to trim from.

src/ast/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,13 +1018,13 @@ pub enum ExcludeSelectItem {
10181018
/// ```plaintext
10191019
/// <col_name>
10201020
/// ```
1021-
Single(Ident),
1021+
Single(ObjectName),
10221022
/// Multiple column names inside parenthesis.
10231023
/// # Syntax
10241024
/// ```plaintext
10251025
/// (<col_name>, <col_name>, ...)
10261026
/// ```
1027-
Multiple(Vec<Ident>),
1027+
Multiple(Vec<ObjectName>),
10281028
}
10291029

10301030
impl fmt::Display for ExcludeSelectItem {

src/ast/spans.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ impl Spanned for Delete {
906906
using,
907907
selection,
908908
returning,
909+
output,
909910
order_by,
910911
limit,
911912
} = self;
@@ -923,6 +924,7 @@ impl Spanned for Delete {
923924
)
924925
.chain(selection.iter().map(|i| i.span()))
925926
.chain(returning.iter().flat_map(|i| i.iter().map(|k| k.span())))
927+
.chain(output.iter().map(|i| i.span()))
926928
.chain(order_by.iter().map(|i| i.span()))
927929
.chain(limit.iter().map(|i| i.span())),
928930
),
@@ -940,6 +942,7 @@ impl Spanned for Update {
940942
from,
941943
selection,
942944
returning,
945+
output,
943946
or: _,
944947
limit,
945948
} = self;
@@ -951,6 +954,7 @@ impl Spanned for Update {
951954
.chain(from.iter().map(|i| i.span()))
952955
.chain(selection.iter().map(|i| i.span()))
953956
.chain(returning.iter().flat_map(|i| i.iter().map(|k| k.span())))
957+
.chain(output.iter().map(|i| i.span()))
954958
.chain(limit.iter().map(|i| i.span())),
955959
)
956960
}
@@ -1312,6 +1316,7 @@ impl Spanned for Insert {
13121316
has_table_keyword: _, // bool
13131317
on,
13141318
returning,
1319+
output,
13151320
replace_into: _, // bool
13161321
priority: _, // todo, mysql specific
13171322
insert_alias: _, // todo, mysql specific
@@ -1334,7 +1339,8 @@ impl Spanned for Insert {
13341339
.chain(partitioned.iter().flat_map(|i| i.iter().map(|k| k.span())))
13351340
.chain(after_columns.iter().map(|i| i.span))
13361341
.chain(on.as_ref().map(|i| i.span()))
1337-
.chain(returning.iter().flat_map(|i| i.iter().map(|k| k.span()))),
1342+
.chain(returning.iter().flat_map(|i| i.iter().map(|k| k.span())))
1343+
.chain(output.iter().map(|i| i.span())),
13381344
)
13391345
}
13401346
}
@@ -1849,8 +1855,8 @@ impl Spanned for IlikeSelectItem {
18491855
impl Spanned for ExcludeSelectItem {
18501856
fn span(&self) -> Span {
18511857
match self {
1852-
ExcludeSelectItem::Single(ident) => ident.span,
1853-
ExcludeSelectItem::Multiple(vec) => union_spans(vec.iter().map(|i| i.span)),
1858+
ExcludeSelectItem::Single(name) => name.span(),
1859+
ExcludeSelectItem::Multiple(vec) => union_spans(vec.iter().map(|i| i.span())),
18541860
}
18551861
}
18561862
}

src/dialect/bigquery.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,8 @@ impl Dialect for BigQueryDialect {
162162
fn supports_select_wildcard_replace(&self) -> bool {
163163
true
164164
}
165+
166+
fn supports_comma_separated_trim(&self) -> bool {
167+
true
168+
}
165169
}

src/dialect/clickhouse.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,8 @@ impl Dialect for ClickHouseDialect {
141141
fn supports_select_wildcard_replace(&self) -> bool {
142142
true
143143
}
144+
145+
fn supports_comma_separated_trim(&self) -> bool {
146+
true
147+
}
144148
}

src/dialect/duckdb.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,8 @@ impl Dialect for DuckDbDialect {
129129
fn supports_select_wildcard_replace(&self) -> bool {
130130
true
131131
}
132+
133+
fn supports_comma_separated_trim(&self) -> bool {
134+
true
135+
}
132136
}

src/dialect/generic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,12 @@ impl Dialect for GenericDialect {
280280
fn supports_constraint_keyword_without_name(&self) -> bool {
281281
true
282282
}
283+
284+
fn supports_key_column_option(&self) -> bool {
285+
true
286+
}
287+
288+
fn supports_comma_separated_trim(&self) -> bool {
289+
true
290+
}
283291
}

0 commit comments

Comments
 (0)