1#[cfg(not(feature = "std"))]
20use alloc::{
21 boxed::Box,
22 format,
23 string::{String, ToString},
24 vec,
25 vec::Vec,
26};
27use helpers::{
28 attached_token::AttachedToken,
29 stmt_data_loading::{FileStagingCommand, StageLoadSelectItemKind},
30};
31
32use core::cmp::Ordering;
33use core::ops::Deref;
34use core::{
35 fmt::{self, Display},
36 hash,
37};
38
39#[cfg(feature = "serde")]
40use serde::{Deserialize, Serialize};
41
42#[cfg(feature = "visitor")]
43use sqlparser_derive::{Visit, VisitMut};
44
45use crate::{
46 display_utils::SpaceOrNewline,
47 tokenizer::{Span, Token},
48};
49use crate::{
50 display_utils::{Indent, NewLine},
51 keywords::Keyword,
52};
53
54pub use self::data_type::{
55 ArrayElemTypeDef, BinaryLength, CharLengthUnits, CharacterLength, DataType, EnumMember,
56 ExactNumberInfo, IntervalFields, StructBracketKind, TimezoneInfo,
57};
58pub use self::dcl::{
59 AlterDefaultPrivileges, AlterDefaultPrivilegesAction, AlterDefaultPrivilegesObjectType,
60 AlterRoleOperation, CreateRole, Grant, ResetConfig, Revoke, RoleOption, SecondaryRoles,
61 SetConfigValue, Use,
62};
63pub use self::ddl::{
64 AccessMethodType, AggregateModifyKind, Alignment, AlterCollation, AlterCollationOperation,
65 AlterColumnOperation, AlterConnectorOwner, AlterDomain, AlterDomainOperation, AlterExtension,
66 AlterExtensionOperation, AlterFunction, AlterFunctionAction, AlterFunctionKind,
67 AlterFunctionOperation, AlterIndexOperation, AlterOperator, AlterOperatorClass,
68 AlterOperatorClassOperation, AlterOperatorFamily, AlterOperatorFamilyOperation,
69 AlterOperatorOperation, AlterPolicy, AlterPolicyOperation, AlterSchema, AlterSchemaOperation,
70 AlterTable, AlterTableAlgorithm, AlterTableLock, AlterTableOperation, AlterTableType,
71 AlterTrigger, AlterTriggerOperation, AlterType, AlterTypeAddValue, AlterTypeAddValuePosition,
72 AlterTypeOperation, AlterTypeRename, AlterTypeRenameValue, CastContext, CastFunctionKind,
73 ClusteredBy, ColumnDef, ColumnOption, ColumnOptionDef, ColumnOptions, ColumnPolicy,
74 ColumnPolicyProperty, ConstraintCharacteristics, CreateAccessMethod, CreateAggregate,
75 CreateAggregateOption, CreateCast, CreateCollation, CreateCollationDefinition, CreateConnector,
76 CreateConversion, CreateDomain, CreateEventTrigger, CreateExtension, CreateForeignDataWrapper,
77 CreateForeignTable, CreateFunction, CreateIndex, CreateLanguage, CreateOperator,
78 CreateOperatorClass, CreateOperatorFamily, CreatePolicy, CreatePolicyCommand, CreatePolicyType,
79 CreatePublication, CreateRule, CreateStatistics, CreateSubscription, CreateTable,
80 CreateTablespace, CreateTextSearchConfiguration, CreateTextSearchDictionary,
81 CreateTextSearchParser, CreateTextSearchTemplate, CreateTransform, CreateTrigger,
82 CreateUserMapping, CreateView, Deduplicate, DeferrableInitial, DistStyle, DropBehavior,
83 DropExtension, DropFunction, DropOperator, DropOperatorClass, DropOperatorFamily,
84 DropOperatorSignature, DropPolicy, DropTrigger, EventTriggerEvent, FdwRoutineClause, ForValues,
85 FunctionReturnType, GeneratedAs, GeneratedExpressionMode, IdentityParameters, IdentityProperty,
86 IdentityPropertyFormatKind, IdentityPropertyKind, IdentityPropertyOrder, IndexColumn,
87 IndexOption, IndexType, KeyOrIndexDisplay, Msck, NullsDistinctOption, OperatorArgTypes,
88 OperatorClassItem, OperatorFamilyDropItem, OperatorFamilyItem, OperatorOption, OperatorPurpose,
89 Owner, Partition, PartitionBoundValue, ProcedureParam, PublicationTarget, ReferentialAction,
90 RenameTableNameKind, ReplicaIdentity, RuleAction, RuleEvent, SecurityLabel,
91 SecurityLabelObjectKind, StatisticsKind, TagsColumnOption, TransformElement, TriggerObjectKind,
92 Truncate, UserDefinedTypeCompositeAttributeDef, UserDefinedTypeInternalLength,
93 UserDefinedTypeRangeOption, UserDefinedTypeRepresentation, UserDefinedTypeSqlDefinitionOption,
94 UserDefinedTypeStorage, UserMappingUser, ViewColumnDef,
95};
96pub use self::dml::{
97 Delete, Insert, Merge, MergeAction, MergeClause, MergeClauseKind, MergeInsertExpr,
98 MergeInsertKind, MergeUpdateExpr, MultiTableInsertIntoClause, MultiTableInsertType,
99 MultiTableInsertValue, MultiTableInsertValues, MultiTableInsertWhenClause, OutputClause,
100 Update,
101};
102pub use self::operator::{BinaryOperator, UnaryOperator};
103pub use self::query::{
104 AfterMatchSkip, ConnectByKind, Cte, CteAsMaterialized, Distinct, EmptyMatchesMode,
105 ExceptSelectItem, ExcludeSelectItem, ExprWithAlias, ExprWithAliasAndOrderBy, Fetch, ForClause,
106 ForJson, ForXml, FormatClause, GroupByExpr, GroupByWithModifier, IdentWithAlias,
107 IlikeSelectItem, InputFormatClause, Interpolate, InterpolateExpr, Join, JoinConstraint,
108 JoinOperator, JsonTableColumn, JsonTableColumnErrorHandling, JsonTableNamedColumn,
109 JsonTableNestedColumn, LateralView, LimitClause, LockClause, LockType, MatchRecognizePattern,
110 MatchRecognizeSymbol, Measure, NamedWindowDefinition, NamedWindowExpr, NonBlock, Offset,
111 OffsetRows, OpenJsonTableColumn, OrderBy, OrderByExpr, OrderByKind, OrderByOptions,
112 PipeOperator, PivotValueSource, ProjectionSelect, Query, RenameSelectItem,
113 RepetitionQuantifier, ReplaceSelectElement, ReplaceSelectItem, RowsPerMatch, Select,
114 SelectFlavor, SelectInto, SelectItem, SelectItemQualifiedWildcardKind, SelectModifiers,
115 SetExpr, SetOperator, SetQuantifier, Setting, SymbolDefinition, Table, TableAlias,
116 TableAliasColumnDef, TableFactor, TableFunctionArgs, TableIndexHintForClause,
117 TableIndexHintType, TableIndexHints, TableIndexType, TableSample, TableSampleBucket,
118 TableSampleKind, TableSampleMethod, TableSampleModifier, TableSampleQuantity, TableSampleSeed,
119 TableSampleSeedModifier, TableSampleUnit, TableVersion, TableWithJoins, Top, TopQuantity,
120 UpdateTableFromKind, ValueTableMode, Values, WildcardAdditionalOptions, With, WithFill,
121 XmlNamespaceDefinition, XmlPassingArgument, XmlPassingClause, XmlTableColumn,
122 XmlTableColumnOption,
123};
124
125pub use self::trigger::{
126 TriggerEvent, TriggerExecBody, TriggerExecBodyType, TriggerObject, TriggerPeriod,
127 TriggerReferencing, TriggerReferencingType,
128};
129
130pub use self::value::{
131 escape_double_quote_string, escape_quoted_string, DateTimeField, DollarQuotedString,
132 NormalizationForm, QuoteDelimitedString, TrimWhereField, Value, ValueWithSpan,
133};
134
135use crate::ast::helpers::key_value_options::KeyValueOptions;
136use crate::ast::helpers::stmt_data_loading::StageParamsObject;
137
138#[cfg(feature = "visitor")]
139pub use visitor::*;
140
141pub use self::data_type::GeometricTypeKind;
142
143mod data_type;
144mod dcl;
145mod ddl;
146mod dml;
147pub mod helpers;
149pub mod table_constraints;
150pub use table_constraints::{
151 CheckConstraint, ConstraintUsingIndex, ExclusionConstraint, ExclusionElement,
152 ForeignKeyConstraint, FullTextOrSpatialConstraint, IndexConstraint, PrimaryKeyConstraint,
153 TableConstraint, UniqueConstraint,
154};
155mod operator;
156mod query;
157mod spans;
158pub use spans::Spanned;
159
160pub mod comments;
161mod trigger;
162mod value;
163
164#[cfg(feature = "visitor")]
165mod visitor;
166
167pub struct DisplaySeparated<'a, T>
169where
170 T: fmt::Display,
171{
172 slice: &'a [T],
173 sep: &'static str,
174}
175
176impl<T> fmt::Display for DisplaySeparated<'_, T>
177where
178 T: fmt::Display,
179{
180 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
181 let mut delim = "";
182 for t in self.slice {
183 f.write_str(delim)?;
184 delim = self.sep;
185 t.fmt(f)?;
186 }
187 Ok(())
188 }
189}
190
191pub(crate) fn display_separated<'a, T>(slice: &'a [T], sep: &'static str) -> DisplaySeparated<'a, T>
192where
193 T: fmt::Display,
194{
195 DisplaySeparated { slice, sep }
196}
197
198pub(crate) fn display_comma_separated<T>(slice: &[T]) -> DisplaySeparated<'_, T>
199where
200 T: fmt::Display,
201{
202 DisplaySeparated { slice, sep: ", " }
203}
204
205fn format_statement_list(f: &mut fmt::Formatter, statements: &[Statement]) -> fmt::Result {
208 write!(f, "{}", display_separated(statements, "; "))?;
209 write!(f, ";")
212}
213
214#[derive(Debug, Clone)]
216#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
217#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
218pub struct Ident {
219 pub value: String,
221 pub quote_style: Option<char>,
224 pub span: Span,
226}
227
228impl PartialEq for Ident {
229 fn eq(&self, other: &Self) -> bool {
230 let Ident {
231 value,
232 quote_style,
233 span: _,
235 } = self;
236
237 value == &other.value && quote_style == &other.quote_style
238 }
239}
240
241impl core::hash::Hash for Ident {
242 fn hash<H: hash::Hasher>(&self, state: &mut H) {
243 let Ident {
244 value,
245 quote_style,
246 span: _,
248 } = self;
249
250 value.hash(state);
251 quote_style.hash(state);
252 }
253}
254
255impl Eq for Ident {}
256
257impl PartialOrd for Ident {
258 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
259 Some(self.cmp(other))
260 }
261}
262
263impl Ord for Ident {
264 fn cmp(&self, other: &Self) -> Ordering {
265 let Ident {
266 value,
267 quote_style,
268 span: _,
270 } = self;
271
272 let Ident {
273 value: other_value,
274 quote_style: other_quote_style,
275 span: _,
277 } = other;
278
279 value
281 .cmp(other_value)
282 .then_with(|| quote_style.cmp(other_quote_style))
283 }
284}
285
286impl Ident {
287 pub fn new<S>(value: S) -> Self
289 where
290 S: Into<String>,
291 {
292 Ident {
293 value: value.into(),
294 quote_style: None,
295 span: Span::empty(),
296 }
297 }
298
299 pub fn with_quote<S>(quote: char, value: S) -> Self
302 where
303 S: Into<String>,
304 {
305 assert!(quote == '\'' || quote == '"' || quote == '`' || quote == '[');
306 Ident {
307 value: value.into(),
308 quote_style: Some(quote),
309 span: Span::empty(),
310 }
311 }
312
313 pub fn with_span<S>(span: Span, value: S) -> Self
315 where
316 S: Into<String>,
317 {
318 Ident {
319 value: value.into(),
320 quote_style: None,
321 span,
322 }
323 }
324
325 pub fn with_quote_and_span<S>(quote: char, span: Span, value: S) -> Self
327 where
328 S: Into<String>,
329 {
330 assert!(quote == '\'' || quote == '"' || quote == '`' || quote == '[');
331 Ident {
332 value: value.into(),
333 quote_style: Some(quote),
334 span,
335 }
336 }
337}
338
339impl From<&str> for Ident {
340 fn from(value: &str) -> Self {
341 Ident {
342 value: value.to_string(),
343 quote_style: None,
344 span: Span::empty(),
345 }
346 }
347}
348
349impl fmt::Display for Ident {
350 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
351 match self.quote_style {
352 Some(q) if q == '"' || q == '\'' || q == '`' => {
353 let escaped = value::escape_quoted_string(&self.value, q);
354 write!(f, "{q}{escaped}{q}")
355 }
356 Some('[') => write!(f, "[{}]", self.value),
357 None => f.write_str(&self.value),
358 _ => panic!("unexpected quote style"),
359 }
360 }
361}
362
363#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
365#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
366#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
367pub struct ObjectName(pub Vec<ObjectNamePart>);
368
369impl From<Vec<Ident>> for ObjectName {
370 fn from(idents: Vec<Ident>) -> Self {
371 ObjectName(idents.into_iter().map(ObjectNamePart::Identifier).collect())
372 }
373}
374
375impl From<Ident> for ObjectName {
376 fn from(ident: Ident) -> Self {
377 ObjectName(vec![ObjectNamePart::Identifier(ident)])
378 }
379}
380
381impl fmt::Display for ObjectName {
382 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
383 write!(f, "{}", display_separated(&self.0, "."))
384 }
385}
386
387#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
389#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
390#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
391pub enum ObjectNamePart {
392 Identifier(Ident),
394 Function(ObjectNamePartFunction),
396}
397
398impl ObjectNamePart {
399 pub fn as_ident(&self) -> Option<&Ident> {
401 match self {
402 ObjectNamePart::Identifier(ident) => Some(ident),
403 ObjectNamePart::Function(_) => None,
404 }
405 }
406}
407
408impl fmt::Display for ObjectNamePart {
409 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
410 match self {
411 ObjectNamePart::Identifier(ident) => write!(f, "{ident}"),
412 ObjectNamePart::Function(func) => write!(f, "{func}"),
413 }
414 }
415}
416
417#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
422#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
423#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
424pub struct ObjectNamePartFunction {
425 pub name: Ident,
427 pub args: Vec<FunctionArg>,
429}
430
431impl fmt::Display for ObjectNamePartFunction {
432 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
433 write!(f, "{}(", self.name)?;
434 write!(f, "{})", display_comma_separated(&self.args))
435 }
436}
437
438#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
441#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
442#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
443pub struct Array {
444 pub elem: Vec<Expr>,
446
447 pub named: bool,
449}
450
451impl fmt::Display for Array {
452 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
453 write!(
454 f,
455 "{}[{}]",
456 if self.named { "ARRAY" } else { "" },
457 display_comma_separated(&self.elem)
458 )
459 }
460}
461
462#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
471#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
472#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
473pub struct Interval {
474 pub value: Box<Expr>,
476 pub leading_field: Option<DateTimeField>,
478 pub leading_precision: Option<u64>,
480 pub last_field: Option<DateTimeField>,
482 pub fractional_seconds_precision: Option<u64>,
486}
487
488impl fmt::Display for Interval {
489 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
490 let value = self.value.as_ref();
491 match (
492 &self.leading_field,
493 self.leading_precision,
494 self.fractional_seconds_precision,
495 ) {
496 (
497 Some(DateTimeField::Second),
498 Some(leading_precision),
499 Some(fractional_seconds_precision),
500 ) => {
501 assert!(self.last_field.is_none());
504 write!(
505 f,
506 "INTERVAL {value} SECOND ({leading_precision}, {fractional_seconds_precision})"
507 )
508 }
509 _ => {
510 write!(f, "INTERVAL {value}")?;
511 if let Some(leading_field) = &self.leading_field {
512 write!(f, " {leading_field}")?;
513 }
514 if let Some(leading_precision) = self.leading_precision {
515 write!(f, " ({leading_precision})")?;
516 }
517 if let Some(last_field) = &self.last_field {
518 write!(f, " TO {last_field}")?;
519 }
520 if let Some(fractional_seconds_precision) = self.fractional_seconds_precision {
521 write!(f, " ({fractional_seconds_precision})")?;
522 }
523 Ok(())
524 }
525 }
526 }
527}
528
529#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
533#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
534#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
535pub struct StructField {
536 pub field_name: Option<Ident>,
538 pub field_type: DataType,
540 pub options: Option<Vec<SqlOption>>,
543}
544
545impl fmt::Display for StructField {
546 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
547 if let Some(name) = &self.field_name {
548 write!(f, "{name} {}", self.field_type)?;
549 } else {
550 write!(f, "{}", self.field_type)?;
551 }
552 if let Some(options) = &self.options {
553 write!(f, " OPTIONS({})", display_separated(options, ", "))
554 } else {
555 Ok(())
556 }
557 }
558}
559
560#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
564#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
565#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
566pub struct UnionField {
567 pub field_name: Ident,
569 pub field_type: DataType,
571}
572
573impl fmt::Display for UnionField {
574 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
575 write!(f, "{} {}", self.field_name, self.field_type)
576 }
577}
578
579#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
583#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
584#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
585pub struct DictionaryField {
586 pub key: Ident,
588 pub value: Box<Expr>,
590}
591
592impl fmt::Display for DictionaryField {
593 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
594 write!(f, "{}: {}", self.key, self.value)
595 }
596}
597
598#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
600#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
601#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
602pub struct Map {
603 pub entries: Vec<MapEntry>,
605}
606
607impl Display for Map {
608 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
609 write!(f, "MAP {{{}}}", display_comma_separated(&self.entries))
610 }
611}
612
613#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
617#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
618#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
619pub struct MapEntry {
620 pub key: Box<Expr>,
622 pub value: Box<Expr>,
624}
625
626impl fmt::Display for MapEntry {
627 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
628 write!(f, "{}: {}", self.key, self.value)
629 }
630}
631
632#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
635#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
636#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
637pub enum CastFormat {
638 Value(ValueWithSpan),
640 ValueAtTimeZone(ValueWithSpan, ValueWithSpan),
642}
643
644#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
646#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
647#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
648pub enum JsonPathElem {
649 Dot {
653 key: String,
655 quoted: bool,
657 },
658 Bracket {
663 key: Expr,
665 },
666 ColonBracket {
671 key: Expr,
673 },
674}
675
676#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
681#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
682#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
683pub struct JsonPath {
684 pub path: Vec<JsonPathElem>,
686}
687
688impl fmt::Display for JsonPath {
689 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
690 for (i, elem) in self.path.iter().enumerate() {
691 match elem {
692 JsonPathElem::Dot { key, quoted } => {
693 if i == 0 {
694 write!(f, ":")?;
695 } else {
696 write!(f, ".")?;
697 }
698
699 if *quoted {
700 write!(f, "\"{}\"", escape_double_quote_string(key))?;
701 } else {
702 write!(f, "{key}")?;
703 }
704 }
705 JsonPathElem::Bracket { key } => {
706 write!(f, "[{key}]")?;
707 }
708 JsonPathElem::ColonBracket { key } => {
709 write!(f, ":[{key}]")?;
710 }
711 }
712 }
713 Ok(())
714 }
715}
716
717#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
719#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
720#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
721pub enum CastKind {
722 Cast,
724 TryCast,
729 SafeCast,
733 DoubleColon,
735}
736
737#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
741#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
742#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
743pub enum ConstraintReferenceMatchKind {
744 Full,
746 Partial,
748 Simple,
750}
751
752impl fmt::Display for ConstraintReferenceMatchKind {
753 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
754 match self {
755 Self::Full => write!(f, "MATCH FULL"),
756 Self::Partial => write!(f, "MATCH PARTIAL"),
757 Self::Simple => write!(f, "MATCH SIMPLE"),
758 }
759 }
760}
761
762#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
769#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
770#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
771pub enum ExtractSyntax {
772 From,
774 Comma,
776}
777
778#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
787#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
788#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
789pub enum CeilFloorKind {
790 DateTimeField(DateTimeField),
792 Scale(ValueWithSpan),
794}
795
796#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
799#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
800#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
801pub struct CaseWhen {
802 pub condition: Expr,
804 pub result: Expr,
806}
807
808impl fmt::Display for CaseWhen {
809 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
810 f.write_str("WHEN ")?;
811 self.condition.fmt(f)?;
812 f.write_str(" THEN")?;
813 SpaceOrNewline.fmt(f)?;
814 Indent(&self.result).fmt(f)?;
815 Ok(())
816 }
817}
818
819#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
837#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
838#[cfg_attr(
839 feature = "visitor",
840 derive(Visit, VisitMut),
841 visit(with = "visit_expr")
842)]
843pub enum Expr {
844 Identifier(Ident),
846 CompoundIdentifier(Vec<Ident>),
848 CompoundFieldAccess {
867 root: Box<Expr>,
869 access_chain: Vec<AccessExpr>,
871 },
872 JsonAccess {
878 value: Box<Expr>,
880 path: JsonPath,
882 },
883 IsFalse(Box<Expr>),
885 IsNotFalse(Box<Expr>),
887 IsTrue(Box<Expr>),
889 IsNotTrue(Box<Expr>),
891 IsNull(Box<Expr>),
893 IsNotNull(Box<Expr>),
895 IsUnknown(Box<Expr>),
897 IsNotUnknown(Box<Expr>),
899 IsDistinctFrom(Box<Expr>, Box<Expr>),
901 IsNotDistinctFrom(Box<Expr>, Box<Expr>),
903 IsNormalized {
905 expr: Box<Expr>,
907 form: Option<NormalizationForm>,
909 negated: bool,
911 },
912 InList {
914 expr: Box<Expr>,
916 list: Vec<Expr>,
918 negated: bool,
920 },
921 InSubquery {
923 expr: Box<Expr>,
925 subquery: Box<Query>,
927 negated: bool,
929 },
930 InUnnest {
932 expr: Box<Expr>,
934 array_expr: Box<Expr>,
936 negated: bool,
938 },
939 Between {
941 expr: Box<Expr>,
943 negated: bool,
945 low: Box<Expr>,
947 high: Box<Expr>,
949 },
950 BinaryOp {
952 left: Box<Expr>,
954 op: BinaryOperator,
956 right: Box<Expr>,
958 },
959 Like {
961 negated: bool,
963 any: bool,
966 expr: Box<Expr>,
968 pattern: Box<Expr>,
970 escape_char: Option<ValueWithSpan>,
972 },
973 ILike {
975 negated: bool,
977 any: bool,
980 expr: Box<Expr>,
982 pattern: Box<Expr>,
984 escape_char: Option<ValueWithSpan>,
986 },
987 SimilarTo {
989 negated: bool,
991 expr: Box<Expr>,
993 pattern: Box<Expr>,
995 escape_char: Option<ValueWithSpan>,
997 },
998 RLike {
1000 negated: bool,
1002 expr: Box<Expr>,
1004 pattern: Box<Expr>,
1006 regexp: bool,
1008 },
1009 AnyOp {
1012 left: Box<Expr>,
1014 compare_op: BinaryOperator,
1016 right: Box<Expr>,
1018 is_some: bool,
1020 },
1021 AllOp {
1024 left: Box<Expr>,
1026 compare_op: BinaryOperator,
1028 right: Box<Expr>,
1030 },
1031
1032 UnaryOp {
1034 op: UnaryOperator,
1036 expr: Box<Expr>,
1038 },
1039 Convert {
1041 is_try: bool,
1044 expr: Box<Expr>,
1046 data_type: Option<DataType>,
1048 charset: Option<ObjectName>,
1050 target_before_value: bool,
1052 styles: Vec<Expr>,
1056 },
1057 Cast {
1059 kind: CastKind,
1061 expr: Box<Expr>,
1063 data_type: DataType,
1065 array: bool,
1071 format: Option<CastFormat>,
1075 },
1076 AtTimeZone {
1078 timestamp: Box<Expr>,
1080 time_zone: Box<Expr>,
1082 },
1083 Extract {
1091 field: DateTimeField,
1093 syntax: ExtractSyntax,
1095 expr: Box<Expr>,
1097 },
1098 Ceil {
1105 expr: Box<Expr>,
1107 field: CeilFloorKind,
1109 },
1110 Floor {
1117 expr: Box<Expr>,
1119 field: CeilFloorKind,
1121 },
1122 Position {
1126 expr: Box<Expr>,
1128 r#in: Box<Expr>,
1130 },
1131 Substring {
1139 expr: Box<Expr>,
1141 substring_from: Option<Box<Expr>>,
1143 substring_for: Option<Box<Expr>>,
1145
1146 special: bool,
1150
1151 shorthand: bool,
1154 },
1155 Trim {
1161 trim_where: Option<TrimWhereField>,
1163 trim_what: Option<Box<Expr>>,
1165 expr: Box<Expr>,
1167 trim_characters: Option<Vec<Expr>>,
1169 },
1170 Overlay {
1174 expr: Box<Expr>,
1176 overlay_what: Box<Expr>,
1178 overlay_from: Box<Expr>,
1180 overlay_for: Option<Box<Expr>>,
1182 },
1183 Collate {
1185 expr: Box<Expr>,
1187 collation: ObjectName,
1189 },
1190 Nested(Box<Expr>),
1192 Value(ValueWithSpan),
1194 Prefixed {
1198 prefix: Ident,
1200 value: Box<Expr>,
1203 },
1204 TypedString(TypedString),
1208 Function(Function),
1210 Case {
1216 case_token: AttachedToken,
1218 end_token: AttachedToken,
1220 operand: Option<Box<Expr>>,
1222 conditions: Vec<CaseWhen>,
1224 else_result: Option<Box<Expr>>,
1226 },
1227 Exists {
1230 subquery: Box<Query>,
1232 negated: bool,
1234 },
1235 Subquery(Box<Query>),
1238 GroupingSets(Vec<Vec<Expr>>),
1240 Cube(Vec<Vec<Expr>>),
1242 Rollup(Vec<Vec<Expr>>),
1244 Tuple(Vec<Expr>),
1246 Struct {
1255 values: Vec<Expr>,
1257 fields: Vec<StructField>,
1259 },
1260 Named {
1268 expr: Box<Expr>,
1270 name: Ident,
1272 },
1273 Dictionary(Vec<DictionaryField>),
1281 Map(Map),
1289 Array(Array),
1291 Interval(Interval),
1293 MatchAgainst {
1304 columns: Vec<ObjectName>,
1306 match_value: ValueWithSpan,
1308 opt_search_modifier: Option<SearchModifier>,
1310 },
1311 Wildcard(AttachedToken),
1313 QualifiedWildcard(ObjectName, AttachedToken),
1316 OuterJoin(Box<Expr>),
1331 Prior(Box<Expr>),
1333 Lambda(LambdaFunction),
1344 MemberOf(MemberOf),
1346}
1347
1348impl Expr {
1349 pub fn value(value: impl Into<ValueWithSpan>) -> Self {
1351 Expr::Value(value.into())
1352 }
1353}
1354
1355#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1357#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1358#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1359pub enum Subscript {
1360 Index {
1362 index: Expr,
1364 },
1365
1366 Slice {
1388 lower_bound: Option<Expr>,
1390 upper_bound: Option<Expr>,
1392 stride: Option<Expr>,
1394 },
1395}
1396
1397impl fmt::Display for Subscript {
1398 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1399 match self {
1400 Subscript::Index { index } => write!(f, "{index}"),
1401 Subscript::Slice {
1402 lower_bound,
1403 upper_bound,
1404 stride,
1405 } => {
1406 if let Some(lower) = lower_bound {
1407 write!(f, "{lower}")?;
1408 }
1409 write!(f, ":")?;
1410 if let Some(upper) = upper_bound {
1411 write!(f, "{upper}")?;
1412 }
1413 if let Some(stride) = stride {
1414 write!(f, ":")?;
1415 write!(f, "{stride}")?;
1416 }
1417 Ok(())
1418 }
1419 }
1420 }
1421}
1422
1423#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1426#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1427#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1428pub enum AccessExpr {
1429 Dot(Expr),
1431 Subscript(Subscript),
1433}
1434
1435impl fmt::Display for AccessExpr {
1436 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1437 match self {
1438 AccessExpr::Dot(expr) => write!(f, ".{expr}"),
1439 AccessExpr::Subscript(subscript) => write!(f, "[{subscript}]"),
1440 }
1441 }
1442}
1443
1444#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1446#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1447#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1448pub struct LambdaFunction {
1449 pub params: OneOrManyWithParens<LambdaFunctionParameter>,
1451 pub body: Box<Expr>,
1453 pub syntax: LambdaSyntax,
1455}
1456
1457impl fmt::Display for LambdaFunction {
1458 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1459 match self.syntax {
1460 LambdaSyntax::Arrow => write!(f, "{} -> {}", self.params, self.body),
1461 LambdaSyntax::LambdaKeyword => {
1462 write!(f, "lambda ")?;
1465 match &self.params {
1466 OneOrManyWithParens::One(p) => write!(f, "{p}")?,
1467 OneOrManyWithParens::Many(ps) => write!(f, "{}", display_comma_separated(ps))?,
1468 };
1469 write!(f, " : {}", self.body)
1470 }
1471 }
1472 }
1473}
1474
1475#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1477#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1478#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1479pub struct LambdaFunctionParameter {
1480 pub name: Ident,
1482 pub data_type: Option<DataType>,
1485}
1486
1487impl fmt::Display for LambdaFunctionParameter {
1488 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1489 match &self.data_type {
1490 Some(dt) => write!(f, "{} {}", self.name, dt),
1491 None => write!(f, "{}", self.name),
1492 }
1493 }
1494}
1495
1496#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy)]
1498#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1499#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1500pub enum LambdaSyntax {
1501 Arrow,
1508 LambdaKeyword,
1513}
1514
1515#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1538#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1539#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1540pub enum OneOrManyWithParens<T> {
1541 One(T),
1543 Many(Vec<T>),
1545}
1546
1547impl<T> Deref for OneOrManyWithParens<T> {
1548 type Target = [T];
1549
1550 fn deref(&self) -> &[T] {
1551 match self {
1552 OneOrManyWithParens::One(one) => core::slice::from_ref(one),
1553 OneOrManyWithParens::Many(many) => many,
1554 }
1555 }
1556}
1557
1558impl<T> AsRef<[T]> for OneOrManyWithParens<T> {
1559 fn as_ref(&self) -> &[T] {
1560 self
1561 }
1562}
1563
1564impl<'a, T> IntoIterator for &'a OneOrManyWithParens<T> {
1565 type Item = &'a T;
1566 type IntoIter = core::slice::Iter<'a, T>;
1567
1568 fn into_iter(self) -> Self::IntoIter {
1569 self.iter()
1570 }
1571}
1572
1573#[derive(Debug, Clone)]
1575pub struct OneOrManyWithParensIntoIter<T> {
1576 inner: OneOrManyWithParensIntoIterInner<T>,
1577}
1578
1579#[derive(Debug, Clone)]
1580enum OneOrManyWithParensIntoIterInner<T> {
1581 One(core::iter::Once<T>),
1582 Many(<Vec<T> as IntoIterator>::IntoIter),
1583}
1584
1585impl<T> core::iter::FusedIterator for OneOrManyWithParensIntoIter<T>
1586where
1587 core::iter::Once<T>: core::iter::FusedIterator,
1588 <Vec<T> as IntoIterator>::IntoIter: core::iter::FusedIterator,
1589{
1590}
1591
1592impl<T> core::iter::ExactSizeIterator for OneOrManyWithParensIntoIter<T>
1593where
1594 core::iter::Once<T>: core::iter::ExactSizeIterator,
1595 <Vec<T> as IntoIterator>::IntoIter: core::iter::ExactSizeIterator,
1596{
1597}
1598
1599impl<T> core::iter::Iterator for OneOrManyWithParensIntoIter<T> {
1600 type Item = T;
1601
1602 fn next(&mut self) -> Option<Self::Item> {
1603 match &mut self.inner {
1604 OneOrManyWithParensIntoIterInner::One(one) => one.next(),
1605 OneOrManyWithParensIntoIterInner::Many(many) => many.next(),
1606 }
1607 }
1608
1609 fn size_hint(&self) -> (usize, Option<usize>) {
1610 match &self.inner {
1611 OneOrManyWithParensIntoIterInner::One(one) => one.size_hint(),
1612 OneOrManyWithParensIntoIterInner::Many(many) => many.size_hint(),
1613 }
1614 }
1615
1616 fn count(self) -> usize
1617 where
1618 Self: Sized,
1619 {
1620 match self.inner {
1621 OneOrManyWithParensIntoIterInner::One(one) => one.count(),
1622 OneOrManyWithParensIntoIterInner::Many(many) => many.count(),
1623 }
1624 }
1625
1626 fn fold<B, F>(mut self, init: B, f: F) -> B
1627 where
1628 Self: Sized,
1629 F: FnMut(B, Self::Item) -> B,
1630 {
1631 match &mut self.inner {
1632 OneOrManyWithParensIntoIterInner::One(one) => one.fold(init, f),
1633 OneOrManyWithParensIntoIterInner::Many(many) => many.fold(init, f),
1634 }
1635 }
1636}
1637
1638impl<T> core::iter::DoubleEndedIterator for OneOrManyWithParensIntoIter<T> {
1639 fn next_back(&mut self) -> Option<Self::Item> {
1640 match &mut self.inner {
1641 OneOrManyWithParensIntoIterInner::One(one) => one.next_back(),
1642 OneOrManyWithParensIntoIterInner::Many(many) => many.next_back(),
1643 }
1644 }
1645}
1646
1647impl<T> IntoIterator for OneOrManyWithParens<T> {
1648 type Item = T;
1649
1650 type IntoIter = OneOrManyWithParensIntoIter<T>;
1651
1652 fn into_iter(self) -> Self::IntoIter {
1653 let inner = match self {
1654 OneOrManyWithParens::One(one) => {
1655 OneOrManyWithParensIntoIterInner::One(core::iter::once(one))
1656 }
1657 OneOrManyWithParens::Many(many) => {
1658 OneOrManyWithParensIntoIterInner::Many(many.into_iter())
1659 }
1660 };
1661
1662 OneOrManyWithParensIntoIter { inner }
1663 }
1664}
1665
1666impl<T> fmt::Display for OneOrManyWithParens<T>
1667where
1668 T: fmt::Display,
1669{
1670 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1671 match self {
1672 OneOrManyWithParens::One(value) => write!(f, "{value}"),
1673 OneOrManyWithParens::Many(values) => {
1674 write!(f, "({})", display_comma_separated(values))
1675 }
1676 }
1677 }
1678}
1679
1680impl fmt::Display for CastFormat {
1681 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1682 match self {
1683 CastFormat::Value(v) => write!(f, "{v}"),
1684 CastFormat::ValueAtTimeZone(v, tz) => write!(f, "{v} AT TIME ZONE {tz}"),
1685 }
1686 }
1687}
1688
1689impl fmt::Display for Expr {
1690 #[cfg_attr(feature = "recursive-protection", recursive::recursive)]
1691 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1692 match self {
1693 Expr::Identifier(s) => write!(f, "{s}"),
1694 Expr::Wildcard(_) => f.write_str("*"),
1695 Expr::QualifiedWildcard(prefix, _) => write!(f, "{prefix}.*"),
1696 Expr::CompoundIdentifier(s) => write!(f, "{}", display_separated(s, ".")),
1697 Expr::CompoundFieldAccess { root, access_chain } => {
1698 write!(f, "{root}")?;
1699 for field in access_chain {
1700 write!(f, "{field}")?;
1701 }
1702 Ok(())
1703 }
1704 Expr::IsTrue(ast) => write!(f, "{ast} IS TRUE"),
1705 Expr::IsNotTrue(ast) => write!(f, "{ast} IS NOT TRUE"),
1706 Expr::IsFalse(ast) => write!(f, "{ast} IS FALSE"),
1707 Expr::IsNotFalse(ast) => write!(f, "{ast} IS NOT FALSE"),
1708 Expr::IsNull(ast) => write!(f, "{ast} IS NULL"),
1709 Expr::IsNotNull(ast) => write!(f, "{ast} IS NOT NULL"),
1710 Expr::IsUnknown(ast) => write!(f, "{ast} IS UNKNOWN"),
1711 Expr::IsNotUnknown(ast) => write!(f, "{ast} IS NOT UNKNOWN"),
1712 Expr::InList {
1713 expr,
1714 list,
1715 negated,
1716 } => write!(
1717 f,
1718 "{} {}IN ({})",
1719 expr,
1720 if *negated { "NOT " } else { "" },
1721 display_comma_separated(list)
1722 ),
1723 Expr::InSubquery {
1724 expr,
1725 subquery,
1726 negated,
1727 } => write!(
1728 f,
1729 "{} {}IN ({})",
1730 expr,
1731 if *negated { "NOT " } else { "" },
1732 subquery
1733 ),
1734 Expr::InUnnest {
1735 expr,
1736 array_expr,
1737 negated,
1738 } => write!(
1739 f,
1740 "{} {}IN UNNEST({})",
1741 expr,
1742 if *negated { "NOT " } else { "" },
1743 array_expr
1744 ),
1745 Expr::Between {
1746 expr,
1747 negated,
1748 low,
1749 high,
1750 } => write!(
1751 f,
1752 "{} {}BETWEEN {} AND {}",
1753 expr,
1754 if *negated { "NOT " } else { "" },
1755 low,
1756 high
1757 ),
1758 Expr::BinaryOp { left, op, right } => write!(f, "{left} {op} {right}"),
1759 Expr::Like {
1760 negated,
1761 expr,
1762 pattern,
1763 escape_char,
1764 any,
1765 } => match escape_char {
1766 Some(ch) => write!(
1767 f,
1768 "{} {}LIKE {}{} ESCAPE {}",
1769 expr,
1770 if *negated { "NOT " } else { "" },
1771 if *any { "ANY " } else { "" },
1772 pattern,
1773 ch
1774 ),
1775 _ => write!(
1776 f,
1777 "{} {}LIKE {}{}",
1778 expr,
1779 if *negated { "NOT " } else { "" },
1780 if *any { "ANY " } else { "" },
1781 pattern
1782 ),
1783 },
1784 Expr::ILike {
1785 negated,
1786 expr,
1787 pattern,
1788 escape_char,
1789 any,
1790 } => match escape_char {
1791 Some(ch) => write!(
1792 f,
1793 "{} {}ILIKE {}{} ESCAPE {}",
1794 expr,
1795 if *negated { "NOT " } else { "" },
1796 if *any { "ANY" } else { "" },
1797 pattern,
1798 ch
1799 ),
1800 _ => write!(
1801 f,
1802 "{} {}ILIKE {}{}",
1803 expr,
1804 if *negated { "NOT " } else { "" },
1805 if *any { "ANY " } else { "" },
1806 pattern
1807 ),
1808 },
1809 Expr::RLike {
1810 negated,
1811 expr,
1812 pattern,
1813 regexp,
1814 } => write!(
1815 f,
1816 "{} {}{} {}",
1817 expr,
1818 if *negated { "NOT " } else { "" },
1819 if *regexp { "REGEXP" } else { "RLIKE" },
1820 pattern
1821 ),
1822 Expr::IsNormalized {
1823 expr,
1824 form,
1825 negated,
1826 } => {
1827 let not_ = if *negated { "NOT " } else { "" };
1828 if form.is_none() {
1829 write!(f, "{expr} IS {not_}NORMALIZED")
1830 } else {
1831 write!(
1832 f,
1833 "{} IS {}{} NORMALIZED",
1834 expr,
1835 not_,
1836 form.as_ref().unwrap()
1837 )
1838 }
1839 }
1840 Expr::SimilarTo {
1841 negated,
1842 expr,
1843 pattern,
1844 escape_char,
1845 } => match escape_char {
1846 Some(ch) => write!(
1847 f,
1848 "{} {}SIMILAR TO {} ESCAPE {}",
1849 expr,
1850 if *negated { "NOT " } else { "" },
1851 pattern,
1852 ch
1853 ),
1854 _ => write!(
1855 f,
1856 "{} {}SIMILAR TO {}",
1857 expr,
1858 if *negated { "NOT " } else { "" },
1859 pattern
1860 ),
1861 },
1862 Expr::AnyOp {
1863 left,
1864 compare_op,
1865 right,
1866 is_some,
1867 } => {
1868 let add_parens = !matches!(right.as_ref(), Expr::Subquery(_));
1869 write!(
1870 f,
1871 "{left} {compare_op} {}{}{right}{}",
1872 if *is_some { "SOME" } else { "ANY" },
1873 if add_parens { "(" } else { "" },
1874 if add_parens { ")" } else { "" },
1875 )
1876 }
1877 Expr::AllOp {
1878 left,
1879 compare_op,
1880 right,
1881 } => {
1882 let add_parens = !matches!(right.as_ref(), Expr::Subquery(_));
1883 write!(
1884 f,
1885 "{left} {compare_op} ALL{}{right}{}",
1886 if add_parens { "(" } else { "" },
1887 if add_parens { ")" } else { "" },
1888 )
1889 }
1890 Expr::UnaryOp { op, expr } => {
1891 if op == &UnaryOperator::PGPostfixFactorial {
1892 write!(f, "{expr}{op}")
1893 } else if matches!(
1894 op,
1895 UnaryOperator::Not
1896 | UnaryOperator::Hash
1897 | UnaryOperator::AtDashAt
1898 | UnaryOperator::DoubleAt
1899 | UnaryOperator::QuestionDash
1900 | UnaryOperator::QuestionPipe
1901 ) {
1902 write!(f, "{op} {expr}")
1903 } else {
1904 write!(f, "{op}{expr}")
1905 }
1906 }
1907 Expr::Convert {
1908 is_try,
1909 expr,
1910 target_before_value,
1911 data_type,
1912 charset,
1913 styles,
1914 } => {
1915 write!(f, "{}CONVERT(", if *is_try { "TRY_" } else { "" })?;
1916 if let Some(data_type) = data_type {
1917 if let Some(charset) = charset {
1918 write!(f, "{expr}, {data_type} CHARACTER SET {charset}")
1919 } else if *target_before_value {
1920 write!(f, "{data_type}, {expr}")
1921 } else {
1922 write!(f, "{expr}, {data_type}")
1923 }
1924 } else if let Some(charset) = charset {
1925 write!(f, "{expr} USING {charset}")
1926 } else {
1927 write!(f, "{expr}") }?;
1929 if !styles.is_empty() {
1930 write!(f, ", {}", display_comma_separated(styles))?;
1931 }
1932 write!(f, ")")
1933 }
1934 Expr::Cast {
1935 kind,
1936 expr,
1937 data_type,
1938 array,
1939 format,
1940 } => match kind {
1941 CastKind::Cast => {
1942 write!(f, "CAST({expr} AS {data_type}")?;
1943 if *array {
1944 write!(f, " ARRAY")?;
1945 }
1946 if let Some(format) = format {
1947 write!(f, " FORMAT {format}")?;
1948 }
1949 write!(f, ")")
1950 }
1951 CastKind::TryCast => {
1952 if let Some(format) = format {
1953 write!(f, "TRY_CAST({expr} AS {data_type} FORMAT {format})")
1954 } else {
1955 write!(f, "TRY_CAST({expr} AS {data_type})")
1956 }
1957 }
1958 CastKind::SafeCast => {
1959 if let Some(format) = format {
1960 write!(f, "SAFE_CAST({expr} AS {data_type} FORMAT {format})")
1961 } else {
1962 write!(f, "SAFE_CAST({expr} AS {data_type})")
1963 }
1964 }
1965 CastKind::DoubleColon => {
1966 write!(f, "{expr}::{data_type}")
1967 }
1968 },
1969 Expr::Extract {
1970 field,
1971 syntax,
1972 expr,
1973 } => match syntax {
1974 ExtractSyntax::From => write!(f, "EXTRACT({field} FROM {expr})"),
1975 ExtractSyntax::Comma => write!(f, "EXTRACT({field}, {expr})"),
1976 },
1977 Expr::Ceil { expr, field } => match field {
1978 CeilFloorKind::DateTimeField(DateTimeField::NoDateTime) => {
1979 write!(f, "CEIL({expr})")
1980 }
1981 CeilFloorKind::DateTimeField(dt_field) => write!(f, "CEIL({expr} TO {dt_field})"),
1982 CeilFloorKind::Scale(s) => write!(f, "CEIL({expr}, {s})"),
1983 },
1984 Expr::Floor { expr, field } => match field {
1985 CeilFloorKind::DateTimeField(DateTimeField::NoDateTime) => {
1986 write!(f, "FLOOR({expr})")
1987 }
1988 CeilFloorKind::DateTimeField(dt_field) => write!(f, "FLOOR({expr} TO {dt_field})"),
1989 CeilFloorKind::Scale(s) => write!(f, "FLOOR({expr}, {s})"),
1990 },
1991 Expr::Position { expr, r#in } => write!(f, "POSITION({expr} IN {in})"),
1992 Expr::Collate { expr, collation } => write!(f, "{expr} COLLATE {collation}"),
1993 Expr::Nested(ast) => write!(f, "({ast})"),
1994 Expr::Value(v) => write!(f, "{v}"),
1995 Expr::Prefixed { prefix, value } => write!(f, "{prefix} {value}"),
1996 Expr::TypedString(ts) => ts.fmt(f),
1997 Expr::Function(fun) => fun.fmt(f),
1998 Expr::Case {
1999 case_token: _,
2000 end_token: _,
2001 operand,
2002 conditions,
2003 else_result,
2004 } => {
2005 f.write_str("CASE")?;
2006 if let Some(operand) = operand {
2007 f.write_str(" ")?;
2008 operand.fmt(f)?;
2009 }
2010 for when in conditions {
2011 SpaceOrNewline.fmt(f)?;
2012 Indent(when).fmt(f)?;
2013 }
2014 if let Some(else_result) = else_result {
2015 SpaceOrNewline.fmt(f)?;
2016 Indent("ELSE").fmt(f)?;
2017 SpaceOrNewline.fmt(f)?;
2018 Indent(Indent(else_result)).fmt(f)?;
2019 }
2020 SpaceOrNewline.fmt(f)?;
2021 f.write_str("END")
2022 }
2023 Expr::Exists { subquery, negated } => write!(
2024 f,
2025 "{}EXISTS ({})",
2026 if *negated { "NOT " } else { "" },
2027 subquery
2028 ),
2029 Expr::Subquery(s) => write!(f, "({s})"),
2030 Expr::GroupingSets(sets) => {
2031 write!(f, "GROUPING SETS (")?;
2032 let mut sep = "";
2033 for set in sets {
2034 write!(f, "{sep}")?;
2035 sep = ", ";
2036 write!(f, "({})", display_comma_separated(set))?;
2037 }
2038 write!(f, ")")
2039 }
2040 Expr::Cube(sets) => {
2041 write!(f, "CUBE (")?;
2042 let mut sep = "";
2043 for set in sets {
2044 write!(f, "{sep}")?;
2045 sep = ", ";
2046 if set.len() == 1 {
2047 write!(f, "{}", set[0])?;
2048 } else {
2049 write!(f, "({})", display_comma_separated(set))?;
2050 }
2051 }
2052 write!(f, ")")
2053 }
2054 Expr::Rollup(sets) => {
2055 write!(f, "ROLLUP (")?;
2056 let mut sep = "";
2057 for set in sets {
2058 write!(f, "{sep}")?;
2059 sep = ", ";
2060 if set.len() == 1 {
2061 write!(f, "{}", set[0])?;
2062 } else {
2063 write!(f, "({})", display_comma_separated(set))?;
2064 }
2065 }
2066 write!(f, ")")
2067 }
2068 Expr::Substring {
2069 expr,
2070 substring_from,
2071 substring_for,
2072 special,
2073 shorthand,
2074 } => {
2075 f.write_str("SUBSTR")?;
2076 if !*shorthand {
2077 f.write_str("ING")?;
2078 }
2079 write!(f, "({expr}")?;
2080 if let Some(from_part) = substring_from {
2081 if *special {
2082 write!(f, ", {from_part}")?;
2083 } else {
2084 write!(f, " FROM {from_part}")?;
2085 }
2086 }
2087 if let Some(for_part) = substring_for {
2088 if *special {
2089 write!(f, ", {for_part}")?;
2090 } else {
2091 write!(f, " FOR {for_part}")?;
2092 }
2093 }
2094
2095 write!(f, ")")
2096 }
2097 Expr::Overlay {
2098 expr,
2099 overlay_what,
2100 overlay_from,
2101 overlay_for,
2102 } => {
2103 write!(
2104 f,
2105 "OVERLAY({expr} PLACING {overlay_what} FROM {overlay_from}"
2106 )?;
2107 if let Some(for_part) = overlay_for {
2108 write!(f, " FOR {for_part}")?;
2109 }
2110
2111 write!(f, ")")
2112 }
2113 Expr::IsDistinctFrom(a, b) => write!(f, "{a} IS DISTINCT FROM {b}"),
2114 Expr::IsNotDistinctFrom(a, b) => write!(f, "{a} IS NOT DISTINCT FROM {b}"),
2115 Expr::Trim {
2116 expr,
2117 trim_where,
2118 trim_what,
2119 trim_characters,
2120 } => {
2121 write!(f, "TRIM(")?;
2122 if let Some(ident) = trim_where {
2123 write!(f, "{ident} ")?;
2124 }
2125 if let Some(trim_char) = trim_what {
2126 write!(f, "{trim_char} FROM {expr}")?;
2127 } else {
2128 write!(f, "{expr}")?;
2129 }
2130 if let Some(characters) = trim_characters {
2131 write!(f, ", {}", display_comma_separated(characters))?;
2132 }
2133
2134 write!(f, ")")
2135 }
2136 Expr::Tuple(exprs) => {
2137 write!(f, "({})", display_comma_separated(exprs))
2138 }
2139 Expr::Struct { values, fields } => {
2140 if !fields.is_empty() {
2141 write!(
2142 f,
2143 "STRUCT<{}>({})",
2144 display_comma_separated(fields),
2145 display_comma_separated(values)
2146 )
2147 } else {
2148 write!(f, "STRUCT({})", display_comma_separated(values))
2149 }
2150 }
2151 Expr::Named { expr, name } => {
2152 write!(f, "{expr} AS {name}")
2153 }
2154 Expr::Dictionary(fields) => {
2155 write!(f, "{{{}}}", display_comma_separated(fields))
2156 }
2157 Expr::Map(map) => {
2158 write!(f, "{map}")
2159 }
2160 Expr::Array(set) => {
2161 write!(f, "{set}")
2162 }
2163 Expr::JsonAccess { value, path } => {
2164 write!(f, "{value}{path}")
2165 }
2166 Expr::AtTimeZone {
2167 timestamp,
2168 time_zone,
2169 } => {
2170 write!(f, "{timestamp} AT TIME ZONE {time_zone}")
2171 }
2172 Expr::Interval(interval) => {
2173 write!(f, "{interval}")
2174 }
2175 Expr::MatchAgainst {
2176 columns,
2177 match_value: match_expr,
2178 opt_search_modifier,
2179 } => {
2180 write!(f, "MATCH ({}) AGAINST ", display_comma_separated(columns),)?;
2181
2182 if let Some(search_modifier) = opt_search_modifier {
2183 write!(f, "({match_expr} {search_modifier})")?;
2184 } else {
2185 write!(f, "({match_expr})")?;
2186 }
2187
2188 Ok(())
2189 }
2190 Expr::OuterJoin(expr) => {
2191 write!(f, "{expr} (+)")
2192 }
2193 Expr::Prior(expr) => write!(f, "PRIOR {expr}"),
2194 Expr::Lambda(lambda) => write!(f, "{lambda}"),
2195 Expr::MemberOf(member_of) => write!(f, "{member_of}"),
2196 }
2197 }
2198}
2199
2200#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2209#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2210#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2211pub enum WindowType {
2212 WindowSpec(WindowSpec),
2214 NamedWindow(Ident),
2216}
2217
2218impl Display for WindowType {
2219 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2220 match self {
2221 WindowType::WindowSpec(spec) => {
2222 f.write_str("(")?;
2223 NewLine.fmt(f)?;
2224 Indent(spec).fmt(f)?;
2225 NewLine.fmt(f)?;
2226 f.write_str(")")
2227 }
2228 WindowType::NamedWindow(name) => name.fmt(f),
2229 }
2230 }
2231}
2232
2233#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2235#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2236#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2237pub struct WindowSpec {
2238 pub window_name: Option<Ident>,
2246 pub partition_by: Vec<Expr>,
2248 pub order_by: Vec<OrderByExpr>,
2250 pub window_frame: Option<WindowFrame>,
2252}
2253
2254impl fmt::Display for WindowSpec {
2255 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2256 let mut is_first = true;
2257 if let Some(window_name) = &self.window_name {
2258 if !is_first {
2259 SpaceOrNewline.fmt(f)?;
2260 }
2261 is_first = false;
2262 write!(f, "{window_name}")?;
2263 }
2264 if !self.partition_by.is_empty() {
2265 if !is_first {
2266 SpaceOrNewline.fmt(f)?;
2267 }
2268 is_first = false;
2269 write!(
2270 f,
2271 "PARTITION BY {}",
2272 display_comma_separated(&self.partition_by)
2273 )?;
2274 }
2275 if !self.order_by.is_empty() {
2276 if !is_first {
2277 SpaceOrNewline.fmt(f)?;
2278 }
2279 is_first = false;
2280 write!(f, "ORDER BY {}", display_comma_separated(&self.order_by))?;
2281 }
2282 if let Some(window_frame) = &self.window_frame {
2283 if !is_first {
2284 SpaceOrNewline.fmt(f)?;
2285 }
2286 if let Some(end_bound) = &window_frame.end_bound {
2287 write!(
2288 f,
2289 "{} BETWEEN {} AND {}",
2290 window_frame.units, window_frame.start_bound, end_bound
2291 )?;
2292 } else {
2293 write!(f, "{} {}", window_frame.units, window_frame.start_bound)?;
2294 }
2295 }
2296 Ok(())
2297 }
2298}
2299
2300#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2306#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2307#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2308pub struct WindowFrame {
2309 pub units: WindowFrameUnits,
2311 pub start_bound: WindowFrameBound,
2313 pub end_bound: Option<WindowFrameBound>,
2317 }
2319
2320impl Default for WindowFrame {
2321 fn default() -> Self {
2325 Self {
2326 units: WindowFrameUnits::Range,
2327 start_bound: WindowFrameBound::Preceding(None),
2328 end_bound: None,
2329 }
2330 }
2331}
2332
2333#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2334#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2335#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2336pub enum WindowFrameUnits {
2338 Rows,
2340 Range,
2342 Groups,
2344}
2345
2346impl fmt::Display for WindowFrameUnits {
2347 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2348 f.write_str(match self {
2349 WindowFrameUnits::Rows => "ROWS",
2350 WindowFrameUnits::Range => "RANGE",
2351 WindowFrameUnits::Groups => "GROUPS",
2352 })
2353 }
2354}
2355
2356#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2360#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2361#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2362pub enum NullTreatment {
2364 IgnoreNulls,
2366 RespectNulls,
2368}
2369
2370impl fmt::Display for NullTreatment {
2371 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2372 f.write_str(match self {
2373 NullTreatment::IgnoreNulls => "IGNORE NULLS",
2374 NullTreatment::RespectNulls => "RESPECT NULLS",
2375 })
2376 }
2377}
2378
2379#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2381#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2382#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2383pub enum WindowFrameBound {
2384 CurrentRow,
2386 Preceding(Option<Box<Expr>>),
2388 Following(Option<Box<Expr>>),
2390}
2391
2392impl fmt::Display for WindowFrameBound {
2393 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2394 match self {
2395 WindowFrameBound::CurrentRow => f.write_str("CURRENT ROW"),
2396 WindowFrameBound::Preceding(None) => f.write_str("UNBOUNDED PRECEDING"),
2397 WindowFrameBound::Following(None) => f.write_str("UNBOUNDED FOLLOWING"),
2398 WindowFrameBound::Preceding(Some(n)) => write!(f, "{n} PRECEDING"),
2399 WindowFrameBound::Following(Some(n)) => write!(f, "{n} FOLLOWING"),
2400 }
2401 }
2402}
2403
2404#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2405#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2406#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2407pub enum AddDropSync {
2409 ADD,
2411 DROP,
2413 SYNC,
2415}
2416
2417impl fmt::Display for AddDropSync {
2418 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2419 match self {
2420 AddDropSync::SYNC => f.write_str("SYNC PARTITIONS"),
2421 AddDropSync::DROP => f.write_str("DROP PARTITIONS"),
2422 AddDropSync::ADD => f.write_str("ADD PARTITIONS"),
2423 }
2424 }
2425}
2426
2427#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2428#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2429#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2430pub enum ShowCreateObject {
2432 Event,
2434 Function,
2436 Procedure,
2438 Table,
2440 Trigger,
2442 View,
2444}
2445
2446impl fmt::Display for ShowCreateObject {
2447 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2448 match self {
2449 ShowCreateObject::Event => f.write_str("EVENT"),
2450 ShowCreateObject::Function => f.write_str("FUNCTION"),
2451 ShowCreateObject::Procedure => f.write_str("PROCEDURE"),
2452 ShowCreateObject::Table => f.write_str("TABLE"),
2453 ShowCreateObject::Trigger => f.write_str("TRIGGER"),
2454 ShowCreateObject::View => f.write_str("VIEW"),
2455 }
2456 }
2457}
2458
2459#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2460#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2461#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2462pub enum CommentObject {
2464 Aggregate,
2466 Collation,
2468 Column,
2470 Constraint,
2472 Database,
2474 Domain,
2476 Extension,
2478 Function,
2480 Index,
2482 MaterializedView,
2484 Operator,
2486 Policy,
2488 Procedure,
2490 Role,
2492 Rule,
2494 Schema,
2496 Sequence,
2498 Table,
2500 Trigger,
2502 Type,
2504 User,
2506 View,
2508}
2509
2510impl CommentObject {
2511 pub(crate) fn keyword_str(&self) -> &'static str {
2512 match self {
2513 CommentObject::Aggregate => "AGGREGATE",
2514 CommentObject::Collation => "COLLATION",
2515 CommentObject::Column => "COLUMN",
2516 CommentObject::Constraint => "CONSTRAINT",
2517 CommentObject::Database => "DATABASE",
2518 CommentObject::Domain => "DOMAIN",
2519 CommentObject::Extension => "EXTENSION",
2520 CommentObject::Function => "FUNCTION",
2521 CommentObject::Index => "INDEX",
2522 CommentObject::MaterializedView => "MATERIALIZED VIEW",
2523 CommentObject::Operator => "OPERATOR",
2524 CommentObject::Policy => "POLICY",
2525 CommentObject::Procedure => "PROCEDURE",
2526 CommentObject::Role => "ROLE",
2527 CommentObject::Rule => "RULE",
2528 CommentObject::Schema => "SCHEMA",
2529 CommentObject::Sequence => "SEQUENCE",
2530 CommentObject::Table => "TABLE",
2531 CommentObject::Trigger => "TRIGGER",
2532 CommentObject::Type => "TYPE",
2533 CommentObject::User => "USER",
2534 CommentObject::View => "VIEW",
2535 }
2536 }
2537
2538 pub(crate) fn from_keyword(keyword: Keyword) -> Option<Self> {
2543 Some(match keyword {
2544 Keyword::AGGREGATE => CommentObject::Aggregate,
2545 Keyword::COLLATION => CommentObject::Collation,
2546 Keyword::COLUMN => CommentObject::Column,
2547 Keyword::CONSTRAINT => CommentObject::Constraint,
2548 Keyword::DATABASE => CommentObject::Database,
2549 Keyword::DOMAIN => CommentObject::Domain,
2550 Keyword::EXTENSION => CommentObject::Extension,
2551 Keyword::FUNCTION => CommentObject::Function,
2552 Keyword::INDEX => CommentObject::Index,
2553 Keyword::OPERATOR => CommentObject::Operator,
2554 Keyword::POLICY => CommentObject::Policy,
2555 Keyword::PROCEDURE => CommentObject::Procedure,
2556 Keyword::ROLE => CommentObject::Role,
2557 Keyword::RULE => CommentObject::Rule,
2558 Keyword::SCHEMA => CommentObject::Schema,
2559 Keyword::SEQUENCE => CommentObject::Sequence,
2560 Keyword::TABLE => CommentObject::Table,
2561 Keyword::TRIGGER => CommentObject::Trigger,
2562 Keyword::TYPE => CommentObject::Type,
2563 Keyword::USER => CommentObject::User,
2564 Keyword::VIEW => CommentObject::View,
2565 _ => return None,
2566 })
2567 }
2568}
2569
2570impl fmt::Display for CommentObject {
2571 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2572 f.write_str(self.keyword_str())
2573 }
2574}
2575
2576#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2583#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2584#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2585pub struct CommentOperatorArgs {
2586 pub left: Option<DataType>,
2588 pub right: Option<DataType>,
2590}
2591
2592impl fmt::Display for CommentOperatorArgs {
2593 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2594 let write_side = |opt: &Option<DataType>, f: &mut fmt::Formatter| -> fmt::Result {
2595 match opt {
2596 Some(dt) => write!(f, "{dt}"),
2597 None => f.write_str("NONE"),
2598 }
2599 };
2600 f.write_str("(")?;
2601 write_side(&self.left, f)?;
2602 f.write_str(", ")?;
2603 write_side(&self.right, f)?;
2604 f.write_str(")")
2605 }
2606}
2607
2608#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2609#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2610#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2611pub enum Password {
2613 Password(Expr),
2615 NullPassword,
2617}
2618
2619#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2636#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2637#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2638pub struct CaseStatement {
2639 pub case_token: AttachedToken,
2641 pub match_expr: Option<Expr>,
2643 pub when_blocks: Vec<ConditionalStatementBlock>,
2645 pub else_block: Option<ConditionalStatementBlock>,
2647 pub end_case_token: AttachedToken,
2649}
2650
2651impl fmt::Display for CaseStatement {
2652 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2653 let CaseStatement {
2654 case_token: _,
2655 match_expr,
2656 when_blocks,
2657 else_block,
2658 end_case_token: AttachedToken(end),
2659 } = self;
2660
2661 write!(f, "CASE")?;
2662
2663 if let Some(expr) = match_expr {
2664 write!(f, " {expr}")?;
2665 }
2666
2667 if !when_blocks.is_empty() {
2668 write!(f, " {}", display_separated(when_blocks, " "))?;
2669 }
2670
2671 if let Some(else_block) = else_block {
2672 write!(f, " {else_block}")?;
2673 }
2674
2675 write!(f, " END")?;
2676
2677 if let Token::Word(w) = &end.token {
2678 if w.keyword == Keyword::CASE {
2679 write!(f, " CASE")?;
2680 }
2681 }
2682
2683 Ok(())
2684 }
2685}
2686
2687#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2709#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2710#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2711pub struct IfStatement {
2712 pub if_block: ConditionalStatementBlock,
2714 pub elseif_blocks: Vec<ConditionalStatementBlock>,
2716 pub else_block: Option<ConditionalStatementBlock>,
2718 pub end_token: Option<AttachedToken>,
2720}
2721
2722impl fmt::Display for IfStatement {
2723 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2724 let IfStatement {
2725 if_block,
2726 elseif_blocks,
2727 else_block,
2728 end_token,
2729 } = self;
2730
2731 write!(f, "{if_block}")?;
2732
2733 for elseif_block in elseif_blocks {
2734 write!(f, " {elseif_block}")?;
2735 }
2736
2737 if let Some(else_block) = else_block {
2738 write!(f, " {else_block}")?;
2739 }
2740
2741 if let Some(AttachedToken(end_token)) = end_token {
2742 write!(f, " END {end_token}")?;
2743 }
2744
2745 Ok(())
2746 }
2747}
2748
2749#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2761#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2762#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2763pub struct WhileStatement {
2764 pub while_block: ConditionalStatementBlock,
2766}
2767
2768impl fmt::Display for WhileStatement {
2769 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2770 let WhileStatement { while_block } = self;
2771 write!(f, "{while_block}")?;
2772 Ok(())
2773 }
2774}
2775
2776#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2801#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2802#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2803pub struct ConditionalStatementBlock {
2804 pub start_token: AttachedToken,
2806 pub condition: Option<Expr>,
2808 pub then_token: Option<AttachedToken>,
2810 pub conditional_statements: ConditionalStatements,
2812}
2813
2814impl ConditionalStatementBlock {
2815 pub fn statements(&self) -> &Vec<Statement> {
2817 self.conditional_statements.statements()
2818 }
2819}
2820
2821impl fmt::Display for ConditionalStatementBlock {
2822 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2823 let ConditionalStatementBlock {
2824 start_token: AttachedToken(start_token),
2825 condition,
2826 then_token,
2827 conditional_statements,
2828 } = self;
2829
2830 write!(f, "{start_token}")?;
2831
2832 if let Some(condition) = condition {
2833 write!(f, " {condition}")?;
2834 }
2835
2836 if then_token.is_some() {
2837 write!(f, " THEN")?;
2838 }
2839
2840 if !conditional_statements.statements().is_empty() {
2841 write!(f, " {conditional_statements}")?;
2842 }
2843
2844 Ok(())
2845 }
2846}
2847
2848#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2850#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2851#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2852pub enum ConditionalStatements {
2854 Sequence {
2856 statements: Vec<Statement>,
2858 },
2859 BeginEnd(BeginEndStatements),
2861}
2862
2863impl ConditionalStatements {
2864 pub fn statements(&self) -> &Vec<Statement> {
2866 match self {
2867 ConditionalStatements::Sequence { statements } => statements,
2868 ConditionalStatements::BeginEnd(bes) => &bes.statements,
2869 }
2870 }
2871}
2872
2873impl fmt::Display for ConditionalStatements {
2874 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2875 match self {
2876 ConditionalStatements::Sequence { statements } => {
2877 if !statements.is_empty() {
2878 format_statement_list(f, statements)?;
2879 }
2880 Ok(())
2881 }
2882 ConditionalStatements::BeginEnd(bes) => write!(f, "{bes}"),
2883 }
2884 }
2885}
2886
2887#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2896#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2897#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2898pub struct BeginEndStatements {
2899 pub begin_token: AttachedToken,
2901 pub statements: Vec<Statement>,
2903 pub end_token: AttachedToken,
2905}
2906
2907impl fmt::Display for BeginEndStatements {
2908 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2909 let BeginEndStatements {
2910 begin_token: AttachedToken(begin_token),
2911 statements,
2912 end_token: AttachedToken(end_token),
2913 } = self;
2914
2915 if begin_token.token != Token::EOF {
2916 write!(f, "{begin_token} ")?;
2917 }
2918 if !statements.is_empty() {
2919 format_statement_list(f, statements)?;
2920 }
2921 if end_token.token != Token::EOF {
2922 write!(f, " {end_token}")?;
2923 }
2924 Ok(())
2925 }
2926}
2927
2928#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2940#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2941#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2942pub struct RaiseStatement {
2943 pub value: Option<RaiseStatementValue>,
2945}
2946
2947impl fmt::Display for RaiseStatement {
2948 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2949 let RaiseStatement { value } = self;
2950
2951 write!(f, "RAISE")?;
2952 if let Some(value) = value {
2953 write!(f, " {value}")?;
2954 }
2955
2956 Ok(())
2957 }
2958}
2959
2960#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2962#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2963#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2964pub enum RaiseStatementValue {
2965 UsingMessage(Expr),
2967 Expr(Expr),
2969}
2970
2971impl fmt::Display for RaiseStatementValue {
2972 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2973 match self {
2974 RaiseStatementValue::Expr(expr) => write!(f, "{expr}"),
2975 RaiseStatementValue::UsingMessage(expr) => write!(f, "USING MESSAGE = {expr}"),
2976 }
2977 }
2978}
2979
2980#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2988#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2989#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2990pub struct ThrowStatement {
2991 pub error_number: Option<Box<Expr>>,
2993 pub message: Option<Box<Expr>>,
2995 pub state: Option<Box<Expr>>,
2997}
2998
2999impl fmt::Display for ThrowStatement {
3000 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3001 let ThrowStatement {
3002 error_number,
3003 message,
3004 state,
3005 } = self;
3006
3007 write!(f, "THROW")?;
3008 if let (Some(error_number), Some(message), Some(state)) = (error_number, message, state) {
3009 write!(f, " {error_number}, {message}, {state}")?;
3010 }
3011 Ok(())
3012 }
3013}
3014
3015#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3023#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3024#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3025pub enum DeclareAssignment {
3026 Expr(Box<Expr>),
3028
3029 Default(Box<Expr>),
3031
3032 DuckAssignment(Box<Expr>),
3039
3040 For(Box<Expr>),
3047
3048 MsSqlAssignment(Box<Expr>),
3055}
3056
3057impl fmt::Display for DeclareAssignment {
3058 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3059 match self {
3060 DeclareAssignment::Expr(expr) => {
3061 write!(f, "{expr}")
3062 }
3063 DeclareAssignment::Default(expr) => {
3064 write!(f, "DEFAULT {expr}")
3065 }
3066 DeclareAssignment::DuckAssignment(expr) => {
3067 write!(f, ":= {expr}")
3068 }
3069 DeclareAssignment::MsSqlAssignment(expr) => {
3070 write!(f, "= {expr}")
3071 }
3072 DeclareAssignment::For(expr) => {
3073 write!(f, "FOR {expr}")
3074 }
3075 }
3076 }
3077}
3078
3079#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3081#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3082#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3083pub enum DeclareType {
3084 Cursor,
3090
3091 ResultSet,
3099
3100 Exception,
3108}
3109
3110impl fmt::Display for DeclareType {
3111 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3112 match self {
3113 DeclareType::Cursor => {
3114 write!(f, "CURSOR")
3115 }
3116 DeclareType::ResultSet => {
3117 write!(f, "RESULTSET")
3118 }
3119 DeclareType::Exception => {
3120 write!(f, "EXCEPTION")
3121 }
3122 }
3123 }
3124}
3125
3126#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3139#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3140#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3141pub struct Declare {
3142 pub names: Vec<Ident>,
3145 pub data_type: Option<DataType>,
3148 pub assignment: Option<DeclareAssignment>,
3150 pub declare_type: Option<DeclareType>,
3152 pub binary: Option<bool>,
3154 pub sensitive: Option<bool>,
3158 pub scroll: Option<bool>,
3162 pub hold: Option<bool>,
3166 pub for_query: Option<Box<Query>>,
3168}
3169
3170impl fmt::Display for Declare {
3171 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3172 let Declare {
3173 names,
3174 data_type,
3175 assignment,
3176 declare_type,
3177 binary,
3178 sensitive,
3179 scroll,
3180 hold,
3181 for_query,
3182 } = self;
3183 write!(f, "{}", display_comma_separated(names))?;
3184
3185 if let Some(true) = binary {
3186 write!(f, " BINARY")?;
3187 }
3188
3189 if let Some(sensitive) = sensitive {
3190 if *sensitive {
3191 write!(f, " INSENSITIVE")?;
3192 } else {
3193 write!(f, " ASENSITIVE")?;
3194 }
3195 }
3196
3197 if let Some(scroll) = scroll {
3198 if *scroll {
3199 write!(f, " SCROLL")?;
3200 } else {
3201 write!(f, " NO SCROLL")?;
3202 }
3203 }
3204
3205 if let Some(declare_type) = declare_type {
3206 write!(f, " {declare_type}")?;
3207 }
3208
3209 if let Some(hold) = hold {
3210 if *hold {
3211 write!(f, " WITH HOLD")?;
3212 } else {
3213 write!(f, " WITHOUT HOLD")?;
3214 }
3215 }
3216
3217 if let Some(query) = for_query {
3218 write!(f, " FOR {query}")?;
3219 }
3220
3221 if let Some(data_type) = data_type {
3222 write!(f, " {data_type}")?;
3223 }
3224
3225 if let Some(expr) = assignment {
3226 write!(f, " {expr}")?;
3227 }
3228 Ok(())
3229 }
3230}
3231
3232#[derive(Debug, Default, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3234#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3235#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3236pub enum CreateTableOptions {
3238 #[default]
3240 None,
3241 With(Vec<SqlOption>),
3243 Options(Vec<SqlOption>),
3245 Plain(Vec<SqlOption>),
3247 TableProperties(Vec<SqlOption>),
3249}
3250
3251impl fmt::Display for CreateTableOptions {
3252 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3253 match self {
3254 CreateTableOptions::With(with_options) => {
3255 write!(f, "WITH ({})", display_comma_separated(with_options))
3256 }
3257 CreateTableOptions::Options(options) => {
3258 write!(f, "OPTIONS({})", display_comma_separated(options))
3259 }
3260 CreateTableOptions::TableProperties(options) => {
3261 write!(f, "TBLPROPERTIES ({})", display_comma_separated(options))
3262 }
3263 CreateTableOptions::Plain(options) => {
3264 write!(f, "{}", display_separated(options, " "))
3265 }
3266 CreateTableOptions::None => Ok(()),
3267 }
3268 }
3269}
3270
3271#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3278#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3279#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3280pub enum FromTable {
3281 WithFromKeyword(Vec<TableWithJoins>),
3283 WithoutKeyword(Vec<TableWithJoins>),
3286}
3287impl Display for FromTable {
3288 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3289 match self {
3290 FromTable::WithFromKeyword(tables) => {
3291 write!(f, "FROM {}", display_comma_separated(tables))
3292 }
3293 FromTable::WithoutKeyword(tables) => {
3294 write!(f, "{}", display_comma_separated(tables))
3295 }
3296 }
3297 }
3298}
3299
3300#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3301#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3302#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3303pub enum Set {
3305 SingleAssignment {
3309 scope: Option<ContextModifier>,
3311 hivevar: bool,
3313 variable: ObjectName,
3315 values: Vec<Expr>,
3317 },
3318 ParenthesizedAssignments {
3322 variables: Vec<ObjectName>,
3324 values: Vec<Expr>,
3326 },
3327 MultipleAssignments {
3331 assignments: Vec<SetAssignment>,
3333 },
3334 SetSessionAuthorization(SetSessionAuthorizationParam),
3343 SetSessionParam(SetSessionParamKind),
3347 SetRole {
3358 context_modifier: Option<ContextModifier>,
3360 role_name: Option<Ident>,
3362 },
3363 SetTimeZone {
3373 local: bool,
3375 value: Expr,
3377 },
3378 SetNames {
3382 charset_name: Ident,
3384 collation_name: Option<String>,
3386 },
3387 SetNamesDefault {},
3393 SetTransaction {
3397 modes: Vec<TransactionMode>,
3399 snapshot: Option<ValueWithSpan>,
3401 session: bool,
3403 },
3404}
3405
3406impl Display for Set {
3407 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3408 match self {
3409 Self::ParenthesizedAssignments { variables, values } => write!(
3410 f,
3411 "SET ({}) = ({})",
3412 display_comma_separated(variables),
3413 display_comma_separated(values)
3414 ),
3415 Self::MultipleAssignments { assignments } => {
3416 write!(f, "SET {}", display_comma_separated(assignments))
3417 }
3418 Self::SetRole {
3419 context_modifier,
3420 role_name,
3421 } => {
3422 let role_name = role_name.clone().unwrap_or_else(|| Ident::new("NONE"));
3423 write!(
3424 f,
3425 "SET {modifier}ROLE {role_name}",
3426 modifier = context_modifier.map(|m| format!("{m}")).unwrap_or_default()
3427 )
3428 }
3429 Self::SetSessionAuthorization(kind) => write!(f, "SET SESSION AUTHORIZATION {kind}"),
3430 Self::SetSessionParam(kind) => write!(f, "SET {kind}"),
3431 Self::SetTransaction {
3432 modes,
3433 snapshot,
3434 session,
3435 } => {
3436 if *session {
3437 write!(f, "SET SESSION CHARACTERISTICS AS TRANSACTION")?;
3438 } else {
3439 write!(f, "SET TRANSACTION")?;
3440 }
3441 if !modes.is_empty() {
3442 write!(f, " {}", display_comma_separated(modes))?;
3443 }
3444 if let Some(snapshot_id) = snapshot {
3445 write!(f, " SNAPSHOT {snapshot_id}")?;
3446 }
3447 Ok(())
3448 }
3449 Self::SetTimeZone { local, value } => {
3450 f.write_str("SET ")?;
3451 if *local {
3452 f.write_str("LOCAL ")?;
3453 }
3454 write!(f, "TIME ZONE {value}")
3455 }
3456 Self::SetNames {
3457 charset_name,
3458 collation_name,
3459 } => {
3460 write!(f, "SET NAMES {charset_name}")?;
3461
3462 if let Some(collation) = collation_name {
3463 f.write_str(" COLLATE ")?;
3464 f.write_str(collation)?;
3465 };
3466
3467 Ok(())
3468 }
3469 Self::SetNamesDefault {} => {
3470 f.write_str("SET NAMES DEFAULT")?;
3471
3472 Ok(())
3473 }
3474 Set::SingleAssignment {
3475 scope,
3476 hivevar,
3477 variable,
3478 values,
3479 } => {
3480 write!(
3481 f,
3482 "SET {}{}{} = {}",
3483 scope.map(|s| format!("{s}")).unwrap_or_default(),
3484 if *hivevar { "HIVEVAR:" } else { "" },
3485 variable,
3486 display_comma_separated(values)
3487 )
3488 }
3489 }
3490 }
3491}
3492
3493#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3499#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3500#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3501pub struct ExceptionWhen {
3502 pub idents: Vec<Ident>,
3504 pub statements: Vec<Statement>,
3506}
3507
3508impl Display for ExceptionWhen {
3509 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3510 write!(
3511 f,
3512 "WHEN {idents} THEN",
3513 idents = display_separated(&self.idents, " OR ")
3514 )?;
3515
3516 if !self.statements.is_empty() {
3517 write!(f, " ")?;
3518 format_statement_list(f, &self.statements)?;
3519 }
3520
3521 Ok(())
3522 }
3523}
3524
3525#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3532#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3533#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3534pub struct Analyze {
3535 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3536 pub table_name: Option<ObjectName>,
3538 pub partitions: Option<Vec<Expr>>,
3540 pub for_columns: bool,
3542 pub columns: Vec<Ident>,
3544 pub cache_metadata: bool,
3546 pub noscan: bool,
3548 pub compute_statistics: bool,
3550 pub has_table_keyword: bool,
3552}
3553
3554impl fmt::Display for Analyze {
3555 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3556 write!(f, "ANALYZE")?;
3557 if let Some(ref table_name) = self.table_name {
3558 if self.has_table_keyword {
3559 write!(f, " TABLE")?;
3560 }
3561 write!(f, " {table_name}")?;
3562 }
3563 if !self.for_columns && !self.columns.is_empty() {
3564 write!(f, " ({})", display_comma_separated(&self.columns))?;
3565 }
3566 if let Some(ref parts) = self.partitions {
3567 if !parts.is_empty() {
3568 write!(f, " PARTITION ({})", display_comma_separated(parts))?;
3569 }
3570 }
3571 if self.compute_statistics {
3572 write!(f, " COMPUTE STATISTICS")?;
3573 }
3574 if self.noscan {
3575 write!(f, " NOSCAN")?;
3576 }
3577 if self.cache_metadata {
3578 write!(f, " CACHE METADATA")?;
3579 }
3580 if self.for_columns {
3581 write!(f, " FOR COLUMNS")?;
3582 if !self.columns.is_empty() {
3583 write!(f, " {}", display_comma_separated(&self.columns))?;
3584 }
3585 }
3586 Ok(())
3587 }
3588}
3589
3590#[allow(clippy::large_enum_variant)]
3592#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3593#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3594#[cfg_attr(
3595 feature = "visitor",
3596 derive(Visit, VisitMut),
3597 visit(with = "visit_statement")
3598)]
3599pub enum Statement {
3600 Analyze(Analyze),
3605 Set(Set),
3607 Truncate(Truncate),
3612 Msck(Msck),
3617 Query(Box<Query>),
3621 Insert(Insert),
3625 Install {
3629 extension_name: Ident,
3631 },
3632 Load {
3636 extension_name: Ident,
3638 },
3639 Directory {
3642 overwrite: bool,
3644 local: bool,
3646 path: String,
3648 file_format: Option<FileFormat>,
3650 source: Box<Query>,
3652 },
3653 Case(CaseStatement),
3655 If(IfStatement),
3657 While(WhileStatement),
3659 Raise(RaiseStatement),
3661 Call(Function),
3665 Copy {
3669 source: CopySource,
3671 to: bool,
3673 target: CopyTarget,
3675 options: Vec<CopyOption>,
3677 legacy_options: Vec<CopyLegacyOption>,
3679 values: Vec<Option<String>>,
3681 },
3682 CopyIntoSnowflake {
3694 kind: CopyIntoSnowflakeKind,
3696 into: ObjectName,
3698 into_columns: Option<Vec<Ident>>,
3700 from_obj: Option<ObjectName>,
3702 from_obj_alias: Option<Ident>,
3704 stage_params: StageParamsObject,
3706 from_transformations: Option<Vec<StageLoadSelectItemKind>>,
3708 from_query: Option<Box<Query>>,
3710 files: Option<Vec<String>>,
3712 pattern: Option<String>,
3714 file_format: KeyValueOptions,
3716 copy_options: KeyValueOptions,
3718 validation_mode: Option<String>,
3720 partition: Option<Box<Expr>>,
3722 },
3723 Open(OpenStatement),
3728 Close {
3733 cursor: CloseCursor,
3735 },
3736 Update(Update),
3740 Delete(Delete),
3744 CreateView(CreateView),
3748 CreateTable(CreateTable),
3752 CreateVirtualTable {
3757 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3758 name: ObjectName,
3760 if_not_exists: bool,
3762 module_name: Ident,
3764 module_args: Vec<Ident>,
3766 },
3767 CreateIndex(CreateIndex),
3771 CreateRole(CreateRole),
3776 CreateSecret {
3781 or_replace: bool,
3783 temporary: Option<bool>,
3785 if_not_exists: bool,
3787 name: Option<Ident>,
3789 storage_specifier: Option<Ident>,
3791 secret_type: Ident,
3793 options: Vec<SecretOption>,
3795 },
3796 CreateServer(CreateServerStatement),
3798 CreateForeignDataWrapper(CreateForeignDataWrapper),
3803 CreateForeignTable(CreateForeignTable),
3808 CreatePolicy(CreatePolicy),
3813 CreateConnector(CreateConnector),
3818 CreateOperator(CreateOperator),
3823 CreateOperatorFamily(CreateOperatorFamily),
3828 CreateOperatorClass(CreateOperatorClass),
3833 CreateAggregate(CreateAggregate),
3838 AlterTable(AlterTable),
3842 AlterSchema(AlterSchema),
3847 AlterIndex {
3851 name: ObjectName,
3853 operation: AlterIndexOperation,
3855 },
3856 AlterView {
3860 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3862 name: ObjectName,
3863 columns: Vec<Ident>,
3865 query: Box<Query>,
3867 with_options: Vec<SqlOption>,
3869 },
3870 AlterDomain(AlterDomain),
3875 AlterExtension(AlterExtension),
3880 AlterFunction(AlterFunction),
3889 AlterType(AlterType),
3894 AlterTrigger(AlterTrigger),
3899 AlterCollation(AlterCollation),
3904 AlterDefaultPrivileges(AlterDefaultPrivileges),
3912 AlterOperator(AlterOperator),
3917 AlterOperatorFamily(AlterOperatorFamily),
3922 AlterOperatorClass(AlterOperatorClass),
3927 AlterRole {
3931 name: Ident,
3933 operation: AlterRoleOperation,
3935 },
3936 AlterPolicy(AlterPolicy),
3941 AlterConnector {
3950 name: Ident,
3952 properties: Option<Vec<SqlOption>>,
3954 url: Option<String>,
3956 owner: Option<ddl::AlterConnectorOwner>,
3958 },
3959 AlterSession {
3965 set: bool,
3967 session_params: KeyValueOptions,
3969 },
3970 AttachDatabase {
3975 schema_name: Ident,
3977 database_file_name: Expr,
3979 database: bool,
3981 },
3982 AttachDuckDBDatabase {
3988 if_not_exists: bool,
3990 database: bool,
3992 database_path: Ident,
3994 database_alias: Option<Ident>,
3996 attach_options: Vec<AttachDuckDBDatabaseOption>,
3998 },
3999 DetachDuckDBDatabase {
4005 if_exists: bool,
4007 database: bool,
4009 database_alias: Ident,
4011 },
4012 Drop {
4016 object_type: ObjectType,
4018 if_exists: bool,
4020 names: Vec<ObjectName>,
4022 cascade: bool,
4025 restrict: bool,
4028 purge: bool,
4031 temporary: bool,
4033 table: Option<ObjectName>,
4036 },
4037 DropFunction(DropFunction),
4041 DropDomain(DropDomain),
4049 DropProcedure {
4053 if_exists: bool,
4055 proc_desc: Vec<FunctionDesc>,
4057 drop_behavior: Option<DropBehavior>,
4059 },
4060 DropSecret {
4064 if_exists: bool,
4066 temporary: Option<bool>,
4068 name: Ident,
4070 storage_specifier: Option<Ident>,
4072 },
4073 DropPolicy(DropPolicy),
4078 DropConnector {
4083 if_exists: bool,
4085 name: Ident,
4087 },
4088 Declare {
4096 stmts: Vec<Declare>,
4098 },
4099 CreateExtension(CreateExtension),
4108 CreateCollation(CreateCollation),
4114 CreateTextSearchConfiguration(CreateTextSearchConfiguration),
4120 CreateTextSearchDictionary(CreateTextSearchDictionary),
4126 CreateTextSearchParser(CreateTextSearchParser),
4132 CreateTextSearchTemplate(CreateTextSearchTemplate),
4138 CreatePublication(CreatePublication),
4144 CreateSubscription(CreateSubscription),
4150 CreateCast(CreateCast),
4158 CreateConversion(CreateConversion),
4164 CreateLanguage(CreateLanguage),
4170 CreateRule(CreateRule),
4176 CreateStatistics(CreateStatistics),
4182 CreateAccessMethod(CreateAccessMethod),
4188 CreateEventTrigger(CreateEventTrigger),
4194 CreateTransform(CreateTransform),
4200 SecurityLabel(SecurityLabel),
4206 CreateUserMapping(CreateUserMapping),
4212 CreateTablespace(CreateTablespace),
4218 DropExtension(DropExtension),
4224 DropOperator(DropOperator),
4230 DropOperatorFamily(DropOperatorFamily),
4236 DropOperatorClass(DropOperatorClass),
4242 Fetch {
4250 name: Ident,
4252 direction: FetchDirection,
4254 position: FetchPosition,
4256 into: Option<ObjectName>,
4258 },
4259 Flush {
4266 object_type: FlushType,
4268 location: Option<FlushLocation>,
4270 channel: Option<String>,
4272 read_lock: bool,
4274 export: bool,
4276 tables: Vec<ObjectName>,
4278 },
4279 Discard {
4286 object_type: DiscardObject,
4288 },
4289 ShowFunctions {
4293 filter: Option<ShowStatementFilter>,
4295 },
4296 ShowVariable {
4302 variable: Vec<Ident>,
4304 },
4305 ShowStatus {
4311 filter: Option<ShowStatementFilter>,
4313 global: bool,
4315 session: bool,
4317 },
4318 ShowVariables {
4324 filter: Option<ShowStatementFilter>,
4326 global: bool,
4328 session: bool,
4330 },
4331 ShowCreate {
4337 obj_type: ShowCreateObject,
4339 obj_name: ObjectName,
4341 },
4342 ShowColumns {
4346 extended: bool,
4348 full: bool,
4350 show_options: ShowStatementOptions,
4352 },
4353 ShowCatalogs {
4357 terse: bool,
4359 history: bool,
4361 show_options: ShowStatementOptions,
4363 },
4364 ShowDatabases {
4368 terse: bool,
4370 history: bool,
4372 show_options: ShowStatementOptions,
4374 },
4375 ShowProcessList {
4381 full: bool,
4383 },
4384 ShowSchemas {
4388 terse: bool,
4390 history: bool,
4392 show_options: ShowStatementOptions,
4394 },
4395 ShowCharset(ShowCharset),
4402 ShowObjects(ShowObjects),
4408 ShowTables {
4412 terse: bool,
4414 history: bool,
4416 extended: bool,
4418 full: bool,
4420 external: bool,
4422 show_options: ShowStatementOptions,
4424 },
4425 ShowViews {
4429 terse: bool,
4431 materialized: bool,
4433 show_options: ShowStatementOptions,
4435 },
4436 ShowCollation {
4442 filter: Option<ShowStatementFilter>,
4444 },
4445 Use(Use),
4449 StartTransaction {
4459 modes: Vec<TransactionMode>,
4461 begin: bool,
4463 transaction: Option<BeginTransactionKind>,
4465 modifier: Option<TransactionModifier>,
4467 statements: Vec<Statement>,
4476 exception: Option<Vec<ExceptionWhen>>,
4490 has_end_keyword: bool,
4492 },
4493 Comment {
4499 object_type: CommentObject,
4501 object_name: ObjectName,
4503 arguments: Option<Vec<DataType>>,
4508 operator_args: Option<CommentOperatorArgs>,
4513 table_name: Option<ObjectName>,
4520 on_domain: bool,
4523 comment: Option<String>,
4525 if_exists: bool,
4528 },
4529 Commit {
4539 chain: bool,
4541 end: bool,
4543 modifier: Option<TransactionModifier>,
4545 },
4546 Rollback {
4550 chain: bool,
4552 savepoint: Option<Ident>,
4554 },
4555 CreateSchema {
4559 schema_name: SchemaName,
4561 if_not_exists: bool,
4563 with: Option<Vec<SqlOption>>,
4571 options: Option<Vec<SqlOption>>,
4579 default_collate_spec: Option<Expr>,
4587 clone: Option<ObjectName>,
4595 },
4596 CreateDatabase {
4602 db_name: ObjectName,
4604 if_not_exists: bool,
4606 location: Option<String>,
4608 managed_location: Option<String>,
4610 or_replace: bool,
4612 transient: bool,
4614 clone: Option<ObjectName>,
4616 data_retention_time_in_days: Option<u64>,
4618 max_data_extension_time_in_days: Option<u64>,
4620 external_volume: Option<String>,
4622 catalog: Option<String>,
4624 replace_invalid_characters: Option<bool>,
4626 default_ddl_collation: Option<String>,
4628 storage_serialization_policy: Option<StorageSerializationPolicy>,
4630 comment: Option<String>,
4632 default_charset: Option<String>,
4634 default_collation: Option<String>,
4636 catalog_sync: Option<String>,
4638 catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
4640 catalog_sync_namespace_flatten_delimiter: Option<String>,
4642 with_tags: Option<Vec<Tag>>,
4644 with_contacts: Option<Vec<ContactEntry>>,
4646 },
4647 CreateFunction(CreateFunction),
4657 CreateTrigger(CreateTrigger),
4659 DropTrigger(DropTrigger),
4661 CreateProcedure {
4665 or_alter: bool,
4667 name: ObjectName,
4669 params: Option<Vec<ProcedureParam>>,
4671 language: Option<Ident>,
4673 body: ConditionalStatements,
4675 },
4676 CreateMacro {
4683 or_replace: bool,
4685 temporary: bool,
4687 name: ObjectName,
4689 args: Option<Vec<MacroArg>>,
4691 definition: MacroDefinition,
4693 },
4694 CreateStage {
4699 or_replace: bool,
4701 temporary: bool,
4703 if_not_exists: bool,
4705 name: ObjectName,
4707 stage_params: StageParamsObject,
4709 directory_table_params: KeyValueOptions,
4711 file_format: KeyValueOptions,
4713 copy_options: KeyValueOptions,
4715 comment: Option<String>,
4717 },
4718 Assert {
4722 condition: Expr,
4724 message: Option<Expr>,
4726 },
4727 Grant(Grant),
4731 Deny(DenyStatement),
4735 Revoke(Revoke),
4739 Deallocate {
4745 name: Ident,
4747 prepare: bool,
4749 },
4750 Execute {
4759 name: Option<ObjectName>,
4761 parameters: Vec<Expr>,
4763 has_parentheses: bool,
4765 immediate: bool,
4767 into: Vec<Ident>,
4769 using: Vec<ExprWithAlias>,
4771 output: bool,
4774 default: bool,
4777 },
4778 Prepare {
4784 name: Ident,
4786 data_types: Vec<DataType>,
4788 statement: Box<Statement>,
4790 },
4791 Kill {
4798 modifier: Option<KillType>,
4800 id: u64,
4803 },
4804 ExplainTable {
4809 describe_alias: DescribeAlias,
4811 hive_format: Option<HiveDescribeFormat>,
4813 has_table_keyword: bool,
4818 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4820 table_name: ObjectName,
4821 },
4822 Explain {
4826 describe_alias: DescribeAlias,
4828 analyze: bool,
4830 verbose: bool,
4832 query_plan: bool,
4837 estimate: bool,
4840 statement: Box<Statement>,
4842 format: Option<AnalyzeFormatKind>,
4844 options: Option<Vec<UtilityOption>>,
4846 },
4847 Savepoint {
4852 name: Ident,
4854 },
4855 ReleaseSavepoint {
4859 name: Ident,
4861 },
4862 Merge(Merge),
4871 Cache {
4879 table_flag: Option<ObjectName>,
4881 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4883 table_name: ObjectName,
4884 has_as: bool,
4886 options: Vec<SqlOption>,
4888 query: Option<Box<Query>>,
4890 },
4891 UNCache {
4895 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4897 table_name: ObjectName,
4898 if_exists: bool,
4900 },
4901 CreateSequence {
4906 temporary: bool,
4908 if_not_exists: bool,
4910 name: ObjectName,
4912 data_type: Option<DataType>,
4914 sequence_options: Vec<SequenceOptions>,
4916 owned_by: Option<ObjectName>,
4918 },
4919 CreateDomain(CreateDomain),
4921 CreateType {
4925 name: ObjectName,
4927 representation: Option<UserDefinedTypeRepresentation>,
4929 },
4930 Pragma {
4934 name: ObjectName,
4936 value: Option<ValueWithSpan>,
4938 is_eq: bool,
4940 },
4941 Lock(Lock),
4947 LockTables {
4952 tables: Vec<LockTable>,
4954 },
4955 UnlockTables,
4960 Unload {
4972 query: Option<Box<Query>>,
4974 query_text: Option<String>,
4976 to: Ident,
4978 auth: Option<IamRoleKind>,
4980 with: Vec<SqlOption>,
4982 options: Vec<CopyLegacyOption>,
4984 },
4985 OptimizeTable {
4997 name: ObjectName,
4999 has_table_keyword: bool,
5001 on_cluster: Option<Ident>,
5004 partition: Option<Partition>,
5007 include_final: bool,
5010 deduplicate: Option<Deduplicate>,
5013 predicate: Option<Expr>,
5016 zorder: Option<Vec<Expr>>,
5019 },
5020 LISTEN {
5027 channel: Ident,
5029 },
5030 UNLISTEN {
5037 channel: Ident,
5039 },
5040 NOTIFY {
5047 channel: Ident,
5049 payload: Option<String>,
5051 },
5052 LoadData {
5061 local: bool,
5063 inpath: String,
5065 overwrite: bool,
5067 table_name: ObjectName,
5069 partitioned: Option<Vec<Expr>>,
5071 table_format: Option<HiveLoadDataFormat>,
5073 },
5074 RenameTable(Vec<RenameTable>),
5081 List(FileStagingCommand),
5084 Remove(FileStagingCommand),
5087 RaisError {
5094 message: Box<Expr>,
5096 severity: Box<Expr>,
5098 state: Box<Expr>,
5100 arguments: Vec<Expr>,
5102 options: Vec<RaisErrorOption>,
5104 },
5105 Throw(ThrowStatement),
5107 Print(PrintStatement),
5113 WaitFor(WaitForStatement),
5117 Return(ReturnStatement),
5123 ExportData(ExportData),
5132 CreateUser(CreateUser),
5137 AlterUser(AlterUser),
5142 Vacuum(VacuumStatement),
5149 Reset(ResetStatement),
5157}
5158
5159impl From<Analyze> for Statement {
5160 fn from(analyze: Analyze) -> Self {
5161 Statement::Analyze(analyze)
5162 }
5163}
5164
5165impl From<ddl::Truncate> for Statement {
5166 fn from(truncate: ddl::Truncate) -> Self {
5167 Statement::Truncate(truncate)
5168 }
5169}
5170
5171impl From<Lock> for Statement {
5172 fn from(lock: Lock) -> Self {
5173 Statement::Lock(lock)
5174 }
5175}
5176
5177impl From<ddl::Msck> for Statement {
5178 fn from(msck: ddl::Msck) -> Self {
5179 Statement::Msck(msck)
5180 }
5181}
5182
5183#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5189#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5190#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5191pub enum CurrentGrantsKind {
5192 CopyCurrentGrants,
5194 RevokeCurrentGrants,
5196}
5197
5198impl fmt::Display for CurrentGrantsKind {
5199 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5200 match self {
5201 CurrentGrantsKind::CopyCurrentGrants => write!(f, "COPY CURRENT GRANTS"),
5202 CurrentGrantsKind::RevokeCurrentGrants => write!(f, "REVOKE CURRENT GRANTS"),
5203 }
5204 }
5205}
5206
5207#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5208#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5209#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5210pub enum RaisErrorOption {
5213 Log,
5215 NoWait,
5217 SetError,
5219}
5220
5221impl fmt::Display for RaisErrorOption {
5222 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5223 match self {
5224 RaisErrorOption::Log => write!(f, "LOG"),
5225 RaisErrorOption::NoWait => write!(f, "NOWAIT"),
5226 RaisErrorOption::SetError => write!(f, "SETERROR"),
5227 }
5228 }
5229}
5230
5231impl fmt::Display for Statement {
5232 #[allow(clippy::cognitive_complexity)]
5257 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5258 match self {
5259 Statement::Flush {
5260 object_type,
5261 location,
5262 channel,
5263 read_lock,
5264 export,
5265 tables,
5266 } => {
5267 write!(f, "FLUSH")?;
5268 if let Some(location) = location {
5269 f.write_str(" ")?;
5270 location.fmt(f)?;
5271 }
5272 write!(f, " {object_type}")?;
5273
5274 if let Some(channel) = channel {
5275 write!(f, " FOR CHANNEL {channel}")?;
5276 }
5277
5278 write!(
5279 f,
5280 "{tables}{read}{export}",
5281 tables = if !tables.is_empty() {
5282 format!(" {}", display_comma_separated(tables))
5283 } else {
5284 String::new()
5285 },
5286 export = if *export { " FOR EXPORT" } else { "" },
5287 read = if *read_lock { " WITH READ LOCK" } else { "" }
5288 )
5289 }
5290 Statement::Kill { modifier, id } => {
5291 write!(f, "KILL ")?;
5292
5293 if let Some(m) = modifier {
5294 write!(f, "{m} ")?;
5295 }
5296
5297 write!(f, "{id}")
5298 }
5299 Statement::ExplainTable {
5300 describe_alias,
5301 hive_format,
5302 has_table_keyword,
5303 table_name,
5304 } => {
5305 write!(f, "{describe_alias} ")?;
5306
5307 if let Some(format) = hive_format {
5308 write!(f, "{format} ")?;
5309 }
5310 if *has_table_keyword {
5311 write!(f, "TABLE ")?;
5312 }
5313
5314 write!(f, "{table_name}")
5315 }
5316 Statement::Explain {
5317 describe_alias,
5318 verbose,
5319 analyze,
5320 query_plan,
5321 estimate,
5322 statement,
5323 format,
5324 options,
5325 } => {
5326 write!(f, "{describe_alias} ")?;
5327
5328 if *query_plan {
5329 write!(f, "QUERY PLAN ")?;
5330 }
5331 if *analyze {
5332 write!(f, "ANALYZE ")?;
5333 }
5334 if *estimate {
5335 write!(f, "ESTIMATE ")?;
5336 }
5337
5338 if *verbose {
5339 write!(f, "VERBOSE ")?;
5340 }
5341
5342 if let Some(format) = format {
5343 write!(f, "{format} ")?;
5344 }
5345
5346 if let Some(options) = options {
5347 write!(f, "({}) ", display_comma_separated(options))?;
5348 }
5349
5350 write!(f, "{statement}")
5351 }
5352 Statement::Query(s) => s.fmt(f),
5353 Statement::Declare { stmts } => {
5354 write!(f, "DECLARE ")?;
5355 write!(f, "{}", display_separated(stmts, "; "))
5356 }
5357 Statement::Fetch {
5358 name,
5359 direction,
5360 position,
5361 into,
5362 } => {
5363 write!(f, "FETCH {direction} {position} {name}")?;
5364
5365 if let Some(into) = into {
5366 write!(f, " INTO {into}")?;
5367 }
5368
5369 Ok(())
5370 }
5371 Statement::Directory {
5372 overwrite,
5373 local,
5374 path,
5375 file_format,
5376 source,
5377 } => {
5378 write!(
5379 f,
5380 "INSERT{overwrite}{local} DIRECTORY '{path}'",
5381 overwrite = if *overwrite { " OVERWRITE" } else { "" },
5382 local = if *local { " LOCAL" } else { "" },
5383 path = path
5384 )?;
5385 if let Some(ref ff) = file_format {
5386 write!(f, " STORED AS {ff}")?
5387 }
5388 write!(f, " {source}")
5389 }
5390 Statement::Msck(msck) => msck.fmt(f),
5391 Statement::Truncate(truncate) => truncate.fmt(f),
5392 Statement::Case(stmt) => {
5393 write!(f, "{stmt}")
5394 }
5395 Statement::If(stmt) => {
5396 write!(f, "{stmt}")
5397 }
5398 Statement::While(stmt) => {
5399 write!(f, "{stmt}")
5400 }
5401 Statement::Raise(stmt) => {
5402 write!(f, "{stmt}")
5403 }
5404 Statement::AttachDatabase {
5405 schema_name,
5406 database_file_name,
5407 database,
5408 } => {
5409 let keyword = if *database { "DATABASE " } else { "" };
5410 write!(f, "ATTACH {keyword}{database_file_name} AS {schema_name}")
5411 }
5412 Statement::AttachDuckDBDatabase {
5413 if_not_exists,
5414 database,
5415 database_path,
5416 database_alias,
5417 attach_options,
5418 } => {
5419 write!(
5420 f,
5421 "ATTACH{database}{if_not_exists} {database_path}",
5422 database = if *database { " DATABASE" } else { "" },
5423 if_not_exists = if *if_not_exists { " IF NOT EXISTS" } else { "" },
5424 )?;
5425 if let Some(alias) = database_alias {
5426 write!(f, " AS {alias}")?;
5427 }
5428 if !attach_options.is_empty() {
5429 write!(f, " ({})", display_comma_separated(attach_options))?;
5430 }
5431 Ok(())
5432 }
5433 Statement::DetachDuckDBDatabase {
5434 if_exists,
5435 database,
5436 database_alias,
5437 } => {
5438 write!(
5439 f,
5440 "DETACH{database}{if_exists} {database_alias}",
5441 database = if *database { " DATABASE" } else { "" },
5442 if_exists = if *if_exists { " IF EXISTS" } else { "" },
5443 )?;
5444 Ok(())
5445 }
5446 Statement::Analyze(analyze) => analyze.fmt(f),
5447 Statement::Insert(insert) => insert.fmt(f),
5448 Statement::Install {
5449 extension_name: name,
5450 } => write!(f, "INSTALL {name}"),
5451
5452 Statement::Load {
5453 extension_name: name,
5454 } => write!(f, "LOAD {name}"),
5455
5456 Statement::Call(function) => write!(f, "CALL {function}"),
5457
5458 Statement::Copy {
5459 source,
5460 to,
5461 target,
5462 options,
5463 legacy_options,
5464 values,
5465 } => {
5466 write!(f, "COPY")?;
5467 match source {
5468 CopySource::Query(query) => write!(f, " ({query})")?,
5469 CopySource::Table {
5470 table_name,
5471 columns,
5472 } => {
5473 write!(f, " {table_name}")?;
5474 if !columns.is_empty() {
5475 write!(f, " ({})", display_comma_separated(columns))?;
5476 }
5477 }
5478 }
5479 write!(f, " {} {}", if *to { "TO" } else { "FROM" }, target)?;
5480 if !options.is_empty() {
5481 write!(f, " ({})", display_comma_separated(options))?;
5482 }
5483 if !legacy_options.is_empty() {
5484 write!(f, " {}", display_separated(legacy_options, " "))?;
5485 }
5486 if !values.is_empty() {
5487 writeln!(f, ";")?;
5488 let mut delim = "";
5489 for v in values {
5490 write!(f, "{delim}")?;
5491 delim = "\t";
5492 if let Some(v) = v {
5493 write!(f, "{v}")?;
5494 } else {
5495 write!(f, "\\N")?;
5496 }
5497 }
5498 write!(f, "\n\\.")?;
5499 }
5500 Ok(())
5501 }
5502 Statement::Update(update) => update.fmt(f),
5503 Statement::Delete(delete) => delete.fmt(f),
5504 Statement::Open(open) => open.fmt(f),
5505 Statement::Close { cursor } => {
5506 write!(f, "CLOSE {cursor}")?;
5507
5508 Ok(())
5509 }
5510 Statement::CreateDatabase {
5511 db_name,
5512 if_not_exists,
5513 location,
5514 managed_location,
5515 or_replace,
5516 transient,
5517 clone,
5518 data_retention_time_in_days,
5519 max_data_extension_time_in_days,
5520 external_volume,
5521 catalog,
5522 replace_invalid_characters,
5523 default_ddl_collation,
5524 storage_serialization_policy,
5525 comment,
5526 default_charset,
5527 default_collation,
5528 catalog_sync,
5529 catalog_sync_namespace_mode,
5530 catalog_sync_namespace_flatten_delimiter,
5531 with_tags,
5532 with_contacts,
5533 } => {
5534 write!(
5535 f,
5536 "CREATE {or_replace}{transient}DATABASE {if_not_exists}{name}",
5537 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5538 transient = if *transient { "TRANSIENT " } else { "" },
5539 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5540 name = db_name,
5541 )?;
5542
5543 if let Some(l) = location {
5544 write!(f, " LOCATION '{l}'")?;
5545 }
5546 if let Some(ml) = managed_location {
5547 write!(f, " MANAGEDLOCATION '{ml}'")?;
5548 }
5549 if let Some(clone) = clone {
5550 write!(f, " CLONE {clone}")?;
5551 }
5552
5553 if let Some(value) = data_retention_time_in_days {
5554 write!(f, " DATA_RETENTION_TIME_IN_DAYS = {value}")?;
5555 }
5556
5557 if let Some(value) = max_data_extension_time_in_days {
5558 write!(f, " MAX_DATA_EXTENSION_TIME_IN_DAYS = {value}")?;
5559 }
5560
5561 if let Some(vol) = external_volume {
5562 write!(f, " EXTERNAL_VOLUME = '{vol}'")?;
5563 }
5564
5565 if let Some(cat) = catalog {
5566 write!(f, " CATALOG = '{cat}'")?;
5567 }
5568
5569 if let Some(true) = replace_invalid_characters {
5570 write!(f, " REPLACE_INVALID_CHARACTERS = TRUE")?;
5571 } else if let Some(false) = replace_invalid_characters {
5572 write!(f, " REPLACE_INVALID_CHARACTERS = FALSE")?;
5573 }
5574
5575 if let Some(collation) = default_ddl_collation {
5576 write!(f, " DEFAULT_DDL_COLLATION = '{collation}'")?;
5577 }
5578
5579 if let Some(policy) = storage_serialization_policy {
5580 write!(f, " STORAGE_SERIALIZATION_POLICY = {policy}")?;
5581 }
5582
5583 if let Some(comment) = comment {
5584 write!(f, " COMMENT = '{comment}'")?;
5585 }
5586
5587 if let Some(charset) = default_charset {
5588 write!(f, " DEFAULT CHARACTER SET {charset}")?;
5589 }
5590
5591 if let Some(collation) = default_collation {
5592 write!(f, " DEFAULT COLLATE {collation}")?;
5593 }
5594
5595 if let Some(sync) = catalog_sync {
5596 write!(f, " CATALOG_SYNC = '{sync}'")?;
5597 }
5598
5599 if let Some(mode) = catalog_sync_namespace_mode {
5600 write!(f, " CATALOG_SYNC_NAMESPACE_MODE = {mode}")?;
5601 }
5602
5603 if let Some(delim) = catalog_sync_namespace_flatten_delimiter {
5604 write!(f, " CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '{delim}'")?;
5605 }
5606
5607 if let Some(tags) = with_tags {
5608 write!(f, " WITH TAG ({})", display_comma_separated(tags))?;
5609 }
5610
5611 if let Some(contacts) = with_contacts {
5612 write!(f, " WITH CONTACT ({})", display_comma_separated(contacts))?;
5613 }
5614 Ok(())
5615 }
5616 Statement::CreateFunction(create_function) => create_function.fmt(f),
5617 Statement::CreateDomain(create_domain) => create_domain.fmt(f),
5618 Statement::CreateTrigger(create_trigger) => create_trigger.fmt(f),
5619 Statement::DropTrigger(drop_trigger) => drop_trigger.fmt(f),
5620 Statement::CreateProcedure {
5621 name,
5622 or_alter,
5623 params,
5624 language,
5625 body,
5626 } => {
5627 write!(
5628 f,
5629 "CREATE {or_alter}PROCEDURE {name}",
5630 or_alter = if *or_alter { "OR ALTER " } else { "" },
5631 name = name
5632 )?;
5633
5634 if let Some(p) = params {
5635 if !p.is_empty() {
5636 write!(f, " ({})", display_comma_separated(p))?;
5637 }
5638 }
5639
5640 if let Some(language) = language {
5641 write!(f, " LANGUAGE {language}")?;
5642 }
5643
5644 write!(f, " AS {body}")
5645 }
5646 Statement::CreateMacro {
5647 or_replace,
5648 temporary,
5649 name,
5650 args,
5651 definition,
5652 } => {
5653 write!(
5654 f,
5655 "CREATE {or_replace}{temp}MACRO {name}",
5656 temp = if *temporary { "TEMPORARY " } else { "" },
5657 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5658 )?;
5659 if let Some(args) = args {
5660 write!(f, "({})", display_comma_separated(args))?;
5661 }
5662 match definition {
5663 MacroDefinition::Expr(expr) => write!(f, " AS {expr}")?,
5664 MacroDefinition::Table(query) => write!(f, " AS TABLE {query}")?,
5665 }
5666 Ok(())
5667 }
5668 Statement::CreateView(create_view) => create_view.fmt(f),
5669 Statement::CreateTable(create_table) => create_table.fmt(f),
5670 Statement::LoadData {
5671 local,
5672 inpath,
5673 overwrite,
5674 table_name,
5675 partitioned,
5676 table_format,
5677 } => {
5678 write!(
5679 f,
5680 "LOAD DATA {local}INPATH '{inpath}' {overwrite}INTO TABLE {table_name}",
5681 local = if *local { "LOCAL " } else { "" },
5682 inpath = inpath,
5683 overwrite = if *overwrite { "OVERWRITE " } else { "" },
5684 table_name = table_name,
5685 )?;
5686 if let Some(ref parts) = &partitioned {
5687 if !parts.is_empty() {
5688 write!(f, " PARTITION ({})", display_comma_separated(parts))?;
5689 }
5690 }
5691 if let Some(HiveLoadDataFormat {
5692 serde,
5693 input_format,
5694 }) = &table_format
5695 {
5696 write!(f, " INPUTFORMAT {input_format} SERDE {serde}")?;
5697 }
5698 Ok(())
5699 }
5700 Statement::CreateVirtualTable {
5701 name,
5702 if_not_exists,
5703 module_name,
5704 module_args,
5705 } => {
5706 write!(
5707 f,
5708 "CREATE VIRTUAL TABLE {if_not_exists}{name} USING {module_name}",
5709 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5710 name = name,
5711 module_name = module_name
5712 )?;
5713 if !module_args.is_empty() {
5714 write!(f, " ({})", display_comma_separated(module_args))?;
5715 }
5716 Ok(())
5717 }
5718 Statement::CreateIndex(create_index) => create_index.fmt(f),
5719 Statement::CreateExtension(create_extension) => write!(f, "{create_extension}"),
5720 Statement::CreateCollation(create_collation) => write!(f, "{create_collation}"),
5721 Statement::CreateTextSearchConfiguration(v) => write!(f, "{v}"),
5722 Statement::CreateTextSearchDictionary(v) => write!(f, "{v}"),
5723 Statement::CreateTextSearchParser(v) => write!(f, "{v}"),
5724 Statement::CreateTextSearchTemplate(v) => write!(f, "{v}"),
5725 Statement::CreatePublication(v) => write!(f, "{v}"),
5726 Statement::CreateSubscription(v) => write!(f, "{v}"),
5727 Statement::CreateCast(v) => write!(f, "{v}"),
5728 Statement::CreateConversion(v) => write!(f, "{v}"),
5729 Statement::CreateLanguage(v) => write!(f, "{v}"),
5730 Statement::CreateRule(v) => write!(f, "{v}"),
5731 Statement::CreateStatistics(v) => write!(f, "{v}"),
5732 Statement::CreateAccessMethod(v) => write!(f, "{v}"),
5733 Statement::CreateEventTrigger(v) => write!(f, "{v}"),
5734 Statement::CreateTransform(v) => write!(f, "{v}"),
5735 Statement::SecurityLabel(v) => write!(f, "{v}"),
5736 Statement::CreateUserMapping(v) => write!(f, "{v}"),
5737 Statement::CreateTablespace(v) => write!(f, "{v}"),
5738 Statement::DropExtension(drop_extension) => write!(f, "{drop_extension}"),
5739 Statement::DropOperator(drop_operator) => write!(f, "{drop_operator}"),
5740 Statement::DropOperatorFamily(drop_operator_family) => {
5741 write!(f, "{drop_operator_family}")
5742 }
5743 Statement::DropOperatorClass(drop_operator_class) => {
5744 write!(f, "{drop_operator_class}")
5745 }
5746 Statement::CreateRole(create_role) => write!(f, "{create_role}"),
5747 Statement::CreateSecret {
5748 or_replace,
5749 temporary,
5750 if_not_exists,
5751 name,
5752 storage_specifier,
5753 secret_type,
5754 options,
5755 } => {
5756 write!(
5757 f,
5758 "CREATE {or_replace}",
5759 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5760 )?;
5761 if let Some(t) = temporary {
5762 write!(f, "{}", if *t { "TEMPORARY " } else { "PERSISTENT " })?;
5763 }
5764 write!(
5765 f,
5766 "SECRET {if_not_exists}",
5767 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5768 )?;
5769 if let Some(n) = name {
5770 write!(f, "{n} ")?;
5771 };
5772 if let Some(s) = storage_specifier {
5773 write!(f, "IN {s} ")?;
5774 }
5775 write!(f, "( TYPE {secret_type}",)?;
5776 if !options.is_empty() {
5777 write!(f, ", {o}", o = display_comma_separated(options))?;
5778 }
5779 write!(f, " )")?;
5780 Ok(())
5781 }
5782 Statement::CreateServer(stmt) => {
5783 write!(f, "{stmt}")
5784 }
5785 Statement::CreateForeignDataWrapper(stmt) => write!(f, "{stmt}"),
5786 Statement::CreateForeignTable(stmt) => write!(f, "{stmt}"),
5787 Statement::CreatePolicy(policy) => write!(f, "{policy}"),
5788 Statement::CreateConnector(create_connector) => create_connector.fmt(f),
5789 Statement::CreateOperator(create_operator) => create_operator.fmt(f),
5790 Statement::CreateOperatorFamily(create_operator_family) => {
5791 create_operator_family.fmt(f)
5792 }
5793 Statement::CreateOperatorClass(create_operator_class) => create_operator_class.fmt(f),
5794 Statement::CreateAggregate(create_aggregate) => create_aggregate.fmt(f),
5795 Statement::AlterTable(alter_table) => write!(f, "{alter_table}"),
5796 Statement::AlterIndex { name, operation } => {
5797 write!(f, "ALTER INDEX {name} {operation}")
5798 }
5799 Statement::AlterView {
5800 name,
5801 columns,
5802 query,
5803 with_options,
5804 } => {
5805 write!(f, "ALTER VIEW {name}")?;
5806 if !with_options.is_empty() {
5807 write!(f, " WITH ({})", display_comma_separated(with_options))?;
5808 }
5809 if !columns.is_empty() {
5810 write!(f, " ({})", display_comma_separated(columns))?;
5811 }
5812 write!(f, " AS {query}")
5813 }
5814 Statement::AlterDomain(alter_domain) => write!(f, "{alter_domain}"),
5815 Statement::AlterExtension(alter_extension) => write!(f, "{alter_extension}"),
5816 Statement::AlterFunction(alter_function) => write!(f, "{alter_function}"),
5817 Statement::AlterTrigger(alter_trigger) => write!(f, "{alter_trigger}"),
5818 Statement::AlterType(AlterType { name, operation }) => {
5819 write!(f, "ALTER TYPE {name} {operation}")
5820 }
5821 Statement::AlterCollation(alter_collation) => write!(f, "{alter_collation}"),
5822 Statement::AlterDefaultPrivileges(alter_default_privileges) => {
5823 write!(f, "{alter_default_privileges}")
5824 }
5825 Statement::AlterOperator(alter_operator) => write!(f, "{alter_operator}"),
5826 Statement::AlterOperatorFamily(alter_operator_family) => {
5827 write!(f, "{alter_operator_family}")
5828 }
5829 Statement::AlterOperatorClass(alter_operator_class) => {
5830 write!(f, "{alter_operator_class}")
5831 }
5832 Statement::AlterRole { name, operation } => {
5833 write!(f, "ALTER ROLE {name} {operation}")
5834 }
5835 Statement::AlterPolicy(alter_policy) => write!(f, "{alter_policy}"),
5836 Statement::AlterConnector {
5837 name,
5838 properties,
5839 url,
5840 owner,
5841 } => {
5842 write!(f, "ALTER CONNECTOR {name}")?;
5843 if let Some(properties) = properties {
5844 write!(
5845 f,
5846 " SET DCPROPERTIES({})",
5847 display_comma_separated(properties)
5848 )?;
5849 }
5850 if let Some(url) = url {
5851 write!(f, " SET URL '{url}'")?;
5852 }
5853 if let Some(owner) = owner {
5854 write!(f, " SET OWNER {owner}")?;
5855 }
5856 Ok(())
5857 }
5858 Statement::AlterSession {
5859 set,
5860 session_params,
5861 } => {
5862 write!(
5863 f,
5864 "ALTER SESSION {set}",
5865 set = if *set { "SET" } else { "UNSET" }
5866 )?;
5867 if !session_params.options.is_empty() {
5868 if *set {
5869 write!(f, " {session_params}")?;
5870 } else {
5871 let options = session_params
5872 .options
5873 .iter()
5874 .map(|p| p.option_name.clone())
5875 .collect::<Vec<_>>();
5876 write!(f, " {}", display_separated(&options, ", "))?;
5877 }
5878 }
5879 Ok(())
5880 }
5881 Statement::Drop {
5882 object_type,
5883 if_exists,
5884 names,
5885 cascade,
5886 restrict,
5887 purge,
5888 temporary,
5889 table,
5890 } => {
5891 write!(
5892 f,
5893 "DROP {}{}{} {}{}{}{}",
5894 if *temporary { "TEMPORARY " } else { "" },
5895 object_type,
5896 if *if_exists { " IF EXISTS" } else { "" },
5897 display_comma_separated(names),
5898 if *cascade { " CASCADE" } else { "" },
5899 if *restrict { " RESTRICT" } else { "" },
5900 if *purge { " PURGE" } else { "" },
5901 )?;
5902 if let Some(table_name) = table.as_ref() {
5903 write!(f, " ON {table_name}")?;
5904 };
5905 Ok(())
5906 }
5907 Statement::DropFunction(drop_function) => write!(f, "{drop_function}"),
5908 Statement::DropDomain(DropDomain {
5909 if_exists,
5910 name,
5911 drop_behavior,
5912 }) => {
5913 write!(
5914 f,
5915 "DROP DOMAIN{} {name}",
5916 if *if_exists { " IF EXISTS" } else { "" },
5917 )?;
5918 if let Some(op) = drop_behavior {
5919 write!(f, " {op}")?;
5920 }
5921 Ok(())
5922 }
5923 Statement::DropProcedure {
5924 if_exists,
5925 proc_desc,
5926 drop_behavior,
5927 } => {
5928 write!(
5929 f,
5930 "DROP PROCEDURE{} {}",
5931 if *if_exists { " IF EXISTS" } else { "" },
5932 display_comma_separated(proc_desc),
5933 )?;
5934 if let Some(op) = drop_behavior {
5935 write!(f, " {op}")?;
5936 }
5937 Ok(())
5938 }
5939 Statement::DropSecret {
5940 if_exists,
5941 temporary,
5942 name,
5943 storage_specifier,
5944 } => {
5945 write!(f, "DROP ")?;
5946 if let Some(t) = temporary {
5947 write!(f, "{}", if *t { "TEMPORARY " } else { "PERSISTENT " })?;
5948 }
5949 write!(
5950 f,
5951 "SECRET {if_exists}{name}",
5952 if_exists = if *if_exists { "IF EXISTS " } else { "" },
5953 )?;
5954 if let Some(s) = storage_specifier {
5955 write!(f, " FROM {s}")?;
5956 }
5957 Ok(())
5958 }
5959 Statement::DropPolicy(policy) => write!(f, "{policy}"),
5960 Statement::DropConnector { if_exists, name } => {
5961 write!(
5962 f,
5963 "DROP CONNECTOR {if_exists}{name}",
5964 if_exists = if *if_exists { "IF EXISTS " } else { "" }
5965 )?;
5966 Ok(())
5967 }
5968 Statement::Discard { object_type } => {
5969 write!(f, "DISCARD {object_type}")?;
5970 Ok(())
5971 }
5972 Self::Set(set) => write!(f, "{set}"),
5973 Statement::ShowVariable { variable } => {
5974 write!(f, "SHOW")?;
5975 if !variable.is_empty() {
5976 write!(f, " {}", display_separated(variable, " "))?;
5977 }
5978 Ok(())
5979 }
5980 Statement::ShowStatus {
5981 filter,
5982 global,
5983 session,
5984 } => {
5985 write!(f, "SHOW")?;
5986 if *global {
5987 write!(f, " GLOBAL")?;
5988 }
5989 if *session {
5990 write!(f, " SESSION")?;
5991 }
5992 write!(f, " STATUS")?;
5993 if filter.is_some() {
5994 write!(f, " {}", filter.as_ref().unwrap())?;
5995 }
5996 Ok(())
5997 }
5998 Statement::ShowVariables {
5999 filter,
6000 global,
6001 session,
6002 } => {
6003 write!(f, "SHOW")?;
6004 if *global {
6005 write!(f, " GLOBAL")?;
6006 }
6007 if *session {
6008 write!(f, " SESSION")?;
6009 }
6010 write!(f, " VARIABLES")?;
6011 if filter.is_some() {
6012 write!(f, " {}", filter.as_ref().unwrap())?;
6013 }
6014 Ok(())
6015 }
6016 Statement::ShowCreate { obj_type, obj_name } => {
6017 write!(f, "SHOW CREATE {obj_type} {obj_name}",)?;
6018 Ok(())
6019 }
6020 Statement::ShowColumns {
6021 extended,
6022 full,
6023 show_options,
6024 } => {
6025 write!(
6026 f,
6027 "SHOW {extended}{full}COLUMNS{show_options}",
6028 extended = if *extended { "EXTENDED " } else { "" },
6029 full = if *full { "FULL " } else { "" },
6030 )?;
6031 Ok(())
6032 }
6033 Statement::ShowDatabases {
6034 terse,
6035 history,
6036 show_options,
6037 } => {
6038 write!(
6039 f,
6040 "SHOW {terse}DATABASES{history}{show_options}",
6041 terse = if *terse { "TERSE " } else { "" },
6042 history = if *history { " HISTORY" } else { "" },
6043 )?;
6044 Ok(())
6045 }
6046 Statement::ShowCatalogs {
6047 terse,
6048 history,
6049 show_options,
6050 } => {
6051 write!(
6052 f,
6053 "SHOW {terse}CATALOGS{history}{show_options}",
6054 terse = if *terse { "TERSE " } else { "" },
6055 history = if *history { " HISTORY" } else { "" },
6056 )?;
6057 Ok(())
6058 }
6059 Statement::ShowProcessList { full } => {
6060 write!(
6061 f,
6062 "SHOW {full}PROCESSLIST",
6063 full = if *full { "FULL " } else { "" },
6064 )?;
6065 Ok(())
6066 }
6067 Statement::ShowSchemas {
6068 terse,
6069 history,
6070 show_options,
6071 } => {
6072 write!(
6073 f,
6074 "SHOW {terse}SCHEMAS{history}{show_options}",
6075 terse = if *terse { "TERSE " } else { "" },
6076 history = if *history { " HISTORY" } else { "" },
6077 )?;
6078 Ok(())
6079 }
6080 Statement::ShowObjects(ShowObjects {
6081 terse,
6082 show_options,
6083 }) => {
6084 write!(
6085 f,
6086 "SHOW {terse}OBJECTS{show_options}",
6087 terse = if *terse { "TERSE " } else { "" },
6088 )?;
6089 Ok(())
6090 }
6091 Statement::ShowTables {
6092 terse,
6093 history,
6094 extended,
6095 full,
6096 external,
6097 show_options,
6098 } => {
6099 write!(
6100 f,
6101 "SHOW {terse}{extended}{full}{external}TABLES{history}{show_options}",
6102 terse = if *terse { "TERSE " } else { "" },
6103 extended = if *extended { "EXTENDED " } else { "" },
6104 full = if *full { "FULL " } else { "" },
6105 external = if *external { "EXTERNAL " } else { "" },
6106 history = if *history { " HISTORY" } else { "" },
6107 )?;
6108 Ok(())
6109 }
6110 Statement::ShowViews {
6111 terse,
6112 materialized,
6113 show_options,
6114 } => {
6115 write!(
6116 f,
6117 "SHOW {terse}{materialized}VIEWS{show_options}",
6118 terse = if *terse { "TERSE " } else { "" },
6119 materialized = if *materialized { "MATERIALIZED " } else { "" }
6120 )?;
6121 Ok(())
6122 }
6123 Statement::ShowFunctions { filter } => {
6124 write!(f, "SHOW FUNCTIONS")?;
6125 if let Some(filter) = filter {
6126 write!(f, " {filter}")?;
6127 }
6128 Ok(())
6129 }
6130 Statement::Use(use_expr) => use_expr.fmt(f),
6131 Statement::ShowCollation { filter } => {
6132 write!(f, "SHOW COLLATION")?;
6133 if let Some(filter) = filter {
6134 write!(f, " {filter}")?;
6135 }
6136 Ok(())
6137 }
6138 Statement::ShowCharset(show_stm) => show_stm.fmt(f),
6139 Statement::StartTransaction {
6140 modes,
6141 begin: syntax_begin,
6142 transaction,
6143 modifier,
6144 statements,
6145 exception,
6146 has_end_keyword,
6147 } => {
6148 if *syntax_begin {
6149 if let Some(modifier) = *modifier {
6150 write!(f, "BEGIN {modifier}")?;
6151 } else {
6152 write!(f, "BEGIN")?;
6153 }
6154 } else {
6155 write!(f, "START")?;
6156 }
6157 if let Some(transaction) = transaction {
6158 write!(f, " {transaction}")?;
6159 }
6160 if !modes.is_empty() {
6161 write!(f, " {}", display_comma_separated(modes))?;
6162 }
6163 if !statements.is_empty() {
6164 write!(f, " ")?;
6165 format_statement_list(f, statements)?;
6166 }
6167 if let Some(exception_when) = exception {
6168 write!(f, " EXCEPTION")?;
6169 for when in exception_when {
6170 write!(f, " {when}")?;
6171 }
6172 }
6173 if *has_end_keyword {
6174 write!(f, " END")?;
6175 }
6176 Ok(())
6177 }
6178 Statement::Commit {
6179 chain,
6180 end: end_syntax,
6181 modifier,
6182 } => {
6183 if *end_syntax {
6184 write!(f, "END")?;
6185 if let Some(modifier) = *modifier {
6186 write!(f, " {modifier}")?;
6187 }
6188 if *chain {
6189 write!(f, " AND CHAIN")?;
6190 }
6191 } else {
6192 write!(f, "COMMIT{}", if *chain { " AND CHAIN" } else { "" })?;
6193 }
6194 Ok(())
6195 }
6196 Statement::Rollback { chain, savepoint } => {
6197 write!(f, "ROLLBACK")?;
6198
6199 if *chain {
6200 write!(f, " AND CHAIN")?;
6201 }
6202
6203 if let Some(savepoint) = savepoint {
6204 write!(f, " TO SAVEPOINT {savepoint}")?;
6205 }
6206
6207 Ok(())
6208 }
6209 Statement::CreateSchema {
6210 schema_name,
6211 if_not_exists,
6212 with,
6213 options,
6214 default_collate_spec,
6215 clone,
6216 } => {
6217 write!(
6218 f,
6219 "CREATE SCHEMA {if_not_exists}{name}",
6220 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
6221 name = schema_name
6222 )?;
6223
6224 if let Some(collate) = default_collate_spec {
6225 write!(f, " DEFAULT COLLATE {collate}")?;
6226 }
6227
6228 if let Some(with) = with {
6229 write!(f, " WITH ({})", display_comma_separated(with))?;
6230 }
6231
6232 if let Some(options) = options {
6233 write!(f, " OPTIONS({})", display_comma_separated(options))?;
6234 }
6235
6236 if let Some(clone) = clone {
6237 write!(f, " CLONE {clone}")?;
6238 }
6239 Ok(())
6240 }
6241 Statement::Assert { condition, message } => {
6242 write!(f, "ASSERT {condition}")?;
6243 if let Some(m) = message {
6244 write!(f, " AS {m}")?;
6245 }
6246 Ok(())
6247 }
6248 Statement::Grant(grant) => write!(f, "{grant}"),
6249 Statement::Deny(s) => write!(f, "{s}"),
6250 Statement::Revoke(revoke) => write!(f, "{revoke}"),
6251 Statement::Deallocate { name, prepare } => write!(
6252 f,
6253 "DEALLOCATE {prepare}{name}",
6254 prepare = if *prepare { "PREPARE " } else { "" },
6255 name = name,
6256 ),
6257 Statement::Execute {
6258 name,
6259 parameters,
6260 has_parentheses,
6261 immediate,
6262 into,
6263 using,
6264 output,
6265 default,
6266 } => {
6267 let (open, close) = if *has_parentheses {
6268 (if name.is_some() { "(" } else { " (" }, ")")
6270 } else {
6271 (if parameters.is_empty() { "" } else { " " }, "")
6272 };
6273 write!(f, "EXECUTE")?;
6274 if *immediate {
6275 write!(f, " IMMEDIATE")?;
6276 }
6277 if let Some(name) = name {
6278 write!(f, " {name}")?;
6279 }
6280 write!(f, "{open}{}{close}", display_comma_separated(parameters),)?;
6281 if !into.is_empty() {
6282 write!(f, " INTO {}", display_comma_separated(into))?;
6283 }
6284 if !using.is_empty() {
6285 write!(f, " USING {}", display_comma_separated(using))?;
6286 };
6287 if *output {
6288 write!(f, " OUTPUT")?;
6289 }
6290 if *default {
6291 write!(f, " DEFAULT")?;
6292 }
6293 Ok(())
6294 }
6295 Statement::Prepare {
6296 name,
6297 data_types,
6298 statement,
6299 } => {
6300 write!(f, "PREPARE {name} ")?;
6301 if !data_types.is_empty() {
6302 write!(f, "({}) ", display_comma_separated(data_types))?;
6303 }
6304 write!(f, "AS {statement}")
6305 }
6306 Statement::Comment {
6307 object_type,
6308 object_name,
6309 arguments,
6310 operator_args,
6311 table_name,
6312 on_domain,
6313 comment,
6314 if_exists,
6315 } => {
6316 write!(f, "COMMENT ")?;
6317 if *if_exists {
6318 write!(f, "IF EXISTS ")?;
6319 }
6320 write!(f, "ON {object_type} {object_name}")?;
6321 if let Some(args) = arguments {
6322 write!(f, "({})", display_comma_separated(args))?;
6323 }
6324 if let Some(operator_args) = operator_args {
6325 write!(f, "{operator_args}")?;
6326 }
6327 if let Some(table_name) = table_name {
6328 let prefix = if *on_domain { " ON DOMAIN " } else { " ON " };
6329 write!(f, "{prefix}{table_name}")?;
6330 }
6331 write!(f, " IS ")?;
6332 if let Some(c) = comment {
6333 write!(f, "'{}'", value::escape_single_quote_string(c))
6334 } else {
6335 write!(f, "NULL")
6336 }
6337 }
6338 Statement::Savepoint { name } => {
6339 write!(f, "SAVEPOINT ")?;
6340 write!(f, "{name}")
6341 }
6342 Statement::ReleaseSavepoint { name } => {
6343 write!(f, "RELEASE SAVEPOINT {name}")
6344 }
6345 Statement::Merge(merge) => merge.fmt(f),
6346 Statement::Cache {
6347 table_name,
6348 table_flag,
6349 has_as,
6350 options,
6351 query,
6352 } => {
6353 if let Some(table_flag) = table_flag {
6354 write!(f, "CACHE {table_flag} TABLE {table_name}")?;
6355 } else {
6356 write!(f, "CACHE TABLE {table_name}")?;
6357 }
6358
6359 if !options.is_empty() {
6360 write!(f, " OPTIONS({})", display_comma_separated(options))?;
6361 }
6362
6363 match (*has_as, query) {
6364 (true, Some(query)) => write!(f, " AS {query}"),
6365 (true, None) => f.write_str(" AS"),
6366 (false, Some(query)) => write!(f, " {query}"),
6367 (false, None) => Ok(()),
6368 }
6369 }
6370 Statement::UNCache {
6371 table_name,
6372 if_exists,
6373 } => {
6374 if *if_exists {
6375 write!(f, "UNCACHE TABLE IF EXISTS {table_name}")
6376 } else {
6377 write!(f, "UNCACHE TABLE {table_name}")
6378 }
6379 }
6380 Statement::CreateSequence {
6381 temporary,
6382 if_not_exists,
6383 name,
6384 data_type,
6385 sequence_options,
6386 owned_by,
6387 } => {
6388 let as_type: String = if let Some(dt) = data_type.as_ref() {
6389 [" AS ", &dt.to_string()].concat()
6392 } else {
6393 "".to_string()
6394 };
6395 write!(
6396 f,
6397 "CREATE {temporary}SEQUENCE {if_not_exists}{name}{as_type}",
6398 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
6399 temporary = if *temporary { "TEMPORARY " } else { "" },
6400 name = name,
6401 as_type = as_type
6402 )?;
6403 for sequence_option in sequence_options {
6404 write!(f, "{sequence_option}")?;
6405 }
6406 if let Some(ob) = owned_by.as_ref() {
6407 write!(f, " OWNED BY {ob}")?;
6408 }
6409 write!(f, "")
6410 }
6411 Statement::CreateStage {
6412 or_replace,
6413 temporary,
6414 if_not_exists,
6415 name,
6416 stage_params,
6417 directory_table_params,
6418 file_format,
6419 copy_options,
6420 comment,
6421 ..
6422 } => {
6423 write!(
6424 f,
6425 "CREATE {or_replace}{temp}STAGE {if_not_exists}{name}{stage_params}",
6426 temp = if *temporary { "TEMPORARY " } else { "" },
6427 or_replace = if *or_replace { "OR REPLACE " } else { "" },
6428 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
6429 )?;
6430 if !directory_table_params.options.is_empty() {
6431 write!(f, " DIRECTORY=({directory_table_params})")?;
6432 }
6433 if !file_format.options.is_empty() {
6434 write!(f, " FILE_FORMAT=({file_format})")?;
6435 }
6436 if !copy_options.options.is_empty() {
6437 write!(f, " COPY_OPTIONS=({copy_options})")?;
6438 }
6439 if comment.is_some() {
6440 write!(f, " COMMENT='{}'", comment.as_ref().unwrap())?;
6441 }
6442 Ok(())
6443 }
6444 Statement::CopyIntoSnowflake {
6445 kind,
6446 into,
6447 into_columns,
6448 from_obj,
6449 from_obj_alias,
6450 stage_params,
6451 from_transformations,
6452 from_query,
6453 files,
6454 pattern,
6455 file_format,
6456 copy_options,
6457 validation_mode,
6458 partition,
6459 } => {
6460 write!(f, "COPY INTO {into}")?;
6461 if let Some(into_columns) = into_columns {
6462 write!(f, " ({})", display_comma_separated(into_columns))?;
6463 }
6464 if let Some(from_transformations) = from_transformations {
6465 if let Some(from_stage) = from_obj {
6467 write!(
6468 f,
6469 " FROM (SELECT {} FROM {}{}",
6470 display_separated(from_transformations, ", "),
6471 from_stage,
6472 stage_params
6473 )?;
6474 }
6475 if let Some(from_obj_alias) = from_obj_alias {
6476 write!(f, " AS {from_obj_alias}")?;
6477 }
6478 write!(f, ")")?;
6479 } else if let Some(from_obj) = from_obj {
6480 write!(f, " FROM {from_obj}{stage_params}")?;
6482 if let Some(from_obj_alias) = from_obj_alias {
6483 write!(f, " AS {from_obj_alias}")?;
6484 }
6485 } else if let Some(from_query) = from_query {
6486 write!(f, " FROM ({from_query})")?;
6488 }
6489
6490 if let Some(files) = files {
6491 write!(f, " FILES = ('{}')", display_separated(files, "', '"))?;
6492 }
6493 if let Some(pattern) = pattern {
6494 write!(f, " PATTERN = '{pattern}'")?;
6495 }
6496 if let Some(partition) = partition {
6497 write!(f, " PARTITION BY {partition}")?;
6498 }
6499 if !file_format.options.is_empty() {
6500 write!(f, " FILE_FORMAT=({file_format})")?;
6501 }
6502 if !copy_options.options.is_empty() {
6503 match kind {
6504 CopyIntoSnowflakeKind::Table => {
6505 write!(f, " COPY_OPTIONS=({copy_options})")?
6506 }
6507 CopyIntoSnowflakeKind::Location => write!(f, " {copy_options}")?,
6508 }
6509 }
6510 if let Some(validation_mode) = validation_mode {
6511 write!(f, " VALIDATION_MODE = {validation_mode}")?;
6512 }
6513 Ok(())
6514 }
6515 Statement::CreateType {
6516 name,
6517 representation,
6518 } => {
6519 write!(f, "CREATE TYPE {name}")?;
6520 if let Some(repr) = representation {
6521 write!(f, " {repr}")?;
6522 }
6523 Ok(())
6524 }
6525 Statement::Pragma { name, value, is_eq } => {
6526 write!(f, "PRAGMA {name}")?;
6527 if value.is_some() {
6528 let val = value.as_ref().unwrap();
6529 if *is_eq {
6530 write!(f, " = {val}")?;
6531 } else {
6532 write!(f, "({val})")?;
6533 }
6534 }
6535 Ok(())
6536 }
6537 Statement::Lock(lock) => lock.fmt(f),
6538 Statement::LockTables { tables } => {
6539 write!(f, "LOCK TABLES {}", display_comma_separated(tables))
6540 }
6541 Statement::UnlockTables => {
6542 write!(f, "UNLOCK TABLES")
6543 }
6544 Statement::Unload {
6545 query,
6546 query_text,
6547 to,
6548 auth,
6549 with,
6550 options,
6551 } => {
6552 write!(f, "UNLOAD(")?;
6553 if let Some(query) = query {
6554 write!(f, "{query}")?;
6555 }
6556 if let Some(query_text) = query_text {
6557 write!(f, "'{query_text}'")?;
6558 }
6559 write!(f, ") TO {to}")?;
6560 if let Some(auth) = auth {
6561 write!(f, " IAM_ROLE {auth}")?;
6562 }
6563 if !with.is_empty() {
6564 write!(f, " WITH ({})", display_comma_separated(with))?;
6565 }
6566 if !options.is_empty() {
6567 write!(f, " {}", display_separated(options, " "))?;
6568 }
6569 Ok(())
6570 }
6571 Statement::OptimizeTable {
6572 name,
6573 has_table_keyword,
6574 on_cluster,
6575 partition,
6576 include_final,
6577 deduplicate,
6578 predicate,
6579 zorder,
6580 } => {
6581 write!(f, "OPTIMIZE")?;
6582 if *has_table_keyword {
6583 write!(f, " TABLE")?;
6584 }
6585 write!(f, " {name}")?;
6586 if let Some(on_cluster) = on_cluster {
6587 write!(f, " ON CLUSTER {on_cluster}")?;
6588 }
6589 if let Some(partition) = partition {
6590 write!(f, " {partition}")?;
6591 }
6592 if *include_final {
6593 write!(f, " FINAL")?;
6594 }
6595 if let Some(deduplicate) = deduplicate {
6596 write!(f, " {deduplicate}")?;
6597 }
6598 if let Some(predicate) = predicate {
6599 write!(f, " WHERE {predicate}")?;
6600 }
6601 if let Some(zorder) = zorder {
6602 write!(f, " ZORDER BY ({})", display_comma_separated(zorder))?;
6603 }
6604 Ok(())
6605 }
6606 Statement::LISTEN { channel } => {
6607 write!(f, "LISTEN {channel}")?;
6608 Ok(())
6609 }
6610 Statement::UNLISTEN { channel } => {
6611 write!(f, "UNLISTEN {channel}")?;
6612 Ok(())
6613 }
6614 Statement::NOTIFY { channel, payload } => {
6615 write!(f, "NOTIFY {channel}")?;
6616 if let Some(payload) = payload {
6617 write!(f, ", '{payload}'")?;
6618 }
6619 Ok(())
6620 }
6621 Statement::RenameTable(rename_tables) => {
6622 write!(f, "RENAME TABLE {}", display_comma_separated(rename_tables))
6623 }
6624 Statement::RaisError {
6625 message,
6626 severity,
6627 state,
6628 arguments,
6629 options,
6630 } => {
6631 write!(f, "RAISERROR({message}, {severity}, {state}")?;
6632 if !arguments.is_empty() {
6633 write!(f, ", {}", display_comma_separated(arguments))?;
6634 }
6635 write!(f, ")")?;
6636 if !options.is_empty() {
6637 write!(f, " WITH {}", display_comma_separated(options))?;
6638 }
6639 Ok(())
6640 }
6641 Statement::Throw(s) => write!(f, "{s}"),
6642 Statement::Print(s) => write!(f, "{s}"),
6643 Statement::WaitFor(s) => write!(f, "{s}"),
6644 Statement::Return(r) => write!(f, "{r}"),
6645 Statement::List(command) => write!(f, "LIST {command}"),
6646 Statement::Remove(command) => write!(f, "REMOVE {command}"),
6647 Statement::ExportData(e) => write!(f, "{e}"),
6648 Statement::CreateUser(s) => write!(f, "{s}"),
6649 Statement::AlterSchema(s) => write!(f, "{s}"),
6650 Statement::Vacuum(s) => write!(f, "{s}"),
6651 Statement::AlterUser(s) => write!(f, "{s}"),
6652 Statement::Reset(s) => write!(f, "{s}"),
6653 }
6654 }
6655}
6656
6657#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6664#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6665#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6666pub enum SequenceOptions {
6667 IncrementBy(Expr, bool),
6669 MinValue(Option<Expr>),
6671 MaxValue(Option<Expr>),
6673 StartWith(Expr, bool),
6675 Cache(Expr),
6677 Cycle(bool),
6679}
6680
6681impl fmt::Display for SequenceOptions {
6682 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6683 match self {
6684 SequenceOptions::IncrementBy(increment, by) => {
6685 write!(
6686 f,
6687 " INCREMENT{by} {increment}",
6688 by = if *by { " BY" } else { "" },
6689 increment = increment
6690 )
6691 }
6692 SequenceOptions::MinValue(Some(expr)) => {
6693 write!(f, " MINVALUE {expr}")
6694 }
6695 SequenceOptions::MinValue(None) => {
6696 write!(f, " NO MINVALUE")
6697 }
6698 SequenceOptions::MaxValue(Some(expr)) => {
6699 write!(f, " MAXVALUE {expr}")
6700 }
6701 SequenceOptions::MaxValue(None) => {
6702 write!(f, " NO MAXVALUE")
6703 }
6704 SequenceOptions::StartWith(start, with) => {
6705 write!(
6706 f,
6707 " START{with} {start}",
6708 with = if *with { " WITH" } else { "" },
6709 start = start
6710 )
6711 }
6712 SequenceOptions::Cache(cache) => {
6713 write!(f, " CACHE {}", *cache)
6714 }
6715 SequenceOptions::Cycle(no) => {
6716 write!(f, " {}CYCLE", if *no { "NO " } else { "" })
6717 }
6718 }
6719 }
6720}
6721
6722#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6724#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6725#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6726pub struct SetAssignment {
6727 pub scope: Option<ContextModifier>,
6729 pub name: ObjectName,
6731 pub value: Expr,
6733}
6734
6735impl fmt::Display for SetAssignment {
6736 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6737 write!(
6738 f,
6739 "{}{} = {}",
6740 self.scope.map(|s| format!("{s}")).unwrap_or_default(),
6741 self.name,
6742 self.value
6743 )
6744 }
6745}
6746
6747#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6751#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6752#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6753pub struct TruncateTableTarget {
6754 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
6756 pub name: ObjectName,
6757 pub only: bool,
6763 pub has_asterisk: bool,
6769}
6770
6771impl fmt::Display for TruncateTableTarget {
6772 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6773 if self.only {
6774 write!(f, "ONLY ")?;
6775 };
6776 write!(f, "{}", self.name)?;
6777 if self.has_asterisk {
6778 write!(f, " *")?;
6779 };
6780 Ok(())
6781 }
6782}
6783
6784#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6788#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6789#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6790pub struct Lock {
6791 pub tables: Vec<LockTableTarget>,
6793 pub lock_mode: Option<LockTableMode>,
6795 pub nowait: bool,
6797}
6798
6799impl fmt::Display for Lock {
6800 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6801 write!(f, "LOCK TABLE {}", display_comma_separated(&self.tables))?;
6802 if let Some(lock_mode) = &self.lock_mode {
6803 write!(f, " IN {lock_mode} MODE")?;
6804 }
6805 if self.nowait {
6806 write!(f, " NOWAIT")?;
6807 }
6808 Ok(())
6809 }
6810}
6811
6812#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6816#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6817#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6818pub struct LockTableTarget {
6819 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
6821 pub name: ObjectName,
6822 pub only: bool,
6824 pub has_asterisk: bool,
6826}
6827
6828impl fmt::Display for LockTableTarget {
6829 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6830 if self.only {
6831 write!(f, "ONLY ")?;
6832 }
6833 write!(f, "{}", self.name)?;
6834 if self.has_asterisk {
6835 write!(f, " *")?;
6836 }
6837 Ok(())
6838 }
6839}
6840
6841#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6845#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6846#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6847pub enum LockTableMode {
6848 AccessShare,
6850 RowShare,
6852 RowExclusive,
6854 ShareUpdateExclusive,
6856 Share,
6858 ShareRowExclusive,
6860 Exclusive,
6862 AccessExclusive,
6864}
6865
6866impl fmt::Display for LockTableMode {
6867 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6868 let text = match self {
6869 Self::AccessShare => "ACCESS SHARE",
6870 Self::RowShare => "ROW SHARE",
6871 Self::RowExclusive => "ROW EXCLUSIVE",
6872 Self::ShareUpdateExclusive => "SHARE UPDATE EXCLUSIVE",
6873 Self::Share => "SHARE",
6874 Self::ShareRowExclusive => "SHARE ROW EXCLUSIVE",
6875 Self::Exclusive => "EXCLUSIVE",
6876 Self::AccessExclusive => "ACCESS EXCLUSIVE",
6877 };
6878 write!(f, "{text}")
6879 }
6880}
6881
6882#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6885#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6886#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6887pub enum TruncateIdentityOption {
6888 Restart,
6890 Continue,
6892}
6893
6894#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6897#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6898#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6899pub enum CascadeOption {
6900 Cascade,
6902 Restrict,
6904}
6905
6906impl Display for CascadeOption {
6907 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6908 match self {
6909 CascadeOption::Cascade => write!(f, "CASCADE"),
6910 CascadeOption::Restrict => write!(f, "RESTRICT"),
6911 }
6912 }
6913}
6914
6915#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6917#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6918#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6919pub enum BeginTransactionKind {
6920 Transaction,
6922 Work,
6924 Tran,
6927}
6928
6929impl Display for BeginTransactionKind {
6930 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6931 match self {
6932 BeginTransactionKind::Transaction => write!(f, "TRANSACTION"),
6933 BeginTransactionKind::Work => write!(f, "WORK"),
6934 BeginTransactionKind::Tran => write!(f, "TRAN"),
6935 }
6936 }
6937}
6938
6939#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6942#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6943#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6944pub enum MinMaxValue {
6945 Empty,
6947 None,
6949 Some(Expr),
6951}
6952
6953#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6954#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6955#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6956#[non_exhaustive]
6957pub enum OnInsert {
6959 DuplicateKeyUpdate(Vec<Assignment>),
6961 OnConflict(OnConflict),
6963}
6964
6965#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6966#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6967#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6968pub struct InsertAliases {
6970 pub row_alias: ObjectName,
6972 pub col_aliases: Option<Vec<Ident>>,
6974}
6975
6976#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6977#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6978#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6979pub struct TableAliasWithoutColumns {
6981 pub explicit: bool,
6983 pub alias: Ident,
6985}
6986
6987#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6988#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6989#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6990pub struct OnConflict {
6992 pub conflict_target: Option<ConflictTarget>,
6994 pub action: OnConflictAction,
6996}
6997#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6998#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6999#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7000pub enum ConflictTarget {
7002 Columns(Vec<Ident>),
7004 OnConstraint(ObjectName),
7006}
7007#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7008#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7009#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7010pub enum OnConflictAction {
7012 DoNothing,
7014 DoUpdate(DoUpdate),
7016}
7017
7018#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7019#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7020#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7021pub struct DoUpdate {
7023 pub assignments: Vec<Assignment>,
7025 pub selection: Option<Expr>,
7027}
7028
7029impl fmt::Display for OnInsert {
7030 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7031 match self {
7032 Self::DuplicateKeyUpdate(expr) => write!(
7033 f,
7034 " ON DUPLICATE KEY UPDATE {}",
7035 display_comma_separated(expr)
7036 ),
7037 Self::OnConflict(o) => write!(f, "{o}"),
7038 }
7039 }
7040}
7041impl fmt::Display for OnConflict {
7042 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7043 write!(f, " ON CONFLICT")?;
7044 if let Some(target) = &self.conflict_target {
7045 write!(f, "{target}")?;
7046 }
7047 write!(f, " {}", self.action)
7048 }
7049}
7050impl fmt::Display for ConflictTarget {
7051 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7052 match self {
7053 ConflictTarget::Columns(cols) => write!(f, "({})", display_comma_separated(cols)),
7054 ConflictTarget::OnConstraint(name) => write!(f, " ON CONSTRAINT {name}"),
7055 }
7056 }
7057}
7058impl fmt::Display for OnConflictAction {
7059 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7060 match self {
7061 Self::DoNothing => write!(f, "DO NOTHING"),
7062 Self::DoUpdate(do_update) => {
7063 write!(f, "DO UPDATE")?;
7064 if !do_update.assignments.is_empty() {
7065 write!(
7066 f,
7067 " SET {}",
7068 display_comma_separated(&do_update.assignments)
7069 )?;
7070 }
7071 if let Some(selection) = &do_update.selection {
7072 write!(f, " WHERE {selection}")?;
7073 }
7074 Ok(())
7075 }
7076 }
7077 }
7078}
7079
7080#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7082#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7083#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7084pub enum Privileges {
7085 All {
7087 with_privileges_keyword: bool,
7089 },
7090 Actions(Vec<Action>),
7092}
7093
7094impl fmt::Display for Privileges {
7095 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7096 match self {
7097 Privileges::All {
7098 with_privileges_keyword,
7099 } => {
7100 write!(
7101 f,
7102 "ALL{}",
7103 if *with_privileges_keyword {
7104 " PRIVILEGES"
7105 } else {
7106 ""
7107 }
7108 )
7109 }
7110 Privileges::Actions(actions) => {
7111 write!(f, "{}", display_comma_separated(actions))
7112 }
7113 }
7114 }
7115}
7116
7117#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7119#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7120#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7121pub enum FetchDirection {
7122 Count {
7124 limit: ValueWithSpan,
7126 },
7127 Next,
7129 Prior,
7131 First,
7133 Last,
7135 Absolute {
7137 limit: ValueWithSpan,
7139 },
7140 Relative {
7142 limit: ValueWithSpan,
7144 },
7145 All,
7147 Forward {
7151 limit: Option<ValueWithSpan>,
7153 },
7154 ForwardAll,
7156 Backward {
7160 limit: Option<ValueWithSpan>,
7162 },
7163 BackwardAll,
7165}
7166
7167impl fmt::Display for FetchDirection {
7168 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7169 match self {
7170 FetchDirection::Count { limit } => f.write_str(&limit.to_string())?,
7171 FetchDirection::Next => f.write_str("NEXT")?,
7172 FetchDirection::Prior => f.write_str("PRIOR")?,
7173 FetchDirection::First => f.write_str("FIRST")?,
7174 FetchDirection::Last => f.write_str("LAST")?,
7175 FetchDirection::Absolute { limit } => {
7176 f.write_str("ABSOLUTE ")?;
7177 f.write_str(&limit.to_string())?;
7178 }
7179 FetchDirection::Relative { limit } => {
7180 f.write_str("RELATIVE ")?;
7181 f.write_str(&limit.to_string())?;
7182 }
7183 FetchDirection::All => f.write_str("ALL")?,
7184 FetchDirection::Forward { limit } => {
7185 f.write_str("FORWARD")?;
7186
7187 if let Some(l) = limit {
7188 f.write_str(" ")?;
7189 f.write_str(&l.to_string())?;
7190 }
7191 }
7192 FetchDirection::ForwardAll => f.write_str("FORWARD ALL")?,
7193 FetchDirection::Backward { limit } => {
7194 f.write_str("BACKWARD")?;
7195
7196 if let Some(l) = limit {
7197 f.write_str(" ")?;
7198 f.write_str(&l.to_string())?;
7199 }
7200 }
7201 FetchDirection::BackwardAll => f.write_str("BACKWARD ALL")?,
7202 };
7203
7204 Ok(())
7205 }
7206}
7207
7208#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7212#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7213#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7214pub enum FetchPosition {
7215 From,
7217 In,
7219}
7220
7221impl fmt::Display for FetchPosition {
7222 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7223 match self {
7224 FetchPosition::From => f.write_str("FROM")?,
7225 FetchPosition::In => f.write_str("IN")?,
7226 };
7227
7228 Ok(())
7229 }
7230}
7231
7232#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7234#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7235#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7236pub enum Action {
7237 AddSearchOptimization,
7239 Apply {
7241 apply_type: ActionApplyType,
7243 },
7244 ApplyBudget,
7246 AttachListing,
7248 AttachPolicy,
7250 Audit,
7252 BindServiceEndpoint,
7254 Connect,
7256 Create {
7258 obj_type: Option<ActionCreateObjectType>,
7260 },
7261 DatabaseRole {
7263 role: ObjectName,
7265 },
7266 Delete,
7268 Drop,
7270 EvolveSchema,
7272 Exec {
7274 obj_type: Option<ActionExecuteObjectType>,
7276 },
7277 Execute {
7279 obj_type: Option<ActionExecuteObjectType>,
7281 },
7282 Failover,
7284 ImportedPrivileges,
7286 ImportShare,
7288 Insert {
7290 columns: Option<Vec<Ident>>,
7292 },
7293 Manage {
7295 manage_type: ActionManageType,
7297 },
7298 ManageReleases,
7300 ManageVersions,
7302 Modify {
7304 modify_type: Option<ActionModifyType>,
7306 },
7307 Monitor {
7309 monitor_type: Option<ActionMonitorType>,
7311 },
7312 Operate,
7314 OverrideShareRestrictions,
7316 Ownership,
7318 PurchaseDataExchangeListing,
7320
7321 Read,
7323 ReadSession,
7325 References {
7327 columns: Option<Vec<Ident>>,
7329 },
7330 Replicate,
7332 ResolveAll,
7334 Role {
7336 role: ObjectName,
7338 },
7339 Select {
7341 columns: Option<Vec<Ident>>,
7343 },
7344 Temporary,
7346 Trigger,
7348 Truncate,
7350 Update {
7352 columns: Option<Vec<Ident>>,
7354 },
7355 Usage,
7357}
7358
7359impl fmt::Display for Action {
7360 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7361 match self {
7362 Action::AddSearchOptimization => f.write_str("ADD SEARCH OPTIMIZATION")?,
7363 Action::Apply { apply_type } => write!(f, "APPLY {apply_type}")?,
7364 Action::ApplyBudget => f.write_str("APPLYBUDGET")?,
7365 Action::AttachListing => f.write_str("ATTACH LISTING")?,
7366 Action::AttachPolicy => f.write_str("ATTACH POLICY")?,
7367 Action::Audit => f.write_str("AUDIT")?,
7368 Action::BindServiceEndpoint => f.write_str("BIND SERVICE ENDPOINT")?,
7369 Action::Connect => f.write_str("CONNECT")?,
7370 Action::Create { obj_type } => {
7371 f.write_str("CREATE")?;
7372 if let Some(obj_type) = obj_type {
7373 write!(f, " {obj_type}")?
7374 }
7375 }
7376 Action::DatabaseRole { role } => write!(f, "DATABASE ROLE {role}")?,
7377 Action::Delete => f.write_str("DELETE")?,
7378 Action::Drop => f.write_str("DROP")?,
7379 Action::EvolveSchema => f.write_str("EVOLVE SCHEMA")?,
7380 Action::Exec { obj_type } => {
7381 f.write_str("EXEC")?;
7382 if let Some(obj_type) = obj_type {
7383 write!(f, " {obj_type}")?
7384 }
7385 }
7386 Action::Execute { obj_type } => {
7387 f.write_str("EXECUTE")?;
7388 if let Some(obj_type) = obj_type {
7389 write!(f, " {obj_type}")?
7390 }
7391 }
7392 Action::Failover => f.write_str("FAILOVER")?,
7393 Action::ImportedPrivileges => f.write_str("IMPORTED PRIVILEGES")?,
7394 Action::ImportShare => f.write_str("IMPORT SHARE")?,
7395 Action::Insert { .. } => f.write_str("INSERT")?,
7396 Action::Manage { manage_type } => write!(f, "MANAGE {manage_type}")?,
7397 Action::ManageReleases => f.write_str("MANAGE RELEASES")?,
7398 Action::ManageVersions => f.write_str("MANAGE VERSIONS")?,
7399 Action::Modify { modify_type } => {
7400 write!(f, "MODIFY")?;
7401 if let Some(modify_type) = modify_type {
7402 write!(f, " {modify_type}")?;
7403 }
7404 }
7405 Action::Monitor { monitor_type } => {
7406 write!(f, "MONITOR")?;
7407 if let Some(monitor_type) = monitor_type {
7408 write!(f, " {monitor_type}")?
7409 }
7410 }
7411 Action::Operate => f.write_str("OPERATE")?,
7412 Action::OverrideShareRestrictions => f.write_str("OVERRIDE SHARE RESTRICTIONS")?,
7413 Action::Ownership => f.write_str("OWNERSHIP")?,
7414 Action::PurchaseDataExchangeListing => f.write_str("PURCHASE DATA EXCHANGE LISTING")?,
7415 Action::Read => f.write_str("READ")?,
7416 Action::ReadSession => f.write_str("READ SESSION")?,
7417 Action::References { .. } => f.write_str("REFERENCES")?,
7418 Action::Replicate => f.write_str("REPLICATE")?,
7419 Action::ResolveAll => f.write_str("RESOLVE ALL")?,
7420 Action::Role { role } => write!(f, "ROLE {role}")?,
7421 Action::Select { .. } => f.write_str("SELECT")?,
7422 Action::Temporary => f.write_str("TEMPORARY")?,
7423 Action::Trigger => f.write_str("TRIGGER")?,
7424 Action::Truncate => f.write_str("TRUNCATE")?,
7425 Action::Update { .. } => f.write_str("UPDATE")?,
7426 Action::Usage => f.write_str("USAGE")?,
7427 };
7428 match self {
7429 Action::Insert { columns }
7430 | Action::References { columns }
7431 | Action::Select { columns }
7432 | Action::Update { columns } => {
7433 if let Some(columns) = columns {
7434 write!(f, " ({})", display_comma_separated(columns))?;
7435 }
7436 }
7437 _ => (),
7438 };
7439 Ok(())
7440 }
7441}
7442
7443#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7444#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7445#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7446pub enum ActionCreateObjectType {
7449 Account,
7451 Application,
7453 ApplicationPackage,
7455 ComputePool,
7457 DataExchangeListing,
7459 Database,
7461 ExternalVolume,
7463 FailoverGroup,
7465 Integration,
7467 NetworkPolicy,
7469 OrganiationListing,
7471 ReplicationGroup,
7473 Role,
7475 Schema,
7477 Share,
7479 User,
7481 Warehouse,
7483}
7484
7485impl fmt::Display for ActionCreateObjectType {
7486 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7487 match self {
7488 ActionCreateObjectType::Account => write!(f, "ACCOUNT"),
7489 ActionCreateObjectType::Application => write!(f, "APPLICATION"),
7490 ActionCreateObjectType::ApplicationPackage => write!(f, "APPLICATION PACKAGE"),
7491 ActionCreateObjectType::ComputePool => write!(f, "COMPUTE POOL"),
7492 ActionCreateObjectType::DataExchangeListing => write!(f, "DATA EXCHANGE LISTING"),
7493 ActionCreateObjectType::Database => write!(f, "DATABASE"),
7494 ActionCreateObjectType::ExternalVolume => write!(f, "EXTERNAL VOLUME"),
7495 ActionCreateObjectType::FailoverGroup => write!(f, "FAILOVER GROUP"),
7496 ActionCreateObjectType::Integration => write!(f, "INTEGRATION"),
7497 ActionCreateObjectType::NetworkPolicy => write!(f, "NETWORK POLICY"),
7498 ActionCreateObjectType::OrganiationListing => write!(f, "ORGANIZATION LISTING"),
7499 ActionCreateObjectType::ReplicationGroup => write!(f, "REPLICATION GROUP"),
7500 ActionCreateObjectType::Role => write!(f, "ROLE"),
7501 ActionCreateObjectType::Schema => write!(f, "SCHEMA"),
7502 ActionCreateObjectType::Share => write!(f, "SHARE"),
7503 ActionCreateObjectType::User => write!(f, "USER"),
7504 ActionCreateObjectType::Warehouse => write!(f, "WAREHOUSE"),
7505 }
7506 }
7507}
7508
7509#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7510#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7511#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7512pub enum ActionApplyType {
7515 AggregationPolicy,
7517 AuthenticationPolicy,
7519 JoinPolicy,
7521 MaskingPolicy,
7523 PackagesPolicy,
7525 PasswordPolicy,
7527 ProjectionPolicy,
7529 RowAccessPolicy,
7531 SessionPolicy,
7533 Tag,
7535}
7536
7537impl fmt::Display for ActionApplyType {
7538 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7539 match self {
7540 ActionApplyType::AggregationPolicy => write!(f, "AGGREGATION POLICY"),
7541 ActionApplyType::AuthenticationPolicy => write!(f, "AUTHENTICATION POLICY"),
7542 ActionApplyType::JoinPolicy => write!(f, "JOIN POLICY"),
7543 ActionApplyType::MaskingPolicy => write!(f, "MASKING POLICY"),
7544 ActionApplyType::PackagesPolicy => write!(f, "PACKAGES POLICY"),
7545 ActionApplyType::PasswordPolicy => write!(f, "PASSWORD POLICY"),
7546 ActionApplyType::ProjectionPolicy => write!(f, "PROJECTION POLICY"),
7547 ActionApplyType::RowAccessPolicy => write!(f, "ROW ACCESS POLICY"),
7548 ActionApplyType::SessionPolicy => write!(f, "SESSION POLICY"),
7549 ActionApplyType::Tag => write!(f, "TAG"),
7550 }
7551 }
7552}
7553
7554#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7555#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7556#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7557pub enum ActionExecuteObjectType {
7560 Alert,
7562 DataMetricFunction,
7564 ManagedAlert,
7566 ManagedTask,
7568 Task,
7570}
7571
7572impl fmt::Display for ActionExecuteObjectType {
7573 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7574 match self {
7575 ActionExecuteObjectType::Alert => write!(f, "ALERT"),
7576 ActionExecuteObjectType::DataMetricFunction => write!(f, "DATA METRIC FUNCTION"),
7577 ActionExecuteObjectType::ManagedAlert => write!(f, "MANAGED ALERT"),
7578 ActionExecuteObjectType::ManagedTask => write!(f, "MANAGED TASK"),
7579 ActionExecuteObjectType::Task => write!(f, "TASK"),
7580 }
7581 }
7582}
7583
7584#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7585#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7586#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7587pub enum ActionManageType {
7590 AccountSupportCases,
7592 EventSharing,
7594 Grants,
7596 ListingAutoFulfillment,
7598 OrganizationSupportCases,
7600 UserSupportCases,
7602 Warehouses,
7604}
7605
7606impl fmt::Display for ActionManageType {
7607 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7608 match self {
7609 ActionManageType::AccountSupportCases => write!(f, "ACCOUNT SUPPORT CASES"),
7610 ActionManageType::EventSharing => write!(f, "EVENT SHARING"),
7611 ActionManageType::Grants => write!(f, "GRANTS"),
7612 ActionManageType::ListingAutoFulfillment => write!(f, "LISTING AUTO FULFILLMENT"),
7613 ActionManageType::OrganizationSupportCases => write!(f, "ORGANIZATION SUPPORT CASES"),
7614 ActionManageType::UserSupportCases => write!(f, "USER SUPPORT CASES"),
7615 ActionManageType::Warehouses => write!(f, "WAREHOUSES"),
7616 }
7617 }
7618}
7619
7620#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7621#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7622#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7623pub enum ActionModifyType {
7626 LogLevel,
7628 TraceLevel,
7630 SessionLogLevel,
7632 SessionTraceLevel,
7634}
7635
7636impl fmt::Display for ActionModifyType {
7637 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7638 match self {
7639 ActionModifyType::LogLevel => write!(f, "LOG LEVEL"),
7640 ActionModifyType::TraceLevel => write!(f, "TRACE LEVEL"),
7641 ActionModifyType::SessionLogLevel => write!(f, "SESSION LOG LEVEL"),
7642 ActionModifyType::SessionTraceLevel => write!(f, "SESSION TRACE LEVEL"),
7643 }
7644 }
7645}
7646
7647#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7648#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7649#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7650pub enum ActionMonitorType {
7653 Execution,
7655 Security,
7657 Usage,
7659}
7660
7661impl fmt::Display for ActionMonitorType {
7662 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7663 match self {
7664 ActionMonitorType::Execution => write!(f, "EXECUTION"),
7665 ActionMonitorType::Security => write!(f, "SECURITY"),
7666 ActionMonitorType::Usage => write!(f, "USAGE"),
7667 }
7668 }
7669}
7670
7671#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7673#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7674#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7675pub struct Grantee {
7676 pub grantee_type: GranteesType,
7678 pub name: Option<GranteeName>,
7680}
7681
7682impl fmt::Display for Grantee {
7683 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7684 if matches!(self.grantee_type, GranteesType::Public) {
7685 return write!(f, "PUBLIC");
7686 }
7687 match self.grantee_type {
7688 GranteesType::Role => {
7689 write!(f, "ROLE ")?;
7690 }
7691 GranteesType::Share => {
7692 write!(f, "SHARE ")?;
7693 }
7694 GranteesType::User => {
7695 write!(f, "USER ")?;
7696 }
7697 GranteesType::Group => {
7698 write!(f, "GROUP ")?;
7699 }
7700 GranteesType::Public => {}
7701 GranteesType::DatabaseRole => {
7702 write!(f, "DATABASE ROLE ")?;
7703 }
7704 GranteesType::Application => {
7705 write!(f, "APPLICATION ")?;
7706 }
7707 GranteesType::ApplicationRole => {
7708 write!(f, "APPLICATION ROLE ")?;
7709 }
7710 GranteesType::None => (),
7711 }
7712 if let Some(ref name) = self.name {
7713 name.fmt(f)?;
7714 }
7715 Ok(())
7716 }
7717}
7718
7719#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7720#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7721#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7722pub enum GranteesType {
7724 Role,
7726 Share,
7728 User,
7730 Group,
7732 Public,
7734 DatabaseRole,
7736 Application,
7738 ApplicationRole,
7740 None,
7742}
7743
7744#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7746#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7747#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7748pub enum GranteeName {
7749 ObjectName(ObjectName),
7751 UserHost {
7753 user: Ident,
7755 host: Ident,
7757 },
7758}
7759
7760impl fmt::Display for GranteeName {
7761 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7762 match self {
7763 GranteeName::ObjectName(name) => name.fmt(f),
7764 GranteeName::UserHost { user, host } => {
7765 write!(f, "{user}@{host}")
7766 }
7767 }
7768 }
7769}
7770
7771#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7773#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7774#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7775pub enum GrantObjects {
7776 AllSequencesInSchema {
7778 schemas: Vec<ObjectName>,
7780 },
7781 AllTablesInSchema {
7783 schemas: Vec<ObjectName>,
7785 },
7786 AllViewsInSchema {
7788 schemas: Vec<ObjectName>,
7790 },
7791 AllMaterializedViewsInSchema {
7793 schemas: Vec<ObjectName>,
7795 },
7796 AllExternalTablesInSchema {
7798 schemas: Vec<ObjectName>,
7800 },
7801 AllFunctionsInSchema {
7803 schemas: Vec<ObjectName>,
7805 },
7806 FutureSchemasInDatabase {
7808 databases: Vec<ObjectName>,
7810 },
7811 FutureTablesInSchema {
7813 schemas: Vec<ObjectName>,
7815 },
7816 FutureViewsInSchema {
7818 schemas: Vec<ObjectName>,
7820 },
7821 FutureExternalTablesInSchema {
7823 schemas: Vec<ObjectName>,
7825 },
7826 FutureMaterializedViewsInSchema {
7828 schemas: Vec<ObjectName>,
7830 },
7831 FutureSequencesInSchema {
7833 schemas: Vec<ObjectName>,
7835 },
7836 Databases(Vec<ObjectName>),
7838 Schemas(Vec<ObjectName>),
7840 Sequences(Vec<ObjectName>),
7842 Tables(Vec<ObjectName>),
7844 Views(Vec<ObjectName>),
7846 Warehouses(Vec<ObjectName>),
7848 Integrations(Vec<ObjectName>),
7850 ResourceMonitors(Vec<ObjectName>),
7852 Users(Vec<ObjectName>),
7854 ComputePools(Vec<ObjectName>),
7856 Connections(Vec<ObjectName>),
7858 FailoverGroup(Vec<ObjectName>),
7860 ReplicationGroup(Vec<ObjectName>),
7862 ExternalVolumes(Vec<ObjectName>),
7864 Procedure {
7870 name: ObjectName,
7872 arg_types: Vec<DataType>,
7874 },
7875
7876 Function {
7882 name: ObjectName,
7884 arg_types: Vec<DataType>,
7886 },
7887
7888 Types(Vec<ObjectName>),
7893
7894 Domains(Vec<ObjectName>),
7899}
7900
7901impl fmt::Display for GrantObjects {
7902 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7903 match self {
7904 GrantObjects::Sequences(sequences) => {
7905 write!(f, "SEQUENCE {}", display_comma_separated(sequences))
7906 }
7907 GrantObjects::Databases(databases) => {
7908 write!(f, "DATABASE {}", display_comma_separated(databases))
7909 }
7910 GrantObjects::Schemas(schemas) => {
7911 write!(f, "SCHEMA {}", display_comma_separated(schemas))
7912 }
7913 GrantObjects::Tables(tables) => {
7914 write!(f, "{}", display_comma_separated(tables))
7915 }
7916 GrantObjects::Views(views) => {
7917 write!(f, "VIEW {}", display_comma_separated(views))
7918 }
7919 GrantObjects::Warehouses(warehouses) => {
7920 write!(f, "WAREHOUSE {}", display_comma_separated(warehouses))
7921 }
7922 GrantObjects::Integrations(integrations) => {
7923 write!(f, "INTEGRATION {}", display_comma_separated(integrations))
7924 }
7925 GrantObjects::AllSequencesInSchema { schemas } => {
7926 write!(
7927 f,
7928 "ALL SEQUENCES IN SCHEMA {}",
7929 display_comma_separated(schemas)
7930 )
7931 }
7932 GrantObjects::AllTablesInSchema { schemas } => {
7933 write!(
7934 f,
7935 "ALL TABLES IN SCHEMA {}",
7936 display_comma_separated(schemas)
7937 )
7938 }
7939 GrantObjects::AllExternalTablesInSchema { schemas } => {
7940 write!(
7941 f,
7942 "ALL EXTERNAL TABLES IN SCHEMA {}",
7943 display_comma_separated(schemas)
7944 )
7945 }
7946 GrantObjects::AllViewsInSchema { schemas } => {
7947 write!(
7948 f,
7949 "ALL VIEWS IN SCHEMA {}",
7950 display_comma_separated(schemas)
7951 )
7952 }
7953 GrantObjects::AllMaterializedViewsInSchema { schemas } => {
7954 write!(
7955 f,
7956 "ALL MATERIALIZED VIEWS IN SCHEMA {}",
7957 display_comma_separated(schemas)
7958 )
7959 }
7960 GrantObjects::AllFunctionsInSchema { schemas } => {
7961 write!(
7962 f,
7963 "ALL FUNCTIONS IN SCHEMA {}",
7964 display_comma_separated(schemas)
7965 )
7966 }
7967 GrantObjects::FutureSchemasInDatabase { databases } => {
7968 write!(
7969 f,
7970 "FUTURE SCHEMAS IN DATABASE {}",
7971 display_comma_separated(databases)
7972 )
7973 }
7974 GrantObjects::FutureTablesInSchema { schemas } => {
7975 write!(
7976 f,
7977 "FUTURE TABLES IN SCHEMA {}",
7978 display_comma_separated(schemas)
7979 )
7980 }
7981 GrantObjects::FutureExternalTablesInSchema { schemas } => {
7982 write!(
7983 f,
7984 "FUTURE EXTERNAL TABLES IN SCHEMA {}",
7985 display_comma_separated(schemas)
7986 )
7987 }
7988 GrantObjects::FutureViewsInSchema { schemas } => {
7989 write!(
7990 f,
7991 "FUTURE VIEWS IN SCHEMA {}",
7992 display_comma_separated(schemas)
7993 )
7994 }
7995 GrantObjects::FutureMaterializedViewsInSchema { schemas } => {
7996 write!(
7997 f,
7998 "FUTURE MATERIALIZED VIEWS IN SCHEMA {}",
7999 display_comma_separated(schemas)
8000 )
8001 }
8002 GrantObjects::FutureSequencesInSchema { schemas } => {
8003 write!(
8004 f,
8005 "FUTURE SEQUENCES IN SCHEMA {}",
8006 display_comma_separated(schemas)
8007 )
8008 }
8009 GrantObjects::ResourceMonitors(objects) => {
8010 write!(f, "RESOURCE MONITOR {}", display_comma_separated(objects))
8011 }
8012 GrantObjects::Users(objects) => {
8013 write!(f, "USER {}", display_comma_separated(objects))
8014 }
8015 GrantObjects::ComputePools(objects) => {
8016 write!(f, "COMPUTE POOL {}", display_comma_separated(objects))
8017 }
8018 GrantObjects::Connections(objects) => {
8019 write!(f, "CONNECTION {}", display_comma_separated(objects))
8020 }
8021 GrantObjects::FailoverGroup(objects) => {
8022 write!(f, "FAILOVER GROUP {}", display_comma_separated(objects))
8023 }
8024 GrantObjects::ReplicationGroup(objects) => {
8025 write!(f, "REPLICATION GROUP {}", display_comma_separated(objects))
8026 }
8027 GrantObjects::ExternalVolumes(objects) => {
8028 write!(f, "EXTERNAL VOLUME {}", display_comma_separated(objects))
8029 }
8030 GrantObjects::Procedure { name, arg_types } => {
8031 write!(f, "PROCEDURE {name}")?;
8032 if !arg_types.is_empty() {
8033 write!(f, "({})", display_comma_separated(arg_types))?;
8034 }
8035 Ok(())
8036 }
8037 GrantObjects::Function { name, arg_types } => {
8038 write!(f, "FUNCTION {name}")?;
8039 if !arg_types.is_empty() {
8040 write!(f, "({})", display_comma_separated(arg_types))?;
8041 }
8042 Ok(())
8043 }
8044 GrantObjects::Types(types) => {
8045 write!(f, "TYPE {}", display_comma_separated(types))
8046 }
8047 GrantObjects::Domains(domains) => {
8048 write!(f, "DOMAIN {}", display_comma_separated(domains))
8049 }
8050 }
8051 }
8052}
8053
8054#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8058#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8059#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8060pub struct DenyStatement {
8061 pub privileges: Privileges,
8063 pub objects: GrantObjects,
8065 pub grantees: Vec<Grantee>,
8067 pub granted_by: Option<Ident>,
8069 pub cascade: Option<CascadeOption>,
8071}
8072
8073impl fmt::Display for DenyStatement {
8074 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8075 write!(f, "DENY {}", self.privileges)?;
8076 write!(f, " ON {}", self.objects)?;
8077 if !self.grantees.is_empty() {
8078 write!(f, " TO {}", display_comma_separated(&self.grantees))?;
8079 }
8080 if let Some(cascade) = &self.cascade {
8081 write!(f, " {cascade}")?;
8082 }
8083 if let Some(granted_by) = &self.granted_by {
8084 write!(f, " AS {granted_by}")?;
8085 }
8086 Ok(())
8087 }
8088}
8089
8090#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8092#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8093#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8094pub struct Assignment {
8095 pub target: AssignmentTarget,
8097 pub value: Expr,
8099}
8100
8101impl fmt::Display for Assignment {
8102 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8103 write!(f, "{} = {}", self.target, self.value)
8104 }
8105}
8106
8107#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8111#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8112#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8113pub enum AssignmentTarget {
8114 ColumnName(ObjectName),
8116 Tuple(Vec<ObjectName>),
8118}
8119
8120impl fmt::Display for AssignmentTarget {
8121 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8122 match self {
8123 AssignmentTarget::ColumnName(column) => write!(f, "{column}"),
8124 AssignmentTarget::Tuple(columns) => write!(f, "({})", display_comma_separated(columns)),
8125 }
8126 }
8127}
8128
8129#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8130#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8131#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8132pub enum FunctionArgExpr {
8134 Expr(Expr),
8136 QualifiedWildcard(ObjectName),
8138 Wildcard,
8140 WildcardWithOptions(WildcardAdditionalOptions),
8144}
8145
8146impl From<Expr> for FunctionArgExpr {
8147 fn from(wildcard_expr: Expr) -> Self {
8148 match wildcard_expr {
8149 Expr::QualifiedWildcard(prefix, _) => Self::QualifiedWildcard(prefix),
8150 Expr::Wildcard(_) => Self::Wildcard,
8151 expr => Self::Expr(expr),
8152 }
8153 }
8154}
8155
8156impl fmt::Display for FunctionArgExpr {
8157 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8158 match self {
8159 FunctionArgExpr::Expr(expr) => write!(f, "{expr}"),
8160 FunctionArgExpr::QualifiedWildcard(prefix) => write!(f, "{prefix}.*"),
8161 FunctionArgExpr::Wildcard => f.write_str("*"),
8162 FunctionArgExpr::WildcardWithOptions(opts) => write!(f, "*{opts}"),
8163 }
8164 }
8165}
8166
8167#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8168#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8169#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8170pub enum FunctionArgOperator {
8172 Equals,
8174 RightArrow,
8176 Assignment,
8178 Colon,
8180 Value,
8182}
8183
8184impl fmt::Display for FunctionArgOperator {
8185 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8186 match self {
8187 FunctionArgOperator::Equals => f.write_str("="),
8188 FunctionArgOperator::RightArrow => f.write_str("=>"),
8189 FunctionArgOperator::Assignment => f.write_str(":="),
8190 FunctionArgOperator::Colon => f.write_str(":"),
8191 FunctionArgOperator::Value => f.write_str("VALUE"),
8192 }
8193 }
8194}
8195
8196#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8197#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8198#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8199pub enum FunctionArg {
8201 Named {
8205 name: Ident,
8207 arg: FunctionArgExpr,
8209 operator: FunctionArgOperator,
8211 },
8212 ExprNamed {
8216 name: Expr,
8218 arg: FunctionArgExpr,
8220 operator: FunctionArgOperator,
8222 },
8223 Unnamed(FunctionArgExpr),
8225}
8226
8227impl fmt::Display for FunctionArg {
8228 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8229 match self {
8230 FunctionArg::Named {
8231 name,
8232 arg,
8233 operator,
8234 } => write!(f, "{name} {operator} {arg}"),
8235 FunctionArg::ExprNamed {
8236 name,
8237 arg,
8238 operator,
8239 } => write!(f, "{name} {operator} {arg}"),
8240 FunctionArg::Unnamed(unnamed_arg) => write!(f, "{unnamed_arg}"),
8241 }
8242 }
8243}
8244
8245#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8246#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8247#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8248pub enum CloseCursor {
8250 All,
8252 Specific {
8254 name: Ident,
8256 },
8257}
8258
8259impl fmt::Display for CloseCursor {
8260 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8261 match self {
8262 CloseCursor::All => write!(f, "ALL"),
8263 CloseCursor::Specific { name } => write!(f, "{name}"),
8264 }
8265 }
8266}
8267
8268#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8270#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8271#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8272pub struct DropDomain {
8273 pub if_exists: bool,
8275 pub name: ObjectName,
8277 pub drop_behavior: Option<DropBehavior>,
8279}
8280
8281#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8285#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8286#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8287pub struct TypedString {
8288 pub data_type: DataType,
8290 pub value: ValueWithSpan,
8293 pub uses_odbc_syntax: bool,
8304}
8305
8306impl fmt::Display for TypedString {
8307 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8308 let data_type = &self.data_type;
8309 let value = &self.value;
8310 match self.uses_odbc_syntax {
8311 false => {
8312 write!(f, "{data_type}")?;
8313 write!(f, " {value}")
8314 }
8315 true => {
8316 let prefix = match data_type {
8317 DataType::Date => "d",
8318 DataType::Time(..) => "t",
8319 DataType::Timestamp(..) => "ts",
8320 _ => "?",
8321 };
8322 write!(f, "{{{prefix} {value}}}")
8323 }
8324 }
8325 }
8326}
8327
8328#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8330#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8331#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8332pub struct Function {
8333 pub name: ObjectName,
8335 pub uses_odbc_syntax: bool,
8344 pub parameters: FunctionArguments,
8354 pub args: FunctionArguments,
8357 pub filter: Option<Box<Expr>>,
8359 pub null_treatment: Option<NullTreatment>,
8368 pub over: Option<WindowType>,
8370 pub within_group: Vec<OrderByExpr>,
8378}
8379
8380impl fmt::Display for Function {
8381 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8382 if self.uses_odbc_syntax {
8383 write!(f, "{{fn ")?;
8384 }
8385
8386 write!(f, "{}{}{}", self.name, self.parameters, self.args)?;
8387
8388 if !self.within_group.is_empty() {
8389 write!(
8390 f,
8391 " WITHIN GROUP (ORDER BY {})",
8392 display_comma_separated(&self.within_group)
8393 )?;
8394 }
8395
8396 if let Some(filter_cond) = &self.filter {
8397 write!(f, " FILTER (WHERE {filter_cond})")?;
8398 }
8399
8400 if let Some(null_treatment) = &self.null_treatment {
8401 write!(f, " {null_treatment}")?;
8402 }
8403
8404 if let Some(o) = &self.over {
8405 f.write_str(" OVER ")?;
8406 o.fmt(f)?;
8407 }
8408
8409 if self.uses_odbc_syntax {
8410 write!(f, "}}")?;
8411 }
8412
8413 Ok(())
8414 }
8415}
8416
8417#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8419#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8420#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8421pub enum FunctionArguments {
8422 None,
8425 Subquery(Box<Query>),
8428 List(FunctionArgumentList),
8431}
8432
8433impl fmt::Display for FunctionArguments {
8434 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8435 match self {
8436 FunctionArguments::None => Ok(()),
8437 FunctionArguments::Subquery(query) => write!(f, "({query})"),
8438 FunctionArguments::List(args) => write!(f, "({args})"),
8439 }
8440 }
8441}
8442
8443#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8445#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8446#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8447pub struct FunctionArgumentList {
8448 pub duplicate_treatment: Option<DuplicateTreatment>,
8450 pub args: Vec<FunctionArg>,
8452 pub clauses: Vec<FunctionArgumentClause>,
8454}
8455
8456impl fmt::Display for FunctionArgumentList {
8457 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8458 if let Some(duplicate_treatment) = self.duplicate_treatment {
8459 write!(f, "{duplicate_treatment} ")?;
8460 }
8461 write!(f, "{}", display_comma_separated(&self.args))?;
8462 if !self.clauses.is_empty() {
8463 if !self.args.is_empty() {
8464 write!(f, " ")?;
8465 }
8466 write!(f, "{}", display_separated(&self.clauses, " "))?;
8467 }
8468 Ok(())
8469 }
8470}
8471
8472#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8473#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8474#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8475pub enum FunctionArgumentClause {
8477 IgnoreOrRespectNulls(NullTreatment),
8486 OrderBy(Vec<OrderByExpr>),
8490 Limit(Expr),
8492 OnOverflow(ListAggOnOverflow),
8496 Having(HavingBound),
8505 Separator(ValueWithSpan),
8509 JsonNullClause(JsonNullClause),
8515 JsonReturningClause(JsonReturningClause),
8519}
8520
8521impl fmt::Display for FunctionArgumentClause {
8522 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8523 match self {
8524 FunctionArgumentClause::IgnoreOrRespectNulls(null_treatment) => {
8525 write!(f, "{null_treatment}")
8526 }
8527 FunctionArgumentClause::OrderBy(order_by) => {
8528 write!(f, "ORDER BY {}", display_comma_separated(order_by))
8529 }
8530 FunctionArgumentClause::Limit(limit) => write!(f, "LIMIT {limit}"),
8531 FunctionArgumentClause::OnOverflow(on_overflow) => write!(f, "{on_overflow}"),
8532 FunctionArgumentClause::Having(bound) => write!(f, "{bound}"),
8533 FunctionArgumentClause::Separator(sep) => write!(f, "SEPARATOR {sep}"),
8534 FunctionArgumentClause::JsonNullClause(null_clause) => write!(f, "{null_clause}"),
8535 FunctionArgumentClause::JsonReturningClause(returning_clause) => {
8536 write!(f, "{returning_clause}")
8537 }
8538 }
8539 }
8540}
8541
8542#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8544#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8545#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8546pub struct Method {
8547 pub expr: Box<Expr>,
8549 pub method_chain: Vec<Function>,
8552}
8553
8554impl fmt::Display for Method {
8555 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8556 write!(
8557 f,
8558 "{}.{}",
8559 self.expr,
8560 display_separated(&self.method_chain, ".")
8561 )
8562 }
8563}
8564
8565#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8566#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8567#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8568pub enum DuplicateTreatment {
8570 Distinct,
8572 All,
8574}
8575
8576impl fmt::Display for DuplicateTreatment {
8577 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8578 match self {
8579 DuplicateTreatment::Distinct => write!(f, "DISTINCT"),
8580 DuplicateTreatment::All => write!(f, "ALL"),
8581 }
8582 }
8583}
8584
8585#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8586#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8587#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8588pub enum AnalyzeFormatKind {
8590 Keyword(AnalyzeFormat),
8592 Assignment(AnalyzeFormat),
8594}
8595
8596impl fmt::Display for AnalyzeFormatKind {
8597 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8598 match self {
8599 AnalyzeFormatKind::Keyword(format) => write!(f, "FORMAT {format}"),
8600 AnalyzeFormatKind::Assignment(format) => write!(f, "FORMAT={format}"),
8601 }
8602 }
8603}
8604
8605#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8606#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8607#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8608pub enum AnalyzeFormat {
8610 TEXT,
8612 GRAPHVIZ,
8614 JSON,
8616 TRADITIONAL,
8618 TREE,
8620}
8621
8622impl fmt::Display for AnalyzeFormat {
8623 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8624 f.write_str(match self {
8625 AnalyzeFormat::TEXT => "TEXT",
8626 AnalyzeFormat::GRAPHVIZ => "GRAPHVIZ",
8627 AnalyzeFormat::JSON => "JSON",
8628 AnalyzeFormat::TRADITIONAL => "TRADITIONAL",
8629 AnalyzeFormat::TREE => "TREE",
8630 })
8631 }
8632}
8633
8634#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8636#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8637#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8638pub enum FileFormat {
8639 TEXTFILE,
8641 SEQUENCEFILE,
8643 ORC,
8645 PARQUET,
8647 AVRO,
8649 RCFILE,
8651 JSONFILE,
8653}
8654
8655impl fmt::Display for FileFormat {
8656 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8657 use self::FileFormat::*;
8658 f.write_str(match self {
8659 TEXTFILE => "TEXTFILE",
8660 SEQUENCEFILE => "SEQUENCEFILE",
8661 ORC => "ORC",
8662 PARQUET => "PARQUET",
8663 AVRO => "AVRO",
8664 RCFILE => "RCFILE",
8665 JSONFILE => "JSONFILE",
8666 })
8667 }
8668}
8669
8670#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8672#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8673#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8674pub enum ListAggOnOverflow {
8675 Error,
8677
8678 Truncate {
8680 filler: Option<Box<Expr>>,
8682 with_count: bool,
8684 },
8685}
8686
8687impl fmt::Display for ListAggOnOverflow {
8688 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8689 write!(f, "ON OVERFLOW")?;
8690 match self {
8691 ListAggOnOverflow::Error => write!(f, " ERROR"),
8692 ListAggOnOverflow::Truncate { filler, with_count } => {
8693 write!(f, " TRUNCATE")?;
8694 if let Some(filler) = filler {
8695 write!(f, " {filler}")?;
8696 }
8697 if *with_count {
8698 write!(f, " WITH")?;
8699 } else {
8700 write!(f, " WITHOUT")?;
8701 }
8702 write!(f, " COUNT")
8703 }
8704 }
8705 }
8706}
8707
8708#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8710#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8711#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8712pub struct HavingBound(pub HavingBoundKind, pub Expr);
8713
8714impl fmt::Display for HavingBound {
8715 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8716 write!(f, "HAVING {} {}", self.0, self.1)
8717 }
8718}
8719
8720#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8721#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8722#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8723pub enum HavingBoundKind {
8725 Min,
8727 Max,
8729}
8730
8731impl fmt::Display for HavingBoundKind {
8732 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8733 match self {
8734 HavingBoundKind::Min => write!(f, "MIN"),
8735 HavingBoundKind::Max => write!(f, "MAX"),
8736 }
8737 }
8738}
8739
8740#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8741#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8742#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8743pub enum ObjectType {
8745 Collation,
8747 Table,
8749 View,
8751 MaterializedView,
8753 Index,
8755 Schema,
8757 Database,
8759 Role,
8761 Sequence,
8763 Stage,
8765 Type,
8767 User,
8769 Stream,
8771}
8772
8773impl fmt::Display for ObjectType {
8774 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8775 f.write_str(match self {
8776 ObjectType::Collation => "COLLATION",
8777 ObjectType::Table => "TABLE",
8778 ObjectType::View => "VIEW",
8779 ObjectType::MaterializedView => "MATERIALIZED VIEW",
8780 ObjectType::Index => "INDEX",
8781 ObjectType::Schema => "SCHEMA",
8782 ObjectType::Database => "DATABASE",
8783 ObjectType::Role => "ROLE",
8784 ObjectType::Sequence => "SEQUENCE",
8785 ObjectType::Stage => "STAGE",
8786 ObjectType::Type => "TYPE",
8787 ObjectType::User => "USER",
8788 ObjectType::Stream => "STREAM",
8789 })
8790 }
8791}
8792
8793#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8794#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8795#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8796pub enum KillType {
8798 Connection,
8800 Query,
8802 Mutation,
8804}
8805
8806impl fmt::Display for KillType {
8807 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8808 f.write_str(match self {
8809 KillType::Connection => "CONNECTION",
8811 KillType::Query => "QUERY",
8812 KillType::Mutation => "MUTATION",
8814 })
8815 }
8816}
8817
8818#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8819#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8820#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8821pub enum HiveDistributionStyle {
8823 PARTITIONED {
8825 columns: Vec<ColumnDef>,
8827 },
8828 SKEWED {
8830 columns: Vec<ColumnDef>,
8832 on: Vec<ColumnDef>,
8834 stored_as_directories: bool,
8836 },
8837 NONE,
8839}
8840
8841#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8842#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8843#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8844pub enum HiveRowFormat {
8846 SERDE {
8848 class: String,
8850 },
8851 DELIMITED {
8853 delimiters: Vec<HiveRowDelimiter>,
8855 },
8856}
8857
8858#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8859#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8860#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8861pub struct HiveLoadDataFormat {
8863 pub serde: Expr,
8865 pub input_format: Expr,
8867}
8868
8869#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8870#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8871#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8872pub struct HiveRowDelimiter {
8874 pub delimiter: HiveDelimiter,
8876 pub char: Ident,
8878}
8879
8880impl fmt::Display for HiveRowDelimiter {
8881 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8882 write!(f, "{} ", self.delimiter)?;
8883 write!(f, "{}", self.char)
8884 }
8885}
8886
8887#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8888#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8889#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8890pub enum HiveDelimiter {
8892 FieldsTerminatedBy,
8894 FieldsEscapedBy,
8896 CollectionItemsTerminatedBy,
8898 MapKeysTerminatedBy,
8900 LinesTerminatedBy,
8902 NullDefinedAs,
8904}
8905
8906impl fmt::Display for HiveDelimiter {
8907 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8908 use HiveDelimiter::*;
8909 f.write_str(match self {
8910 FieldsTerminatedBy => "FIELDS TERMINATED BY",
8911 FieldsEscapedBy => "ESCAPED BY",
8912 CollectionItemsTerminatedBy => "COLLECTION ITEMS TERMINATED BY",
8913 MapKeysTerminatedBy => "MAP KEYS TERMINATED BY",
8914 LinesTerminatedBy => "LINES TERMINATED BY",
8915 NullDefinedAs => "NULL DEFINED AS",
8916 })
8917 }
8918}
8919
8920#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8921#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8922#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8923pub enum HiveDescribeFormat {
8925 Extended,
8927 Formatted,
8929}
8930
8931impl fmt::Display for HiveDescribeFormat {
8932 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8933 use HiveDescribeFormat::*;
8934 f.write_str(match self {
8935 Extended => "EXTENDED",
8936 Formatted => "FORMATTED",
8937 })
8938 }
8939}
8940
8941#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8942#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8943#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8944pub enum DescribeAlias {
8946 Describe,
8948 Explain,
8950 Desc,
8952}
8953
8954impl fmt::Display for DescribeAlias {
8955 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8956 use DescribeAlias::*;
8957 f.write_str(match self {
8958 Describe => "DESCRIBE",
8959 Explain => "EXPLAIN",
8960 Desc => "DESC",
8961 })
8962 }
8963}
8964
8965#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8966#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8967#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8968#[allow(clippy::large_enum_variant)]
8969pub enum HiveIOFormat {
8971 IOF {
8973 input_format: Expr,
8975 output_format: Expr,
8977 },
8978 FileFormat {
8980 format: FileFormat,
8982 },
8983}
8984
8985#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
8986#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8987#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8988pub struct HiveFormat {
8990 pub row_format: Option<HiveRowFormat>,
8992 pub serde_properties: Option<Vec<SqlOption>>,
8994 pub storage: Option<HiveIOFormat>,
8996 pub location: Option<String>,
8998}
8999
9000#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9001#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9002#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9003pub struct ClusteredIndex {
9005 pub name: Ident,
9007 pub asc: Option<bool>,
9009}
9010
9011impl fmt::Display for ClusteredIndex {
9012 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9013 write!(f, "{}", self.name)?;
9014 match self.asc {
9015 Some(true) => write!(f, " ASC"),
9016 Some(false) => write!(f, " DESC"),
9017 _ => Ok(()),
9018 }
9019 }
9020}
9021
9022#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9023#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9024#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9025pub enum TableOptionsClustered {
9027 ColumnstoreIndex,
9029 ColumnstoreIndexOrder(Vec<Ident>),
9031 Index(Vec<ClusteredIndex>),
9033}
9034
9035impl fmt::Display for TableOptionsClustered {
9036 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9037 match self {
9038 TableOptionsClustered::ColumnstoreIndex => {
9039 write!(f, "CLUSTERED COLUMNSTORE INDEX")
9040 }
9041 TableOptionsClustered::ColumnstoreIndexOrder(values) => {
9042 write!(
9043 f,
9044 "CLUSTERED COLUMNSTORE INDEX ORDER ({})",
9045 display_comma_separated(values)
9046 )
9047 }
9048 TableOptionsClustered::Index(values) => {
9049 write!(f, "CLUSTERED INDEX ({})", display_comma_separated(values))
9050 }
9051 }
9052 }
9053}
9054
9055#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
9057#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9058#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9059pub enum PartitionRangeDirection {
9060 Left,
9062 Right,
9064}
9065
9066#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9067#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9068#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9069pub enum SqlOption {
9071 Clustered(TableOptionsClustered),
9075 Ident(Ident),
9079 KeyValue {
9083 key: Ident,
9085 value: Expr,
9087 },
9088 Partition {
9095 column_name: Ident,
9097 range_direction: Option<PartitionRangeDirection>,
9099 for_values: Vec<Expr>,
9101 },
9102 Comment(CommentDef),
9104 TableSpace(TablespaceOption),
9107 NamedParenthesizedList(NamedParenthesizedList),
9114}
9115
9116impl fmt::Display for SqlOption {
9117 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9118 match self {
9119 SqlOption::Clustered(c) => write!(f, "{c}"),
9120 SqlOption::Ident(ident) => {
9121 write!(f, "{ident}")
9122 }
9123 SqlOption::KeyValue { key: name, value } => {
9124 write!(f, "{name} = {value}")
9125 }
9126 SqlOption::Partition {
9127 column_name,
9128 range_direction,
9129 for_values,
9130 } => {
9131 let direction = match range_direction {
9132 Some(PartitionRangeDirection::Left) => " LEFT",
9133 Some(PartitionRangeDirection::Right) => " RIGHT",
9134 None => "",
9135 };
9136
9137 write!(
9138 f,
9139 "PARTITION ({} RANGE{} FOR VALUES ({}))",
9140 column_name,
9141 direction,
9142 display_comma_separated(for_values)
9143 )
9144 }
9145 SqlOption::TableSpace(tablespace_option) => {
9146 write!(f, "TABLESPACE {}", tablespace_option.name)?;
9147 match tablespace_option.storage {
9148 Some(StorageType::Disk) => write!(f, " STORAGE DISK"),
9149 Some(StorageType::Memory) => write!(f, " STORAGE MEMORY"),
9150 None => Ok(()),
9151 }
9152 }
9153 SqlOption::Comment(comment) => match comment {
9154 CommentDef::WithEq(comment) => {
9155 write!(f, "COMMENT = '{comment}'")
9156 }
9157 CommentDef::WithoutEq(comment) => {
9158 write!(f, "COMMENT '{comment}'")
9159 }
9160 },
9161 SqlOption::NamedParenthesizedList(value) => {
9162 write!(f, "{} = ", value.key)?;
9163 if let Some(key) = &value.name {
9164 write!(f, "{key}")?;
9165 }
9166 if !value.values.is_empty() {
9167 write!(f, "({})", display_comma_separated(&value.values))?
9168 }
9169 Ok(())
9170 }
9171 }
9172 }
9173}
9174
9175#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
9176#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9177#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9178pub enum StorageType {
9180 Disk,
9182 Memory,
9184}
9185
9186#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
9187#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9188#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9189pub struct TablespaceOption {
9192 pub name: String,
9194 pub storage: Option<StorageType>,
9196}
9197
9198#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9199#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9200#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9201pub struct SecretOption {
9203 pub key: Ident,
9205 pub value: Ident,
9207}
9208
9209impl fmt::Display for SecretOption {
9210 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9211 write!(f, "{} {}", self.key, self.value)
9212 }
9213}
9214
9215#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9219#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9220#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9221pub struct CreateServerStatement {
9222 pub name: ObjectName,
9224 pub if_not_exists: bool,
9226 pub server_type: Option<Ident>,
9228 pub version: Option<Ident>,
9230 pub foreign_data_wrapper: ObjectName,
9232 pub options: Option<Vec<CreateServerOption>>,
9234}
9235
9236impl fmt::Display for CreateServerStatement {
9237 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9238 let CreateServerStatement {
9239 name,
9240 if_not_exists,
9241 server_type,
9242 version,
9243 foreign_data_wrapper,
9244 options,
9245 } = self;
9246
9247 write!(
9248 f,
9249 "CREATE SERVER {if_not_exists}{name} ",
9250 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
9251 )?;
9252
9253 if let Some(st) = server_type {
9254 write!(f, "TYPE {st} ")?;
9255 }
9256
9257 if let Some(v) = version {
9258 write!(f, "VERSION {v} ")?;
9259 }
9260
9261 write!(f, "FOREIGN DATA WRAPPER {foreign_data_wrapper}")?;
9262
9263 if let Some(o) = options {
9264 write!(f, " OPTIONS ({o})", o = display_comma_separated(o))?;
9265 }
9266
9267 Ok(())
9268 }
9269}
9270
9271#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9273#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9274#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9275pub struct CreateServerOption {
9276 pub key: Ident,
9278 pub value: Ident,
9280}
9281
9282impl fmt::Display for CreateServerOption {
9283 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9284 write!(f, "{} {}", self.key, self.value)
9285 }
9286}
9287
9288#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9289#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9290#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9291pub enum AttachDuckDBDatabaseOption {
9293 ReadOnly(Option<bool>),
9295 Type(Ident),
9297}
9298
9299impl fmt::Display for AttachDuckDBDatabaseOption {
9300 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9301 match self {
9302 AttachDuckDBDatabaseOption::ReadOnly(Some(true)) => write!(f, "READ_ONLY true"),
9303 AttachDuckDBDatabaseOption::ReadOnly(Some(false)) => write!(f, "READ_ONLY false"),
9304 AttachDuckDBDatabaseOption::ReadOnly(None) => write!(f, "READ_ONLY"),
9305 AttachDuckDBDatabaseOption::Type(t) => write!(f, "TYPE {t}"),
9306 }
9307 }
9308}
9309
9310#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9311#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9312#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9313pub enum TransactionMode {
9315 AccessMode(TransactionAccessMode),
9317 IsolationLevel(TransactionIsolationLevel),
9319}
9320
9321impl fmt::Display for TransactionMode {
9322 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9323 use TransactionMode::*;
9324 match self {
9325 AccessMode(access_mode) => write!(f, "{access_mode}"),
9326 IsolationLevel(iso_level) => write!(f, "ISOLATION LEVEL {iso_level}"),
9327 }
9328 }
9329}
9330
9331#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9332#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9333#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9334pub enum TransactionAccessMode {
9336 ReadOnly,
9338 ReadWrite,
9340}
9341
9342impl fmt::Display for TransactionAccessMode {
9343 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9344 use TransactionAccessMode::*;
9345 f.write_str(match self {
9346 ReadOnly => "READ ONLY",
9347 ReadWrite => "READ WRITE",
9348 })
9349 }
9350}
9351
9352#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9353#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9354#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9355pub enum TransactionIsolationLevel {
9357 ReadUncommitted,
9359 ReadCommitted,
9361 RepeatableRead,
9363 Serializable,
9365 Snapshot,
9367}
9368
9369impl fmt::Display for TransactionIsolationLevel {
9370 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9371 use TransactionIsolationLevel::*;
9372 f.write_str(match self {
9373 ReadUncommitted => "READ UNCOMMITTED",
9374 ReadCommitted => "READ COMMITTED",
9375 RepeatableRead => "REPEATABLE READ",
9376 Serializable => "SERIALIZABLE",
9377 Snapshot => "SNAPSHOT",
9378 })
9379 }
9380}
9381
9382#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9387#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9388#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9389pub enum TransactionModifier {
9390 Deferred,
9392 Immediate,
9394 Exclusive,
9396 Try,
9398 Catch,
9400}
9401
9402impl fmt::Display for TransactionModifier {
9403 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9404 use TransactionModifier::*;
9405 f.write_str(match self {
9406 Deferred => "DEFERRED",
9407 Immediate => "IMMEDIATE",
9408 Exclusive => "EXCLUSIVE",
9409 Try => "TRY",
9410 Catch => "CATCH",
9411 })
9412 }
9413}
9414
9415#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9416#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9417#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9418pub enum ShowStatementFilter {
9420 Like(String),
9422 ILike(String),
9424 Where(Expr),
9426 NoKeyword(String),
9428}
9429
9430impl fmt::Display for ShowStatementFilter {
9431 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9432 use ShowStatementFilter::*;
9433 match self {
9434 Like(pattern) => write!(f, "LIKE '{}'", value::escape_single_quote_string(pattern)),
9435 ILike(pattern) => write!(f, "ILIKE {}", value::escape_single_quote_string(pattern)),
9436 Where(expr) => write!(f, "WHERE {expr}"),
9437 NoKeyword(pattern) => write!(f, "'{}'", value::escape_single_quote_string(pattern)),
9438 }
9439 }
9440}
9441
9442#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9443#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9444#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9445pub enum ShowStatementInClause {
9447 IN,
9449 FROM,
9451}
9452
9453impl fmt::Display for ShowStatementInClause {
9454 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9455 use ShowStatementInClause::*;
9456 match self {
9457 FROM => write!(f, "FROM"),
9458 IN => write!(f, "IN"),
9459 }
9460 }
9461}
9462
9463#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9468#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9469#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9470pub enum SqliteOnConflict {
9471 Rollback,
9473 Abort,
9475 Fail,
9477 Ignore,
9479 Replace,
9481}
9482
9483impl fmt::Display for SqliteOnConflict {
9484 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9485 use SqliteOnConflict::*;
9486 match self {
9487 Rollback => write!(f, "OR ROLLBACK"),
9488 Abort => write!(f, "OR ABORT"),
9489 Fail => write!(f, "OR FAIL"),
9490 Ignore => write!(f, "OR IGNORE"),
9491 Replace => write!(f, "OR REPLACE"),
9492 }
9493 }
9494}
9495
9496#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9502#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9503#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9504pub enum MysqlInsertPriority {
9505 LowPriority,
9507 Delayed,
9509 HighPriority,
9511}
9512
9513impl fmt::Display for crate::ast::MysqlInsertPriority {
9514 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9515 use MysqlInsertPriority::*;
9516 match self {
9517 LowPriority => write!(f, "LOW_PRIORITY"),
9518 Delayed => write!(f, "DELAYED"),
9519 HighPriority => write!(f, "HIGH_PRIORITY"),
9520 }
9521 }
9522}
9523
9524#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9525#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9526#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9527pub enum CopySource {
9529 Table {
9531 table_name: ObjectName,
9533 columns: Vec<Ident>,
9536 },
9537 Query(Box<Query>),
9539}
9540
9541#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9542#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9543#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9544pub enum CopyTarget {
9546 Stdin,
9548 Stdout,
9550 File {
9552 filename: String,
9554 },
9555 Program {
9557 command: String,
9559 },
9560}
9561
9562impl fmt::Display for CopyTarget {
9563 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9564 use CopyTarget::*;
9565 match self {
9566 Stdin => write!(f, "STDIN"),
9567 Stdout => write!(f, "STDOUT"),
9568 File { filename } => write!(f, "'{}'", value::escape_single_quote_string(filename)),
9569 Program { command } => write!(
9570 f,
9571 "PROGRAM '{}'",
9572 value::escape_single_quote_string(command)
9573 ),
9574 }
9575 }
9576}
9577
9578#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9579#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9580#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9581pub enum OnCommit {
9583 DeleteRows,
9585 PreserveRows,
9587 Drop,
9589}
9590
9591#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9595#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9596#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9597pub enum CopyOption {
9598 Format(Ident),
9600 Freeze(bool),
9602 Delimiter(char),
9604 Null(String),
9606 Header(bool),
9608 Quote(char),
9610 Escape(char),
9612 ForceQuote(Vec<Ident>),
9614 ForceNotNull(Vec<Ident>),
9616 ForceNull(Vec<Ident>),
9618 Encoding(String),
9620}
9621
9622impl fmt::Display for CopyOption {
9623 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9624 use CopyOption::*;
9625 match self {
9626 Format(name) => write!(f, "FORMAT {name}"),
9627 Freeze(true) => write!(f, "FREEZE"),
9628 Freeze(false) => write!(f, "FREEZE FALSE"),
9629 Delimiter(char) => write!(f, "DELIMITER '{char}'"),
9630 Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)),
9631 Header(true) => write!(f, "HEADER"),
9632 Header(false) => write!(f, "HEADER FALSE"),
9633 Quote(char) => write!(f, "QUOTE '{char}'"),
9634 Escape(char) => write!(f, "ESCAPE '{char}'"),
9635 ForceQuote(columns) => write!(f, "FORCE_QUOTE ({})", display_comma_separated(columns)),
9636 ForceNotNull(columns) => {
9637 write!(f, "FORCE_NOT_NULL ({})", display_comma_separated(columns))
9638 }
9639 ForceNull(columns) => write!(f, "FORCE_NULL ({})", display_comma_separated(columns)),
9640 Encoding(name) => write!(f, "ENCODING '{}'", value::escape_single_quote_string(name)),
9641 }
9642 }
9643}
9644
9645#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9650#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9651#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9652pub enum CopyLegacyOption {
9653 AcceptAnyDate,
9655 AcceptInvChars(Option<String>),
9657 AddQuotes,
9659 AllowOverwrite,
9661 Binary,
9663 BlankAsNull,
9665 Bzip2,
9667 CleanPath,
9669 CompUpdate {
9671 preset: bool,
9673 enabled: Option<bool>,
9675 },
9676 Csv(Vec<CopyLegacyCsvOption>),
9678 DateFormat(Option<String>),
9680 Delimiter(char),
9682 EmptyAsNull,
9684 Encrypted {
9686 auto: bool,
9688 },
9689 Escape,
9691 Extension(String),
9693 FixedWidth(String),
9695 Gzip,
9697 Header,
9699 IamRole(IamRoleKind),
9701 IgnoreHeader(u64),
9703 Json(Option<String>),
9705 Manifest {
9707 verbose: bool,
9709 },
9710 MaxFileSize(FileSize),
9712 Null(String),
9714 Parallel(Option<bool>),
9716 Parquet,
9718 PartitionBy(UnloadPartitionBy),
9720 Region(String),
9722 RemoveQuotes,
9724 RowGroupSize(FileSize),
9726 StatUpdate(Option<bool>),
9728 TimeFormat(Option<String>),
9730 TruncateColumns,
9732 Zstd,
9734 Credentials(String),
9737}
9738
9739impl fmt::Display for CopyLegacyOption {
9740 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9741 use CopyLegacyOption::*;
9742 match self {
9743 AcceptAnyDate => write!(f, "ACCEPTANYDATE"),
9744 AcceptInvChars(ch) => {
9745 write!(f, "ACCEPTINVCHARS")?;
9746 if let Some(ch) = ch {
9747 write!(f, " '{}'", value::escape_single_quote_string(ch))?;
9748 }
9749 Ok(())
9750 }
9751 AddQuotes => write!(f, "ADDQUOTES"),
9752 AllowOverwrite => write!(f, "ALLOWOVERWRITE"),
9753 Binary => write!(f, "BINARY"),
9754 BlankAsNull => write!(f, "BLANKSASNULL"),
9755 Bzip2 => write!(f, "BZIP2"),
9756 CleanPath => write!(f, "CLEANPATH"),
9757 CompUpdate { preset, enabled } => {
9758 write!(f, "COMPUPDATE")?;
9759 if *preset {
9760 write!(f, " PRESET")?;
9761 } else if let Some(enabled) = enabled {
9762 write!(
9763 f,
9764 "{}",
9765 match enabled {
9766 true => " TRUE",
9767 false => " FALSE",
9768 }
9769 )?;
9770 }
9771 Ok(())
9772 }
9773 Csv(opts) => {
9774 write!(f, "CSV")?;
9775 if !opts.is_empty() {
9776 write!(f, " {}", display_separated(opts, " "))?;
9777 }
9778 Ok(())
9779 }
9780 DateFormat(fmt) => {
9781 write!(f, "DATEFORMAT")?;
9782 if let Some(fmt) = fmt {
9783 write!(f, " '{}'", value::escape_single_quote_string(fmt))?;
9784 }
9785 Ok(())
9786 }
9787 Delimiter(char) => write!(f, "DELIMITER '{char}'"),
9788 EmptyAsNull => write!(f, "EMPTYASNULL"),
9789 Encrypted { auto } => write!(f, "ENCRYPTED{}", if *auto { " AUTO" } else { "" }),
9790 Escape => write!(f, "ESCAPE"),
9791 Extension(ext) => write!(f, "EXTENSION '{}'", value::escape_single_quote_string(ext)),
9792 FixedWidth(spec) => write!(
9793 f,
9794 "FIXEDWIDTH '{}'",
9795 value::escape_single_quote_string(spec)
9796 ),
9797 Gzip => write!(f, "GZIP"),
9798 Header => write!(f, "HEADER"),
9799 IamRole(role) => write!(f, "IAM_ROLE {role}"),
9800 IgnoreHeader(num_rows) => write!(f, "IGNOREHEADER {num_rows}"),
9801 Json(opt) => {
9802 write!(f, "JSON")?;
9803 if let Some(opt) = opt {
9804 write!(f, " AS '{}'", value::escape_single_quote_string(opt))?;
9805 }
9806 Ok(())
9807 }
9808 Manifest { verbose } => write!(f, "MANIFEST{}", if *verbose { " VERBOSE" } else { "" }),
9809 MaxFileSize(file_size) => write!(f, "MAXFILESIZE {file_size}"),
9810 Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)),
9811 Parallel(enabled) => {
9812 write!(
9813 f,
9814 "PARALLEL{}",
9815 match enabled {
9816 Some(true) => " TRUE",
9817 Some(false) => " FALSE",
9818 _ => "",
9819 }
9820 )
9821 }
9822 Parquet => write!(f, "PARQUET"),
9823 PartitionBy(p) => write!(f, "{p}"),
9824 Region(region) => write!(f, "REGION '{}'", value::escape_single_quote_string(region)),
9825 RemoveQuotes => write!(f, "REMOVEQUOTES"),
9826 RowGroupSize(file_size) => write!(f, "ROWGROUPSIZE {file_size}"),
9827 StatUpdate(enabled) => {
9828 write!(
9829 f,
9830 "STATUPDATE{}",
9831 match enabled {
9832 Some(true) => " TRUE",
9833 Some(false) => " FALSE",
9834 _ => "",
9835 }
9836 )
9837 }
9838 TimeFormat(fmt) => {
9839 write!(f, "TIMEFORMAT")?;
9840 if let Some(fmt) = fmt {
9841 write!(f, " '{}'", value::escape_single_quote_string(fmt))?;
9842 }
9843 Ok(())
9844 }
9845 TruncateColumns => write!(f, "TRUNCATECOLUMNS"),
9846 Zstd => write!(f, "ZSTD"),
9847 Credentials(s) => write!(f, "CREDENTIALS '{}'", value::escape_single_quote_string(s)),
9848 }
9849 }
9850}
9851
9852#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9856#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9857#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9858pub struct FileSize {
9859 pub size: ValueWithSpan,
9861 pub unit: Option<FileSizeUnit>,
9863}
9864
9865impl fmt::Display for FileSize {
9866 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9867 write!(f, "{}", self.size)?;
9868 if let Some(unit) = &self.unit {
9869 write!(f, " {unit}")?;
9870 }
9871 Ok(())
9872 }
9873}
9874
9875#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9877#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9878#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9879pub enum FileSizeUnit {
9880 MB,
9882 GB,
9884}
9885
9886impl fmt::Display for FileSizeUnit {
9887 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9888 match self {
9889 FileSizeUnit::MB => write!(f, "MB"),
9890 FileSizeUnit::GB => write!(f, "GB"),
9891 }
9892 }
9893}
9894
9895#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9901#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9902#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9903pub struct UnloadPartitionBy {
9904 pub columns: Vec<Ident>,
9906 pub include: bool,
9908}
9909
9910impl fmt::Display for UnloadPartitionBy {
9911 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9912 write!(
9913 f,
9914 "PARTITION BY ({}){}",
9915 display_comma_separated(&self.columns),
9916 if self.include { " INCLUDE" } else { "" }
9917 )
9918 }
9919}
9920
9921#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9925#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9926#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9927pub enum IamRoleKind {
9928 Default,
9930 Arn(String),
9932}
9933
9934impl fmt::Display for IamRoleKind {
9935 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9936 match self {
9937 IamRoleKind::Default => write!(f, "DEFAULT"),
9938 IamRoleKind::Arn(arn) => write!(f, "'{arn}'"),
9939 }
9940 }
9941}
9942
9943#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9947#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9948#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9949pub enum CopyLegacyCsvOption {
9950 Header,
9952 Quote(char),
9954 Escape(char),
9956 ForceQuote(Vec<Ident>),
9958 ForceNotNull(Vec<Ident>),
9960}
9961
9962impl fmt::Display for CopyLegacyCsvOption {
9963 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9964 use CopyLegacyCsvOption::*;
9965 match self {
9966 Header => write!(f, "HEADER"),
9967 Quote(char) => write!(f, "QUOTE '{char}'"),
9968 Escape(char) => write!(f, "ESCAPE '{char}'"),
9969 ForceQuote(columns) => write!(f, "FORCE QUOTE {}", display_comma_separated(columns)),
9970 ForceNotNull(columns) => {
9971 write!(f, "FORCE NOT NULL {}", display_comma_separated(columns))
9972 }
9973 }
9974 }
9975}
9976
9977#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9979#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9980#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9981pub enum DiscardObject {
9982 ALL,
9984 PLANS,
9986 SEQUENCES,
9988 TEMP,
9990}
9991
9992impl fmt::Display for DiscardObject {
9993 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9994 match self {
9995 DiscardObject::ALL => f.write_str("ALL"),
9996 DiscardObject::PLANS => f.write_str("PLANS"),
9997 DiscardObject::SEQUENCES => f.write_str("SEQUENCES"),
9998 DiscardObject::TEMP => f.write_str("TEMP"),
9999 }
10000 }
10001}
10002
10003#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10005#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10006#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10007pub enum FlushType {
10008 BinaryLogs,
10010 EngineLogs,
10012 ErrorLogs,
10014 GeneralLogs,
10016 Hosts,
10018 Logs,
10020 Privileges,
10022 OptimizerCosts,
10024 RelayLogs,
10026 SlowLogs,
10028 Status,
10030 UserResources,
10032 Tables,
10034}
10035
10036impl fmt::Display for FlushType {
10037 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10038 match self {
10039 FlushType::BinaryLogs => f.write_str("BINARY LOGS"),
10040 FlushType::EngineLogs => f.write_str("ENGINE LOGS"),
10041 FlushType::ErrorLogs => f.write_str("ERROR LOGS"),
10042 FlushType::GeneralLogs => f.write_str("GENERAL LOGS"),
10043 FlushType::Hosts => f.write_str("HOSTS"),
10044 FlushType::Logs => f.write_str("LOGS"),
10045 FlushType::Privileges => f.write_str("PRIVILEGES"),
10046 FlushType::OptimizerCosts => f.write_str("OPTIMIZER_COSTS"),
10047 FlushType::RelayLogs => f.write_str("RELAY LOGS"),
10048 FlushType::SlowLogs => f.write_str("SLOW LOGS"),
10049 FlushType::Status => f.write_str("STATUS"),
10050 FlushType::UserResources => f.write_str("USER_RESOURCES"),
10051 FlushType::Tables => f.write_str("TABLES"),
10052 }
10053 }
10054}
10055
10056#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10058#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10059#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10060pub enum FlushLocation {
10061 NoWriteToBinlog,
10063 Local,
10065}
10066
10067impl fmt::Display for FlushLocation {
10068 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10069 match self {
10070 FlushLocation::NoWriteToBinlog => f.write_str("NO_WRITE_TO_BINLOG"),
10071 FlushLocation::Local => f.write_str("LOCAL"),
10072 }
10073 }
10074}
10075
10076#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10078#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10079#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10080pub enum ContextModifier {
10081 Local,
10083 Session,
10085 Global,
10087}
10088
10089impl fmt::Display for ContextModifier {
10090 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10091 match self {
10092 Self::Local => {
10093 write!(f, "LOCAL ")
10094 }
10095 Self::Session => {
10096 write!(f, "SESSION ")
10097 }
10098 Self::Global => {
10099 write!(f, "GLOBAL ")
10100 }
10101 }
10102 }
10103}
10104
10105#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10107#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10108pub enum DropFunctionOption {
10109 Restrict,
10111 Cascade,
10113}
10114
10115impl fmt::Display for DropFunctionOption {
10116 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10117 match self {
10118 DropFunctionOption::Restrict => write!(f, "RESTRICT "),
10119 DropFunctionOption::Cascade => write!(f, "CASCADE "),
10120 }
10121 }
10122}
10123
10124#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10126#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10127#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10128pub struct FunctionDesc {
10129 pub name: ObjectName,
10131 pub args: Option<Vec<OperateFunctionArg>>,
10133}
10134
10135impl fmt::Display for FunctionDesc {
10136 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10137 write!(f, "{}", self.name)?;
10138 if let Some(args) = &self.args {
10139 write!(f, "({})", display_comma_separated(args))?;
10140 }
10141 Ok(())
10142 }
10143}
10144
10145#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10147#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10148#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10149pub struct OperateFunctionArg {
10150 pub mode: Option<ArgMode>,
10152 pub name: Option<Ident>,
10154 pub data_type: DataType,
10156 pub default_expr: Option<Expr>,
10158}
10159
10160impl OperateFunctionArg {
10161 pub fn unnamed(data_type: DataType) -> Self {
10163 Self {
10164 mode: None,
10165 name: None,
10166 data_type,
10167 default_expr: None,
10168 }
10169 }
10170
10171 pub fn with_name(name: &str, data_type: DataType) -> Self {
10173 Self {
10174 mode: None,
10175 name: Some(name.into()),
10176 data_type,
10177 default_expr: None,
10178 }
10179 }
10180}
10181
10182impl fmt::Display for OperateFunctionArg {
10183 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10184 if let Some(mode) = &self.mode {
10185 write!(f, "{mode} ")?;
10186 }
10187 if let Some(name) = &self.name {
10188 write!(f, "{name} ")?;
10189 }
10190 write!(f, "{}", self.data_type)?;
10191 if let Some(default_expr) = &self.default_expr {
10192 write!(f, " = {default_expr}")?;
10193 }
10194 Ok(())
10195 }
10196}
10197
10198#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10200#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10201#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10202pub enum ArgMode {
10203 In,
10205 Out,
10207 InOut,
10209 Variadic,
10211}
10212
10213impl fmt::Display for ArgMode {
10214 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10215 match self {
10216 ArgMode::In => write!(f, "IN"),
10217 ArgMode::Out => write!(f, "OUT"),
10218 ArgMode::InOut => write!(f, "INOUT"),
10219 ArgMode::Variadic => write!(f, "VARIADIC"),
10220 }
10221 }
10222}
10223
10224#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10226#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10227#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10228pub enum FunctionBehavior {
10229 Immutable,
10231 Stable,
10233 Volatile,
10235}
10236
10237impl fmt::Display for FunctionBehavior {
10238 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10239 match self {
10240 FunctionBehavior::Immutable => write!(f, "IMMUTABLE"),
10241 FunctionBehavior::Stable => write!(f, "STABLE"),
10242 FunctionBehavior::Volatile => write!(f, "VOLATILE"),
10243 }
10244 }
10245}
10246
10247#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10251#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10252#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10253pub enum FunctionSecurity {
10254 Definer,
10256 Invoker,
10258}
10259
10260impl fmt::Display for FunctionSecurity {
10261 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10262 match self {
10263 FunctionSecurity::Definer => write!(f, "SECURITY DEFINER"),
10264 FunctionSecurity::Invoker => write!(f, "SECURITY INVOKER"),
10265 }
10266 }
10267}
10268
10269#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10273#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10274#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10275pub enum FunctionSetValue {
10276 Default,
10278 Values(Vec<Expr>),
10280 FromCurrent,
10282}
10283
10284#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10288#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10289#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10290pub struct FunctionDefinitionSetParam {
10291 pub name: ObjectName,
10293 pub value: FunctionSetValue,
10295}
10296
10297impl fmt::Display for FunctionDefinitionSetParam {
10298 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10299 write!(f, "SET {} ", self.name)?;
10300 match &self.value {
10301 FunctionSetValue::Default => write!(f, "= DEFAULT"),
10302 FunctionSetValue::Values(values) => {
10303 write!(f, "= {}", display_comma_separated(values))
10304 }
10305 FunctionSetValue::FromCurrent => write!(f, "FROM CURRENT"),
10306 }
10307 }
10308}
10309
10310#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10312#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10313#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10314pub enum FunctionCalledOnNull {
10315 CalledOnNullInput,
10317 ReturnsNullOnNullInput,
10319 Strict,
10321}
10322
10323impl fmt::Display for FunctionCalledOnNull {
10324 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10325 match self {
10326 FunctionCalledOnNull::CalledOnNullInput => write!(f, "CALLED ON NULL INPUT"),
10327 FunctionCalledOnNull::ReturnsNullOnNullInput => write!(f, "RETURNS NULL ON NULL INPUT"),
10328 FunctionCalledOnNull::Strict => write!(f, "STRICT"),
10329 }
10330 }
10331}
10332
10333#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10335#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10336#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10337pub enum FunctionParallel {
10338 Unsafe,
10340 Restricted,
10342 Safe,
10344}
10345
10346impl fmt::Display for FunctionParallel {
10347 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10348 match self {
10349 FunctionParallel::Unsafe => write!(f, "PARALLEL UNSAFE"),
10350 FunctionParallel::Restricted => write!(f, "PARALLEL RESTRICTED"),
10351 FunctionParallel::Safe => write!(f, "PARALLEL SAFE"),
10352 }
10353 }
10354}
10355
10356#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10360#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10361#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10362pub enum FunctionDeterminismSpecifier {
10363 Deterministic,
10365 NotDeterministic,
10367}
10368
10369impl fmt::Display for FunctionDeterminismSpecifier {
10370 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10371 match self {
10372 FunctionDeterminismSpecifier::Deterministic => {
10373 write!(f, "DETERMINISTIC")
10374 }
10375 FunctionDeterminismSpecifier::NotDeterministic => {
10376 write!(f, "NOT DETERMINISTIC")
10377 }
10378 }
10379 }
10380}
10381
10382#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10389#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10390#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10391pub enum CreateFunctionBody {
10392 AsBeforeOptions {
10405 body: Expr,
10407 link_symbol: Option<Expr>,
10416 },
10417 AsAfterOptions(Expr),
10429 AsBeginEnd(BeginEndStatements),
10445 Return(Expr),
10456
10457 AsReturnExpr(Expr),
10468
10469 AsReturnSelect(Select),
10480}
10481
10482#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10483#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10484#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10485pub enum CreateFunctionUsing {
10487 Jar(String),
10489 File(String),
10491 Archive(String),
10493}
10494
10495impl fmt::Display for CreateFunctionUsing {
10496 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10497 write!(f, "USING ")?;
10498 match self {
10499 CreateFunctionUsing::Jar(uri) => write!(f, "JAR '{uri}'"),
10500 CreateFunctionUsing::File(uri) => write!(f, "FILE '{uri}'"),
10501 CreateFunctionUsing::Archive(uri) => write!(f, "ARCHIVE '{uri}'"),
10502 }
10503 }
10504}
10505
10506#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10511#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10512#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10513pub struct MacroArg {
10514 pub name: Ident,
10516 pub default_expr: Option<Expr>,
10518}
10519
10520impl MacroArg {
10521 pub fn new(name: &str) -> Self {
10523 Self {
10524 name: name.into(),
10525 default_expr: None,
10526 }
10527 }
10528}
10529
10530impl fmt::Display for MacroArg {
10531 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10532 write!(f, "{}", self.name)?;
10533 if let Some(default_expr) = &self.default_expr {
10534 write!(f, " := {default_expr}")?;
10535 }
10536 Ok(())
10537 }
10538}
10539
10540#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10541#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10542#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10543pub enum MacroDefinition {
10545 Expr(Expr),
10547 Table(Box<Query>),
10549}
10550
10551impl fmt::Display for MacroDefinition {
10552 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10553 match self {
10554 MacroDefinition::Expr(expr) => write!(f, "{expr}")?,
10555 MacroDefinition::Table(query) => write!(f, "{query}")?,
10556 }
10557 Ok(())
10558 }
10559}
10560
10561#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10565#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10566#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10567pub enum SchemaName {
10568 Simple(ObjectName),
10570 UnnamedAuthorization(Ident),
10572 NamedAuthorization(ObjectName, Ident),
10574}
10575
10576impl fmt::Display for SchemaName {
10577 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10578 match self {
10579 SchemaName::Simple(name) => {
10580 write!(f, "{name}")
10581 }
10582 SchemaName::UnnamedAuthorization(authorization) => {
10583 write!(f, "AUTHORIZATION {authorization}")
10584 }
10585 SchemaName::NamedAuthorization(name, authorization) => {
10586 write!(f, "{name} AUTHORIZATION {authorization}")
10587 }
10588 }
10589 }
10590}
10591
10592#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10596#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10597#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10598pub enum SearchModifier {
10599 InNaturalLanguageMode,
10601 InNaturalLanguageModeWithQueryExpansion,
10603 InBooleanMode,
10605 WithQueryExpansion,
10607}
10608
10609impl fmt::Display for SearchModifier {
10610 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10611 match self {
10612 Self::InNaturalLanguageMode => {
10613 write!(f, "IN NATURAL LANGUAGE MODE")?;
10614 }
10615 Self::InNaturalLanguageModeWithQueryExpansion => {
10616 write!(f, "IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION")?;
10617 }
10618 Self::InBooleanMode => {
10619 write!(f, "IN BOOLEAN MODE")?;
10620 }
10621 Self::WithQueryExpansion => {
10622 write!(f, "WITH QUERY EXPANSION")?;
10623 }
10624 }
10625
10626 Ok(())
10627 }
10628}
10629
10630#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10632#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10633#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10634pub struct LockTable {
10635 pub table: Ident,
10637 pub alias: Option<Ident>,
10639 pub lock_type: LockTableType,
10641}
10642
10643impl fmt::Display for LockTable {
10644 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10645 let Self {
10646 table: tbl_name,
10647 alias,
10648 lock_type,
10649 } = self;
10650
10651 write!(f, "{tbl_name} ")?;
10652 if let Some(alias) = alias {
10653 write!(f, "AS {alias} ")?;
10654 }
10655 write!(f, "{lock_type}")?;
10656 Ok(())
10657 }
10658}
10659
10660#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10661#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10662#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10663pub enum LockTableType {
10665 Read {
10667 local: bool,
10669 },
10670 Write {
10672 low_priority: bool,
10674 },
10675}
10676
10677impl fmt::Display for LockTableType {
10678 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10679 match self {
10680 Self::Read { local } => {
10681 write!(f, "READ")?;
10682 if *local {
10683 write!(f, " LOCAL")?;
10684 }
10685 }
10686 Self::Write { low_priority } => {
10687 if *low_priority {
10688 write!(f, "LOW_PRIORITY ")?;
10689 }
10690 write!(f, "WRITE")?;
10691 }
10692 }
10693
10694 Ok(())
10695 }
10696}
10697
10698#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10699#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10700#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10701pub struct HiveSetLocation {
10703 pub has_set: bool,
10705 pub location: Ident,
10707}
10708
10709impl fmt::Display for HiveSetLocation {
10710 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10711 if self.has_set {
10712 write!(f, "SET ")?;
10713 }
10714 write!(f, "LOCATION {}", self.location)
10715 }
10716}
10717
10718#[allow(clippy::large_enum_variant)]
10720#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10721#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10722#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10723pub enum MySQLColumnPosition {
10725 First,
10727 After(Ident),
10729}
10730
10731impl Display for MySQLColumnPosition {
10732 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10733 match self {
10734 MySQLColumnPosition::First => write!(f, "FIRST"),
10735 MySQLColumnPosition::After(ident) => {
10736 let column_name = &ident.value;
10737 write!(f, "AFTER {column_name}")
10738 }
10739 }
10740 }
10741}
10742
10743#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10745#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10746#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10747pub enum CreateViewAlgorithm {
10749 Undefined,
10751 Merge,
10753 TempTable,
10755}
10756
10757impl Display for CreateViewAlgorithm {
10758 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10759 match self {
10760 CreateViewAlgorithm::Undefined => write!(f, "UNDEFINED"),
10761 CreateViewAlgorithm::Merge => write!(f, "MERGE"),
10762 CreateViewAlgorithm::TempTable => write!(f, "TEMPTABLE"),
10763 }
10764 }
10765}
10766#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10768#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10769#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10770pub enum CreateViewSecurity {
10772 Definer,
10774 Invoker,
10776}
10777
10778impl Display for CreateViewSecurity {
10779 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10780 match self {
10781 CreateViewSecurity::Definer => write!(f, "DEFINER"),
10782 CreateViewSecurity::Invoker => write!(f, "INVOKER"),
10783 }
10784 }
10785}
10786
10787#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10791#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10792#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10793pub struct CreateViewParams {
10794 pub algorithm: Option<CreateViewAlgorithm>,
10796 pub definer: Option<GranteeName>,
10798 pub security: Option<CreateViewSecurity>,
10800}
10801
10802impl Display for CreateViewParams {
10803 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10804 let CreateViewParams {
10805 algorithm,
10806 definer,
10807 security,
10808 } = self;
10809 if let Some(algorithm) = algorithm {
10810 write!(f, "ALGORITHM = {algorithm} ")?;
10811 }
10812 if let Some(definers) = definer {
10813 write!(f, "DEFINER = {definers} ")?;
10814 }
10815 if let Some(security) = security {
10816 write!(f, "SQL SECURITY {security} ")?;
10817 }
10818 Ok(())
10819 }
10820}
10821
10822#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10823#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10824#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10825pub struct NamedParenthesizedList {
10833 pub key: Ident,
10835 pub name: Option<Ident>,
10837 pub values: Vec<Ident>,
10839}
10840
10841#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10846#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10847#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10848pub struct RowAccessPolicy {
10849 pub policy: ObjectName,
10851 pub on: Vec<Ident>,
10853}
10854
10855impl RowAccessPolicy {
10856 pub fn new(policy: ObjectName, on: Vec<Ident>) -> Self {
10858 Self { policy, on }
10859 }
10860}
10861
10862impl Display for RowAccessPolicy {
10863 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10864 write!(
10865 f,
10866 "WITH ROW ACCESS POLICY {} ON ({})",
10867 self.policy,
10868 display_comma_separated(self.on.as_slice())
10869 )
10870 }
10871}
10872
10873#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10877#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10878#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10879pub struct StorageLifecyclePolicy {
10880 pub policy: ObjectName,
10882 pub on: Vec<Ident>,
10884}
10885
10886impl Display for StorageLifecyclePolicy {
10887 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10888 write!(
10889 f,
10890 "WITH STORAGE LIFECYCLE POLICY {} ON ({})",
10891 self.policy,
10892 display_comma_separated(self.on.as_slice())
10893 )
10894 }
10895}
10896
10897#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10901#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10902#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10903pub struct Tag {
10904 pub key: ObjectName,
10906 pub value: String,
10908}
10909
10910impl Tag {
10911 pub fn new(key: ObjectName, value: String) -> Self {
10913 Self { key, value }
10914 }
10915}
10916
10917impl Display for Tag {
10918 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10919 write!(f, "{}='{}'", self.key, self.value)
10920 }
10921}
10922
10923#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10927#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10928#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10929pub struct ContactEntry {
10930 pub purpose: String,
10932 pub contact: String,
10934}
10935
10936impl Display for ContactEntry {
10937 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10938 write!(f, "{} = {}", self.purpose, self.contact)
10939 }
10940}
10941
10942#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10944#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10945#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10946pub enum CommentDef {
10947 WithEq(String),
10950 WithoutEq(String),
10952}
10953
10954impl Display for CommentDef {
10955 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10956 match self {
10957 CommentDef::WithEq(comment) | CommentDef::WithoutEq(comment) => write!(f, "{comment}"),
10958 }
10959 }
10960}
10961
10962#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10977#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10978#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10979pub enum WrappedCollection<T> {
10980 NoWrapping(T),
10982 Parentheses(T),
10984}
10985
10986impl<T> Display for WrappedCollection<Vec<T>>
10987where
10988 T: Display,
10989{
10990 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10991 match self {
10992 WrappedCollection::NoWrapping(inner) => {
10993 write!(f, "{}", display_comma_separated(inner.as_slice()))
10994 }
10995 WrappedCollection::Parentheses(inner) => {
10996 write!(f, "({})", display_comma_separated(inner.as_slice()))
10997 }
10998 }
10999 }
11000}
11001
11002#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11026#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11027#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11028pub struct UtilityOption {
11029 pub name: Ident,
11031 pub arg: Option<Expr>,
11033}
11034
11035impl Display for UtilityOption {
11036 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11037 if let Some(ref arg) = self.arg {
11038 write!(f, "{} {}", self.name, arg)
11039 } else {
11040 write!(f, "{}", self.name)
11041 }
11042 }
11043}
11044
11045#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11049#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11050#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11051pub struct ShowStatementOptions {
11052 pub show_in: Option<ShowStatementIn>,
11054 pub starts_with: Option<ValueWithSpan>,
11056 pub limit: Option<Expr>,
11058 pub limit_from: Option<ValueWithSpan>,
11060 pub filter_position: Option<ShowStatementFilterPosition>,
11062}
11063
11064impl Display for ShowStatementOptions {
11065 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11066 let (like_in_infix, like_in_suffix) = match &self.filter_position {
11067 Some(ShowStatementFilterPosition::Infix(filter)) => {
11068 (format!(" {filter}"), "".to_string())
11069 }
11070 Some(ShowStatementFilterPosition::Suffix(filter)) => {
11071 ("".to_string(), format!(" {filter}"))
11072 }
11073 None => ("".to_string(), "".to_string()),
11074 };
11075 write!(
11076 f,
11077 "{like_in_infix}{show_in}{starts_with}{limit}{from}{like_in_suffix}",
11078 show_in = match &self.show_in {
11079 Some(i) => format!(" {i}"),
11080 None => String::new(),
11081 },
11082 starts_with = match &self.starts_with {
11083 Some(s) => format!(" STARTS WITH {s}"),
11084 None => String::new(),
11085 },
11086 limit = match &self.limit {
11087 Some(l) => format!(" LIMIT {l}"),
11088 None => String::new(),
11089 },
11090 from = match &self.limit_from {
11091 Some(f) => format!(" FROM {f}"),
11092 None => String::new(),
11093 }
11094 )?;
11095 Ok(())
11096 }
11097}
11098
11099#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11100#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11101#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11102pub enum ShowStatementFilterPosition {
11104 Infix(ShowStatementFilter), Suffix(ShowStatementFilter), }
11109
11110#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11111#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11112#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11113pub enum ShowStatementInParentType {
11115 Account,
11117 Database,
11119 Schema,
11121 Table,
11123 View,
11125}
11126
11127impl fmt::Display for ShowStatementInParentType {
11128 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11129 match self {
11130 ShowStatementInParentType::Account => write!(f, "ACCOUNT"),
11131 ShowStatementInParentType::Database => write!(f, "DATABASE"),
11132 ShowStatementInParentType::Schema => write!(f, "SCHEMA"),
11133 ShowStatementInParentType::Table => write!(f, "TABLE"),
11134 ShowStatementInParentType::View => write!(f, "VIEW"),
11135 }
11136 }
11137}
11138
11139#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11140#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11141#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11142pub struct ShowStatementIn {
11144 pub clause: ShowStatementInClause,
11146 pub parent_type: Option<ShowStatementInParentType>,
11148 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
11150 pub parent_name: Option<ObjectName>,
11151}
11152
11153impl fmt::Display for ShowStatementIn {
11154 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11155 write!(f, "{}", self.clause)?;
11156 if let Some(parent_type) = &self.parent_type {
11157 write!(f, " {parent_type}")?;
11158 }
11159 if let Some(parent_name) = &self.parent_name {
11160 write!(f, " {parent_name}")?;
11161 }
11162 Ok(())
11163 }
11164}
11165
11166#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11168#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11169#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11170pub struct ShowCharset {
11171 pub is_shorthand: bool,
11174 pub filter: Option<ShowStatementFilter>,
11176}
11177
11178impl fmt::Display for ShowCharset {
11179 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11180 write!(f, "SHOW")?;
11181 if self.is_shorthand {
11182 write!(f, " CHARSET")?;
11183 } else {
11184 write!(f, " CHARACTER SET")?;
11185 }
11186 if let Some(filter) = &self.filter {
11187 write!(f, " {filter}")?;
11188 }
11189 Ok(())
11190 }
11191}
11192
11193#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11194#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11195#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11196pub struct ShowObjects {
11198 pub terse: bool,
11200 pub show_options: ShowStatementOptions,
11202}
11203
11204#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11214#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11215#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11216pub enum JsonNullClause {
11217 NullOnNull,
11219 AbsentOnNull,
11221}
11222
11223impl Display for JsonNullClause {
11224 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11225 match self {
11226 JsonNullClause::NullOnNull => write!(f, "NULL ON NULL"),
11227 JsonNullClause::AbsentOnNull => write!(f, "ABSENT ON NULL"),
11228 }
11229 }
11230}
11231
11232#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11239#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11240#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11241pub struct JsonReturningClause {
11242 pub data_type: DataType,
11244}
11245
11246impl Display for JsonReturningClause {
11247 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11248 write!(f, "RETURNING {}", self.data_type)
11249 }
11250}
11251
11252#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11254#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11255#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11256pub struct RenameTable {
11257 pub old_name: ObjectName,
11259 pub new_name: ObjectName,
11261}
11262
11263impl fmt::Display for RenameTable {
11264 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11265 write!(f, "{} TO {}", self.old_name, self.new_name)?;
11266 Ok(())
11267 }
11268}
11269
11270#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11272#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11273#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11274pub enum TableObject {
11275 TableName(#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] ObjectName),
11281
11282 TableFunction(Function),
11289
11290 TableQuery(Box<Query>),
11299}
11300
11301impl fmt::Display for TableObject {
11302 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11303 match self {
11304 Self::TableName(table_name) => write!(f, "{table_name}"),
11305 Self::TableFunction(func) => write!(f, "FUNCTION {func}"),
11306 Self::TableQuery(table_query) => write!(f, "({table_query})"),
11307 }
11308 }
11309}
11310
11311#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11313#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11314#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11315pub struct SetSessionAuthorizationParam {
11316 pub scope: ContextModifier,
11318 pub kind: SetSessionAuthorizationParamKind,
11320}
11321
11322impl fmt::Display for SetSessionAuthorizationParam {
11323 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11324 write!(f, "{}", self.kind)
11325 }
11326}
11327
11328#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11330#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11331#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11332pub enum SetSessionAuthorizationParamKind {
11333 Default,
11335
11336 User(Ident),
11338}
11339
11340impl fmt::Display for SetSessionAuthorizationParamKind {
11341 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11342 match self {
11343 SetSessionAuthorizationParamKind::Default => write!(f, "DEFAULT"),
11344 SetSessionAuthorizationParamKind::User(name) => write!(f, "{}", name),
11345 }
11346 }
11347}
11348
11349#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11350#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11351#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11352pub enum SetSessionParamKind {
11354 Generic(SetSessionParamGeneric),
11356 IdentityInsert(SetSessionParamIdentityInsert),
11358 Offsets(SetSessionParamOffsets),
11360 Statistics(SetSessionParamStatistics),
11362}
11363
11364impl fmt::Display for SetSessionParamKind {
11365 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11366 match self {
11367 SetSessionParamKind::Generic(x) => write!(f, "{x}"),
11368 SetSessionParamKind::IdentityInsert(x) => write!(f, "{x}"),
11369 SetSessionParamKind::Offsets(x) => write!(f, "{x}"),
11370 SetSessionParamKind::Statistics(x) => write!(f, "{x}"),
11371 }
11372 }
11373}
11374
11375#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11376#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11377#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11378pub struct SetSessionParamGeneric {
11380 pub names: Vec<String>,
11382 pub value: String,
11384}
11385
11386impl fmt::Display for SetSessionParamGeneric {
11387 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11388 write!(f, "{} {}", display_comma_separated(&self.names), self.value)
11389 }
11390}
11391
11392#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11393#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11394#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11395pub struct SetSessionParamIdentityInsert {
11397 pub obj: ObjectName,
11399 pub value: SessionParamValue,
11401}
11402
11403impl fmt::Display for SetSessionParamIdentityInsert {
11404 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11405 write!(f, "IDENTITY_INSERT {} {}", self.obj, self.value)
11406 }
11407}
11408
11409#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11410#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11411#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11412pub struct SetSessionParamOffsets {
11414 pub keywords: Vec<String>,
11416 pub value: SessionParamValue,
11418}
11419
11420impl fmt::Display for SetSessionParamOffsets {
11421 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11422 write!(
11423 f,
11424 "OFFSETS {} {}",
11425 display_comma_separated(&self.keywords),
11426 self.value
11427 )
11428 }
11429}
11430
11431#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11432#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11433#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11434pub struct SetSessionParamStatistics {
11436 pub topic: SessionParamStatsTopic,
11438 pub value: SessionParamValue,
11440}
11441
11442impl fmt::Display for SetSessionParamStatistics {
11443 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11444 write!(f, "STATISTICS {} {}", self.topic, self.value)
11445 }
11446}
11447
11448#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11449#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11450#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11451pub enum SessionParamStatsTopic {
11453 IO,
11455 Profile,
11457 Time,
11459 Xml,
11461}
11462
11463impl fmt::Display for SessionParamStatsTopic {
11464 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11465 match self {
11466 SessionParamStatsTopic::IO => write!(f, "IO"),
11467 SessionParamStatsTopic::Profile => write!(f, "PROFILE"),
11468 SessionParamStatsTopic::Time => write!(f, "TIME"),
11469 SessionParamStatsTopic::Xml => write!(f, "XML"),
11470 }
11471 }
11472}
11473
11474#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11475#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11476#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11477pub enum SessionParamValue {
11479 On,
11481 Off,
11483}
11484
11485impl fmt::Display for SessionParamValue {
11486 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11487 match self {
11488 SessionParamValue::On => write!(f, "ON"),
11489 SessionParamValue::Off => write!(f, "OFF"),
11490 }
11491 }
11492}
11493
11494#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11501#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11502#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11503pub enum StorageSerializationPolicy {
11504 Compatible,
11506 Optimized,
11508}
11509
11510impl Display for StorageSerializationPolicy {
11511 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11512 match self {
11513 StorageSerializationPolicy::Compatible => write!(f, "COMPATIBLE"),
11514 StorageSerializationPolicy::Optimized => write!(f, "OPTIMIZED"),
11515 }
11516 }
11517}
11518
11519#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11526#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11527#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11528pub enum CatalogSyncNamespaceMode {
11529 Nest,
11531 Flatten,
11533}
11534
11535impl Display for CatalogSyncNamespaceMode {
11536 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11537 match self {
11538 CatalogSyncNamespaceMode::Nest => write!(f, "NEST"),
11539 CatalogSyncNamespaceMode::Flatten => write!(f, "FLATTEN"),
11540 }
11541 }
11542}
11543
11544#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11546#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11547#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11548pub enum CopyIntoSnowflakeKind {
11549 Table,
11552 Location,
11555}
11556
11557#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11558#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11559#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11560pub struct PrintStatement {
11562 pub message: Box<Expr>,
11564}
11565
11566impl fmt::Display for PrintStatement {
11567 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11568 write!(f, "PRINT {}", self.message)
11569 }
11570}
11571
11572#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11576#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11577#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11578pub enum WaitForType {
11579 Delay,
11581 Time,
11583}
11584
11585impl fmt::Display for WaitForType {
11586 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11587 match self {
11588 WaitForType::Delay => write!(f, "DELAY"),
11589 WaitForType::Time => write!(f, "TIME"),
11590 }
11591 }
11592}
11593
11594#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11598#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11599#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11600pub struct WaitForStatement {
11601 pub wait_type: WaitForType,
11603 pub expr: Expr,
11605}
11606
11607impl fmt::Display for WaitForStatement {
11608 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11609 write!(f, "WAITFOR {} {}", self.wait_type, self.expr)
11610 }
11611}
11612
11613#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11618#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11619#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11620pub struct ReturnStatement {
11621 pub value: Option<ReturnStatementValue>,
11623}
11624
11625impl fmt::Display for ReturnStatement {
11626 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11627 match &self.value {
11628 Some(ReturnStatementValue::Expr(expr)) => write!(f, "RETURN {expr}"),
11629 None => write!(f, "RETURN"),
11630 }
11631 }
11632}
11633
11634#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11636#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11637#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11638pub enum ReturnStatementValue {
11639 Expr(Expr),
11641}
11642
11643#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11645#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11646#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11647pub struct OpenStatement {
11648 pub cursor_name: Ident,
11650}
11651
11652impl fmt::Display for OpenStatement {
11653 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11654 write!(f, "OPEN {}", self.cursor_name)
11655 }
11656}
11657
11658#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11662#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11663#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11664pub enum NullInclusion {
11665 IncludeNulls,
11667 ExcludeNulls,
11669}
11670
11671impl fmt::Display for NullInclusion {
11672 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11673 match self {
11674 NullInclusion::IncludeNulls => write!(f, "INCLUDE NULLS"),
11675 NullInclusion::ExcludeNulls => write!(f, "EXCLUDE NULLS"),
11676 }
11677 }
11678}
11679
11680#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11688#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11689#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11690pub struct MemberOf {
11691 pub value: Box<Expr>,
11693 pub array: Box<Expr>,
11695}
11696
11697impl fmt::Display for MemberOf {
11698 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11699 write!(f, "{} MEMBER OF({})", self.value, self.array)
11700 }
11701}
11702
11703#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11704#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11705#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11706pub struct ExportData {
11708 pub options: Vec<SqlOption>,
11710 pub query: Box<Query>,
11712 pub connection: Option<ObjectName>,
11714}
11715
11716impl fmt::Display for ExportData {
11717 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11718 if let Some(connection) = &self.connection {
11719 write!(
11720 f,
11721 "EXPORT DATA WITH CONNECTION {connection} OPTIONS({}) AS {}",
11722 display_comma_separated(&self.options),
11723 self.query
11724 )
11725 } else {
11726 write!(
11727 f,
11728 "EXPORT DATA OPTIONS({}) AS {}",
11729 display_comma_separated(&self.options),
11730 self.query
11731 )
11732 }
11733 }
11734}
11735#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11744#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11745#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11746pub struct CreateUser {
11747 pub or_replace: bool,
11749 pub if_not_exists: bool,
11751 pub name: Ident,
11753 pub options: KeyValueOptions,
11755 pub with_tags: bool,
11757 pub tags: KeyValueOptions,
11759}
11760
11761impl fmt::Display for CreateUser {
11762 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11763 write!(f, "CREATE")?;
11764 if self.or_replace {
11765 write!(f, " OR REPLACE")?;
11766 }
11767 write!(f, " USER")?;
11768 if self.if_not_exists {
11769 write!(f, " IF NOT EXISTS")?;
11770 }
11771 write!(f, " {}", self.name)?;
11772 if !self.options.options.is_empty() {
11773 write!(f, " {}", self.options)?;
11774 }
11775 if !self.tags.options.is_empty() {
11776 if self.with_tags {
11777 write!(f, " WITH")?;
11778 }
11779 write!(f, " TAG ({})", self.tags)?;
11780 }
11781 Ok(())
11782 }
11783}
11784
11785#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11797#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11798#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11799pub struct AlterUser {
11800 pub if_exists: bool,
11802 pub name: Ident,
11804 pub rename_to: Option<Ident>,
11807 pub reset_password: bool,
11809 pub abort_all_queries: bool,
11811 pub add_role_delegation: Option<AlterUserAddRoleDelegation>,
11813 pub remove_role_delegation: Option<AlterUserRemoveRoleDelegation>,
11815 pub enroll_mfa: bool,
11817 pub set_default_mfa_method: Option<MfaMethodKind>,
11819 pub remove_mfa_method: Option<MfaMethodKind>,
11821 pub modify_mfa_method: Option<AlterUserModifyMfaMethod>,
11823 pub add_mfa_method_otp: Option<AlterUserAddMfaMethodOtp>,
11825 pub set_policy: Option<AlterUserSetPolicy>,
11827 pub unset_policy: Option<UserPolicyKind>,
11829 pub set_tag: KeyValueOptions,
11831 pub unset_tag: Vec<String>,
11833 pub set_props: KeyValueOptions,
11835 pub unset_props: Vec<String>,
11837 pub password: Option<AlterUserPassword>,
11839}
11840
11841#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11845#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11846#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11847pub struct AlterUserAddRoleDelegation {
11848 pub role: Ident,
11850 pub integration: Ident,
11852}
11853
11854#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11858#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11859#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11860pub struct AlterUserRemoveRoleDelegation {
11861 pub role: Option<Ident>,
11863 pub integration: Ident,
11865}
11866
11867#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11871#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11872#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11873pub struct AlterUserAddMfaMethodOtp {
11874 pub count: Option<ValueWithSpan>,
11876}
11877
11878#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11882#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11883#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11884pub struct AlterUserModifyMfaMethod {
11885 pub method: MfaMethodKind,
11887 pub comment: String,
11889}
11890
11891#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11893#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11894#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11895pub enum MfaMethodKind {
11896 PassKey,
11898 Totp,
11900 Duo,
11902}
11903
11904impl fmt::Display for MfaMethodKind {
11905 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11906 match self {
11907 MfaMethodKind::PassKey => write!(f, "PASSKEY"),
11908 MfaMethodKind::Totp => write!(f, "TOTP"),
11909 MfaMethodKind::Duo => write!(f, "DUO"),
11910 }
11911 }
11912}
11913
11914#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11918#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11919#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11920pub struct AlterUserSetPolicy {
11921 pub policy_kind: UserPolicyKind,
11923 pub policy: Ident,
11925}
11926
11927#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11929#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11930#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11931pub enum UserPolicyKind {
11932 Authentication,
11934 Password,
11936 Session,
11938}
11939
11940impl fmt::Display for UserPolicyKind {
11941 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11942 match self {
11943 UserPolicyKind::Authentication => write!(f, "AUTHENTICATION"),
11944 UserPolicyKind::Password => write!(f, "PASSWORD"),
11945 UserPolicyKind::Session => write!(f, "SESSION"),
11946 }
11947 }
11948}
11949
11950impl fmt::Display for AlterUser {
11951 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11952 write!(f, "ALTER")?;
11953 write!(f, " USER")?;
11954 if self.if_exists {
11955 write!(f, " IF EXISTS")?;
11956 }
11957 write!(f, " {}", self.name)?;
11958 if let Some(new_name) = &self.rename_to {
11959 write!(f, " RENAME TO {new_name}")?;
11960 }
11961 if self.reset_password {
11962 write!(f, " RESET PASSWORD")?;
11963 }
11964 if self.abort_all_queries {
11965 write!(f, " ABORT ALL QUERIES")?;
11966 }
11967 if let Some(role_delegation) = &self.add_role_delegation {
11968 let role = &role_delegation.role;
11969 let integration = &role_delegation.integration;
11970 write!(
11971 f,
11972 " ADD DELEGATED AUTHORIZATION OF ROLE {role} TO SECURITY INTEGRATION {integration}"
11973 )?;
11974 }
11975 if let Some(role_delegation) = &self.remove_role_delegation {
11976 write!(f, " REMOVE DELEGATED")?;
11977 match &role_delegation.role {
11978 Some(role) => write!(f, " AUTHORIZATION OF ROLE {role}")?,
11979 None => write!(f, " AUTHORIZATIONS")?,
11980 }
11981 let integration = &role_delegation.integration;
11982 write!(f, " FROM SECURITY INTEGRATION {integration}")?;
11983 }
11984 if self.enroll_mfa {
11985 write!(f, " ENROLL MFA")?;
11986 }
11987 if let Some(method) = &self.set_default_mfa_method {
11988 write!(f, " SET DEFAULT_MFA_METHOD {method}")?
11989 }
11990 if let Some(method) = &self.remove_mfa_method {
11991 write!(f, " REMOVE MFA METHOD {method}")?;
11992 }
11993 if let Some(modify) = &self.modify_mfa_method {
11994 let method = &modify.method;
11995 let comment = &modify.comment;
11996 write!(
11997 f,
11998 " MODIFY MFA METHOD {method} SET COMMENT '{}'",
11999 value::escape_single_quote_string(comment)
12000 )?;
12001 }
12002 if let Some(add_mfa_method_otp) = &self.add_mfa_method_otp {
12003 write!(f, " ADD MFA METHOD OTP")?;
12004 if let Some(count) = &add_mfa_method_otp.count {
12005 write!(f, " COUNT = {count}")?;
12006 }
12007 }
12008 if let Some(policy) = &self.set_policy {
12009 let policy_kind = &policy.policy_kind;
12010 let name = &policy.policy;
12011 write!(f, " SET {policy_kind} POLICY {name}")?;
12012 }
12013 if let Some(policy_kind) = &self.unset_policy {
12014 write!(f, " UNSET {policy_kind} POLICY")?;
12015 }
12016 if !self.set_tag.options.is_empty() {
12017 write!(f, " SET TAG {}", self.set_tag)?;
12018 }
12019 if !self.unset_tag.is_empty() {
12020 write!(f, " UNSET TAG {}", display_comma_separated(&self.unset_tag))?;
12021 }
12022 let has_props = !self.set_props.options.is_empty();
12023 if has_props {
12024 write!(f, " SET")?;
12025 write!(f, " {}", &self.set_props)?;
12026 }
12027 if !self.unset_props.is_empty() {
12028 write!(f, " UNSET {}", display_comma_separated(&self.unset_props))?;
12029 }
12030 if let Some(password) = &self.password {
12031 write!(f, " {}", password)?;
12032 }
12033 Ok(())
12034 }
12035}
12036
12037#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12041#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12042#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12043pub struct AlterUserPassword {
12044 pub encrypted: bool,
12046 pub password: Option<String>,
12048}
12049
12050impl Display for AlterUserPassword {
12051 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12052 if self.encrypted {
12053 write!(f, "ENCRYPTED ")?;
12054 }
12055 write!(f, "PASSWORD")?;
12056 match &self.password {
12057 None => write!(f, " NULL")?,
12058 Some(password) => write!(f, " '{}'", value::escape_single_quote_string(password))?,
12059 }
12060 Ok(())
12061 }
12062}
12063
12064#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12069#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12070#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12071pub enum CreateTableLikeKind {
12072 Parenthesized(CreateTableLike),
12077 Plain(CreateTableLike),
12083}
12084
12085#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12086#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12087#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12088pub enum CreateTableLikeDefaults {
12090 Including,
12092 Excluding,
12094}
12095
12096impl fmt::Display for CreateTableLikeDefaults {
12097 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12098 match self {
12099 CreateTableLikeDefaults::Including => write!(f, "INCLUDING DEFAULTS"),
12100 CreateTableLikeDefaults::Excluding => write!(f, "EXCLUDING DEFAULTS"),
12101 }
12102 }
12103}
12104
12105#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12106#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12107#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12108pub struct CreateTableLike {
12110 pub name: ObjectName,
12112 pub defaults: Option<CreateTableLikeDefaults>,
12114}
12115
12116impl fmt::Display for CreateTableLike {
12117 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12118 write!(f, "LIKE {}", self.name)?;
12119 if let Some(defaults) = &self.defaults {
12120 write!(f, " {defaults}")?;
12121 }
12122 Ok(())
12123 }
12124}
12125
12126#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12130#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12131#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12132pub enum RefreshModeKind {
12133 Auto,
12135 Full,
12137 Incremental,
12139}
12140
12141impl fmt::Display for RefreshModeKind {
12142 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12143 match self {
12144 RefreshModeKind::Auto => write!(f, "AUTO"),
12145 RefreshModeKind::Full => write!(f, "FULL"),
12146 RefreshModeKind::Incremental => write!(f, "INCREMENTAL"),
12147 }
12148 }
12149}
12150
12151#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12155#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12156#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12157pub enum InitializeKind {
12158 OnCreate,
12160 OnSchedule,
12162}
12163
12164impl fmt::Display for InitializeKind {
12165 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12166 match self {
12167 InitializeKind::OnCreate => write!(f, "ON_CREATE"),
12168 InitializeKind::OnSchedule => write!(f, "ON_SCHEDULE"),
12169 }
12170 }
12171}
12172
12173#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12180#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12181#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12182pub struct VacuumStatement {
12183 pub full: bool,
12185 pub sort_only: bool,
12187 pub delete_only: bool,
12189 pub reindex: bool,
12191 pub recluster: bool,
12193 pub table_name: Option<ObjectName>,
12195 pub threshold: Option<ValueWithSpan>,
12197 pub boost: bool,
12199}
12200
12201impl fmt::Display for VacuumStatement {
12202 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12203 write!(
12204 f,
12205 "VACUUM{}{}{}{}{}",
12206 if self.full { " FULL" } else { "" },
12207 if self.sort_only { " SORT ONLY" } else { "" },
12208 if self.delete_only { " DELETE ONLY" } else { "" },
12209 if self.reindex { " REINDEX" } else { "" },
12210 if self.recluster { " RECLUSTER" } else { "" },
12211 )?;
12212 if let Some(table_name) = &self.table_name {
12213 write!(f, " {table_name}")?;
12214 }
12215 if let Some(threshold) = &self.threshold {
12216 write!(f, " TO {threshold} PERCENT")?;
12217 }
12218 if self.boost {
12219 write!(f, " BOOST")?;
12220 }
12221 Ok(())
12222 }
12223}
12224
12225#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12227#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12228#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12229pub enum Reset {
12230 ALL,
12232
12233 ConfigurationParameter(ObjectName),
12235}
12236
12237#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12242#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12243#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12244pub struct ResetStatement {
12245 pub reset: Reset,
12247}
12248
12249#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12255#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12256#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12257pub struct OptimizerHint {
12258 pub prefix: String,
12265 pub text: String,
12267 pub style: OptimizerHintStyle,
12272}
12273
12274#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12276#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12277#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12278pub enum OptimizerHintStyle {
12279 SingleLine {
12282 prefix: String,
12284 },
12285 MultiLine,
12288}
12289
12290impl fmt::Display for OptimizerHint {
12291 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12292 match &self.style {
12293 OptimizerHintStyle::SingleLine { prefix } => {
12294 f.write_str(prefix)?;
12295 f.write_str(&self.prefix)?;
12296 f.write_str("+")?;
12297 f.write_str(&self.text)
12298 }
12299 OptimizerHintStyle::MultiLine => {
12300 f.write_str("/*")?;
12301 f.write_str(&self.prefix)?;
12302 f.write_str("+")?;
12303 f.write_str(&self.text)?;
12304 f.write_str("*/")
12305 }
12306 }
12307 }
12308}
12309
12310impl fmt::Display for ResetStatement {
12311 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12312 match &self.reset {
12313 Reset::ALL => write!(f, "RESET ALL"),
12314 Reset::ConfigurationParameter(param) => write!(f, "RESET {}", param),
12315 }
12316 }
12317}
12318
12319impl From<Set> for Statement {
12320 fn from(s: Set) -> Self {
12321 Self::Set(s)
12322 }
12323}
12324
12325impl From<Query> for Statement {
12326 fn from(q: Query) -> Self {
12327 Box::new(q).into()
12328 }
12329}
12330
12331impl From<Box<Query>> for Statement {
12332 fn from(q: Box<Query>) -> Self {
12333 Self::Query(q)
12334 }
12335}
12336
12337impl From<Insert> for Statement {
12338 fn from(i: Insert) -> Self {
12339 Self::Insert(i)
12340 }
12341}
12342
12343impl From<Update> for Statement {
12344 fn from(u: Update) -> Self {
12345 Self::Update(u)
12346 }
12347}
12348
12349impl From<CreateView> for Statement {
12350 fn from(cv: CreateView) -> Self {
12351 Self::CreateView(cv)
12352 }
12353}
12354
12355impl From<CreateRole> for Statement {
12356 fn from(cr: CreateRole) -> Self {
12357 Self::CreateRole(cr)
12358 }
12359}
12360
12361impl From<AlterTable> for Statement {
12362 fn from(at: AlterTable) -> Self {
12363 Self::AlterTable(at)
12364 }
12365}
12366
12367impl From<DropFunction> for Statement {
12368 fn from(df: DropFunction) -> Self {
12369 Self::DropFunction(df)
12370 }
12371}
12372
12373impl From<CreateExtension> for Statement {
12374 fn from(ce: CreateExtension) -> Self {
12375 Self::CreateExtension(ce)
12376 }
12377}
12378
12379impl From<CreateCollation> for Statement {
12380 fn from(c: CreateCollation) -> Self {
12381 Self::CreateCollation(c)
12382 }
12383}
12384
12385impl From<DropExtension> for Statement {
12386 fn from(de: DropExtension) -> Self {
12387 Self::DropExtension(de)
12388 }
12389}
12390
12391impl From<CaseStatement> for Statement {
12392 fn from(c: CaseStatement) -> Self {
12393 Self::Case(c)
12394 }
12395}
12396
12397impl From<IfStatement> for Statement {
12398 fn from(i: IfStatement) -> Self {
12399 Self::If(i)
12400 }
12401}
12402
12403impl From<WhileStatement> for Statement {
12404 fn from(w: WhileStatement) -> Self {
12405 Self::While(w)
12406 }
12407}
12408
12409impl From<RaiseStatement> for Statement {
12410 fn from(r: RaiseStatement) -> Self {
12411 Self::Raise(r)
12412 }
12413}
12414
12415impl From<ThrowStatement> for Statement {
12416 fn from(t: ThrowStatement) -> Self {
12417 Self::Throw(t)
12418 }
12419}
12420
12421impl From<Function> for Statement {
12422 fn from(f: Function) -> Self {
12423 Self::Call(f)
12424 }
12425}
12426
12427impl From<OpenStatement> for Statement {
12428 fn from(o: OpenStatement) -> Self {
12429 Self::Open(o)
12430 }
12431}
12432
12433impl From<Delete> for Statement {
12434 fn from(d: Delete) -> Self {
12435 Self::Delete(d)
12436 }
12437}
12438
12439impl From<CreateTable> for Statement {
12440 fn from(c: CreateTable) -> Self {
12441 Self::CreateTable(c)
12442 }
12443}
12444
12445impl From<CreateIndex> for Statement {
12446 fn from(c: CreateIndex) -> Self {
12447 Self::CreateIndex(c)
12448 }
12449}
12450
12451impl From<CreateServerStatement> for Statement {
12452 fn from(c: CreateServerStatement) -> Self {
12453 Self::CreateServer(c)
12454 }
12455}
12456
12457impl From<CreateConnector> for Statement {
12458 fn from(c: CreateConnector) -> Self {
12459 Self::CreateConnector(c)
12460 }
12461}
12462
12463impl From<CreateOperator> for Statement {
12464 fn from(c: CreateOperator) -> Self {
12465 Self::CreateOperator(c)
12466 }
12467}
12468
12469impl From<CreateOperatorFamily> for Statement {
12470 fn from(c: CreateOperatorFamily) -> Self {
12471 Self::CreateOperatorFamily(c)
12472 }
12473}
12474
12475impl From<CreateOperatorClass> for Statement {
12476 fn from(c: CreateOperatorClass) -> Self {
12477 Self::CreateOperatorClass(c)
12478 }
12479}
12480
12481impl From<AlterSchema> for Statement {
12482 fn from(a: AlterSchema) -> Self {
12483 Self::AlterSchema(a)
12484 }
12485}
12486
12487impl From<AlterFunction> for Statement {
12488 fn from(a: AlterFunction) -> Self {
12489 Self::AlterFunction(a)
12490 }
12491}
12492
12493impl From<AlterType> for Statement {
12494 fn from(a: AlterType) -> Self {
12495 Self::AlterType(a)
12496 }
12497}
12498
12499impl From<AlterCollation> for Statement {
12500 fn from(a: AlterCollation) -> Self {
12501 Self::AlterCollation(a)
12502 }
12503}
12504
12505impl From<AlterOperator> for Statement {
12506 fn from(a: AlterOperator) -> Self {
12507 Self::AlterOperator(a)
12508 }
12509}
12510
12511impl From<AlterOperatorFamily> for Statement {
12512 fn from(a: AlterOperatorFamily) -> Self {
12513 Self::AlterOperatorFamily(a)
12514 }
12515}
12516
12517impl From<AlterOperatorClass> for Statement {
12518 fn from(a: AlterOperatorClass) -> Self {
12519 Self::AlterOperatorClass(a)
12520 }
12521}
12522
12523impl From<Merge> for Statement {
12524 fn from(m: Merge) -> Self {
12525 Self::Merge(m)
12526 }
12527}
12528
12529impl From<AlterUser> for Statement {
12530 fn from(a: AlterUser) -> Self {
12531 Self::AlterUser(a)
12532 }
12533}
12534
12535impl From<DropDomain> for Statement {
12536 fn from(d: DropDomain) -> Self {
12537 Self::DropDomain(d)
12538 }
12539}
12540
12541impl From<ShowCharset> for Statement {
12542 fn from(s: ShowCharset) -> Self {
12543 Self::ShowCharset(s)
12544 }
12545}
12546
12547impl From<ShowObjects> for Statement {
12548 fn from(s: ShowObjects) -> Self {
12549 Self::ShowObjects(s)
12550 }
12551}
12552
12553impl From<Use> for Statement {
12554 fn from(u: Use) -> Self {
12555 Self::Use(u)
12556 }
12557}
12558
12559impl From<CreateFunction> for Statement {
12560 fn from(c: CreateFunction) -> Self {
12561 Self::CreateFunction(c)
12562 }
12563}
12564
12565impl From<CreateTrigger> for Statement {
12566 fn from(c: CreateTrigger) -> Self {
12567 Self::CreateTrigger(c)
12568 }
12569}
12570
12571impl From<DropTrigger> for Statement {
12572 fn from(d: DropTrigger) -> Self {
12573 Self::DropTrigger(d)
12574 }
12575}
12576
12577impl From<DropOperator> for Statement {
12578 fn from(d: DropOperator) -> Self {
12579 Self::DropOperator(d)
12580 }
12581}
12582
12583impl From<DropOperatorFamily> for Statement {
12584 fn from(d: DropOperatorFamily) -> Self {
12585 Self::DropOperatorFamily(d)
12586 }
12587}
12588
12589impl From<DropOperatorClass> for Statement {
12590 fn from(d: DropOperatorClass) -> Self {
12591 Self::DropOperatorClass(d)
12592 }
12593}
12594
12595impl From<DenyStatement> for Statement {
12596 fn from(d: DenyStatement) -> Self {
12597 Self::Deny(d)
12598 }
12599}
12600
12601impl From<CreateDomain> for Statement {
12602 fn from(c: CreateDomain) -> Self {
12603 Self::CreateDomain(c)
12604 }
12605}
12606
12607impl From<RenameTable> for Statement {
12608 fn from(r: RenameTable) -> Self {
12609 vec![r].into()
12610 }
12611}
12612
12613impl From<Vec<RenameTable>> for Statement {
12614 fn from(r: Vec<RenameTable>) -> Self {
12615 Self::RenameTable(r)
12616 }
12617}
12618
12619impl From<PrintStatement> for Statement {
12620 fn from(p: PrintStatement) -> Self {
12621 Self::Print(p)
12622 }
12623}
12624
12625impl From<ReturnStatement> for Statement {
12626 fn from(r: ReturnStatement) -> Self {
12627 Self::Return(r)
12628 }
12629}
12630
12631impl From<ExportData> for Statement {
12632 fn from(e: ExportData) -> Self {
12633 Self::ExportData(e)
12634 }
12635}
12636
12637impl From<CreateUser> for Statement {
12638 fn from(c: CreateUser) -> Self {
12639 Self::CreateUser(c)
12640 }
12641}
12642
12643impl From<VacuumStatement> for Statement {
12644 fn from(v: VacuumStatement) -> Self {
12645 Self::Vacuum(v)
12646 }
12647}
12648
12649impl From<ResetStatement> for Statement {
12650 fn from(r: ResetStatement) -> Self {
12651 Self::Reset(r)
12652 }
12653}
12654
12655#[cfg(test)]
12656mod tests {
12657 use crate::tokenizer::Location;
12658
12659 use super::*;
12660
12661 #[test]
12662 fn test_window_frame_default() {
12663 let window_frame = WindowFrame::default();
12664 assert_eq!(WindowFrameBound::Preceding(None), window_frame.start_bound);
12665 }
12666
12667 #[test]
12668 fn test_grouping_sets_display() {
12669 let grouping_sets = Expr::GroupingSets(vec![
12671 vec![Expr::Identifier(Ident::new("a"))],
12672 vec![Expr::Identifier(Ident::new("b"))],
12673 ]);
12674 assert_eq!("GROUPING SETS ((a), (b))", format!("{grouping_sets}"));
12675
12676 let grouping_sets = Expr::GroupingSets(vec![vec![
12678 Expr::Identifier(Ident::new("a")),
12679 Expr::Identifier(Ident::new("b")),
12680 ]]);
12681 assert_eq!("GROUPING SETS ((a, b))", format!("{grouping_sets}"));
12682
12683 let grouping_sets = Expr::GroupingSets(vec![
12685 vec![
12686 Expr::Identifier(Ident::new("a")),
12687 Expr::Identifier(Ident::new("b")),
12688 ],
12689 vec![
12690 Expr::Identifier(Ident::new("c")),
12691 Expr::Identifier(Ident::new("d")),
12692 ],
12693 ]);
12694 assert_eq!("GROUPING SETS ((a, b), (c, d))", format!("{grouping_sets}"));
12695 }
12696
12697 #[test]
12698 fn test_rollup_display() {
12699 let rollup = Expr::Rollup(vec![vec![Expr::Identifier(Ident::new("a"))]]);
12700 assert_eq!("ROLLUP (a)", format!("{rollup}"));
12701
12702 let rollup = Expr::Rollup(vec![vec![
12703 Expr::Identifier(Ident::new("a")),
12704 Expr::Identifier(Ident::new("b")),
12705 ]]);
12706 assert_eq!("ROLLUP ((a, b))", format!("{rollup}"));
12707
12708 let rollup = Expr::Rollup(vec![
12709 vec![Expr::Identifier(Ident::new("a"))],
12710 vec![Expr::Identifier(Ident::new("b"))],
12711 ]);
12712 assert_eq!("ROLLUP (a, b)", format!("{rollup}"));
12713
12714 let rollup = Expr::Rollup(vec![
12715 vec![Expr::Identifier(Ident::new("a"))],
12716 vec![
12717 Expr::Identifier(Ident::new("b")),
12718 Expr::Identifier(Ident::new("c")),
12719 ],
12720 vec![Expr::Identifier(Ident::new("d"))],
12721 ]);
12722 assert_eq!("ROLLUP (a, (b, c), d)", format!("{rollup}"));
12723 }
12724
12725 #[test]
12726 fn test_cube_display() {
12727 let cube = Expr::Cube(vec![vec![Expr::Identifier(Ident::new("a"))]]);
12728 assert_eq!("CUBE (a)", format!("{cube}"));
12729
12730 let cube = Expr::Cube(vec![vec![
12731 Expr::Identifier(Ident::new("a")),
12732 Expr::Identifier(Ident::new("b")),
12733 ]]);
12734 assert_eq!("CUBE ((a, b))", format!("{cube}"));
12735
12736 let cube = Expr::Cube(vec![
12737 vec![Expr::Identifier(Ident::new("a"))],
12738 vec![Expr::Identifier(Ident::new("b"))],
12739 ]);
12740 assert_eq!("CUBE (a, b)", format!("{cube}"));
12741
12742 let cube = Expr::Cube(vec![
12743 vec![Expr::Identifier(Ident::new("a"))],
12744 vec![
12745 Expr::Identifier(Ident::new("b")),
12746 Expr::Identifier(Ident::new("c")),
12747 ],
12748 vec![Expr::Identifier(Ident::new("d"))],
12749 ]);
12750 assert_eq!("CUBE (a, (b, c), d)", format!("{cube}"));
12751 }
12752
12753 #[test]
12754 fn test_interval_display() {
12755 let interval = Expr::Interval(Interval {
12756 value: Box::new(Expr::Value(
12757 Value::SingleQuotedString(String::from("123:45.67")).with_empty_span(),
12758 )),
12759 leading_field: Some(DateTimeField::Minute),
12760 leading_precision: Some(10),
12761 last_field: Some(DateTimeField::Second),
12762 fractional_seconds_precision: Some(9),
12763 });
12764 assert_eq!(
12765 "INTERVAL '123:45.67' MINUTE (10) TO SECOND (9)",
12766 format!("{interval}"),
12767 );
12768
12769 let interval = Expr::Interval(Interval {
12770 value: Box::new(Expr::Value(
12771 Value::SingleQuotedString(String::from("5")).with_empty_span(),
12772 )),
12773 leading_field: Some(DateTimeField::Second),
12774 leading_precision: Some(1),
12775 last_field: None,
12776 fractional_seconds_precision: Some(3),
12777 });
12778 assert_eq!("INTERVAL '5' SECOND (1, 3)", format!("{interval}"));
12779 }
12780
12781 #[test]
12782 fn test_one_or_many_with_parens_deref() {
12783 use core::ops::Index;
12784
12785 let one = OneOrManyWithParens::One("a");
12786
12787 assert_eq!(one.deref(), &["a"]);
12788 assert_eq!(<OneOrManyWithParens<_> as Deref>::deref(&one), &["a"]);
12789
12790 assert_eq!(one[0], "a");
12791 assert_eq!(one.index(0), &"a");
12792 assert_eq!(
12793 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&one, 0),
12794 &"a"
12795 );
12796
12797 assert_eq!(one.len(), 1);
12798 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&one), 1);
12799
12800 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12801
12802 assert_eq!(many1.deref(), &["b"]);
12803 assert_eq!(<OneOrManyWithParens<_> as Deref>::deref(&many1), &["b"]);
12804
12805 assert_eq!(many1[0], "b");
12806 assert_eq!(many1.index(0), &"b");
12807 assert_eq!(
12808 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many1, 0),
12809 &"b"
12810 );
12811
12812 assert_eq!(many1.len(), 1);
12813 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&many1), 1);
12814
12815 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12816
12817 assert_eq!(many2.deref(), &["c", "d"]);
12818 assert_eq!(
12819 <OneOrManyWithParens<_> as Deref>::deref(&many2),
12820 &["c", "d"]
12821 );
12822
12823 assert_eq!(many2[0], "c");
12824 assert_eq!(many2.index(0), &"c");
12825 assert_eq!(
12826 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many2, 0),
12827 &"c"
12828 );
12829
12830 assert_eq!(many2[1], "d");
12831 assert_eq!(many2.index(1), &"d");
12832 assert_eq!(
12833 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many2, 1),
12834 &"d"
12835 );
12836
12837 assert_eq!(many2.len(), 2);
12838 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&many2), 2);
12839 }
12840
12841 #[test]
12842 fn test_one_or_many_with_parens_as_ref() {
12843 let one = OneOrManyWithParens::One("a");
12844
12845 assert_eq!(one.as_ref(), &["a"]);
12846 assert_eq!(<OneOrManyWithParens<_> as AsRef<_>>::as_ref(&one), &["a"]);
12847
12848 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12849
12850 assert_eq!(many1.as_ref(), &["b"]);
12851 assert_eq!(<OneOrManyWithParens<_> as AsRef<_>>::as_ref(&many1), &["b"]);
12852
12853 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12854
12855 assert_eq!(many2.as_ref(), &["c", "d"]);
12856 assert_eq!(
12857 <OneOrManyWithParens<_> as AsRef<_>>::as_ref(&many2),
12858 &["c", "d"]
12859 );
12860 }
12861
12862 #[test]
12863 fn test_one_or_many_with_parens_ref_into_iter() {
12864 let one = OneOrManyWithParens::One("a");
12865
12866 assert_eq!(Vec::from_iter(&one), vec![&"a"]);
12867
12868 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12869
12870 assert_eq!(Vec::from_iter(&many1), vec![&"b"]);
12871
12872 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12873
12874 assert_eq!(Vec::from_iter(&many2), vec![&"c", &"d"]);
12875 }
12876
12877 #[test]
12878 fn test_one_or_many_with_parens_value_into_iter() {
12879 use core::iter::once;
12880
12881 fn test_steps<I>(ours: OneOrManyWithParens<usize>, inner: I, n: usize)
12883 where
12884 I: IntoIterator<Item = usize, IntoIter: DoubleEndedIterator + Clone> + Clone,
12885 {
12886 fn checks<I>(ours: OneOrManyWithParensIntoIter<usize>, inner: I)
12887 where
12888 I: Iterator<Item = usize> + Clone + DoubleEndedIterator,
12889 {
12890 assert_eq!(ours.size_hint(), inner.size_hint());
12891 assert_eq!(ours.clone().count(), inner.clone().count());
12892
12893 assert_eq!(
12894 ours.clone().fold(1, |a, v| a + v),
12895 inner.clone().fold(1, |a, v| a + v)
12896 );
12897
12898 assert_eq!(Vec::from_iter(ours.clone()), Vec::from_iter(inner.clone()));
12899 assert_eq!(
12900 Vec::from_iter(ours.clone().rev()),
12901 Vec::from_iter(inner.clone().rev())
12902 );
12903 }
12904
12905 let mut ours_next = ours.clone().into_iter();
12906 let mut inner_next = inner.clone().into_iter();
12907
12908 for _ in 0..n {
12909 checks(ours_next.clone(), inner_next.clone());
12910
12911 assert_eq!(ours_next.next(), inner_next.next());
12912 }
12913
12914 let mut ours_next_back = ours.clone().into_iter();
12915 let mut inner_next_back = inner.clone().into_iter();
12916
12917 for _ in 0..n {
12918 checks(ours_next_back.clone(), inner_next_back.clone());
12919
12920 assert_eq!(ours_next_back.next_back(), inner_next_back.next_back());
12921 }
12922
12923 let mut ours_mixed = ours.clone().into_iter();
12924 let mut inner_mixed = inner.clone().into_iter();
12925
12926 for i in 0..n {
12927 checks(ours_mixed.clone(), inner_mixed.clone());
12928
12929 if i % 2 == 0 {
12930 assert_eq!(ours_mixed.next_back(), inner_mixed.next_back());
12931 } else {
12932 assert_eq!(ours_mixed.next(), inner_mixed.next());
12933 }
12934 }
12935
12936 let mut ours_mixed2 = ours.into_iter();
12937 let mut inner_mixed2 = inner.into_iter();
12938
12939 for i in 0..n {
12940 checks(ours_mixed2.clone(), inner_mixed2.clone());
12941
12942 if i % 2 == 0 {
12943 assert_eq!(ours_mixed2.next(), inner_mixed2.next());
12944 } else {
12945 assert_eq!(ours_mixed2.next_back(), inner_mixed2.next_back());
12946 }
12947 }
12948 }
12949
12950 test_steps(OneOrManyWithParens::One(1), once(1), 3);
12951 test_steps(OneOrManyWithParens::Many(vec![2]), vec![2], 3);
12952 test_steps(OneOrManyWithParens::Many(vec![3, 4]), vec![3, 4], 4);
12953 }
12954
12955 #[test]
12958 fn test_ident_ord() {
12959 let mut a = Ident::with_span(Span::new(Location::new(1, 1), Location::new(1, 1)), "a");
12960 let mut b = Ident::with_span(Span::new(Location::new(2, 2), Location::new(2, 2)), "b");
12961
12962 assert!(a < b);
12963 std::mem::swap(&mut a.span, &mut b.span);
12964 assert!(a < b);
12965 }
12966}