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 AlterRoleOperation, CreateRole, Grant, ResetConfig, Revoke, RoleOption, SecondaryRoles,
60 SetConfigValue, Use,
61};
62pub use self::ddl::{
63 Alignment, AlterCollation, AlterCollationOperation, AlterColumnOperation, AlterConnectorOwner,
64 AlterFunction, AlterFunctionAction, AlterFunctionKind, AlterFunctionOperation,
65 AlterIndexOperation, AlterOperator, AlterOperatorClass, AlterOperatorClassOperation,
66 AlterOperatorFamily, AlterOperatorFamilyOperation, AlterOperatorOperation, AlterPolicy,
67 AlterPolicyOperation, AlterSchema, AlterSchemaOperation, AlterTable, AlterTableAlgorithm,
68 AlterTableLock, AlterTableOperation, AlterTableType, AlterType, AlterTypeAddValue,
69 AlterTypeAddValuePosition, AlterTypeOperation, AlterTypeRename, AlterTypeRenameValue,
70 AggregateModifyKind, ClusteredBy, ColumnDef, ColumnOption, ColumnOptionDef, ColumnOptions,
71 ColumnPolicy, ColumnPolicyProperty, ConstraintCharacteristics, CreateAggregate,
72 CreateAggregateOption, CreateCollation, CreateCollationDefinition, CreateConnector,
73 CreateDomain, CreateExtension, CreateForeignDataWrapper, CreateForeignTable, CreateFunction,
74 CreateIndex, CreateOperator, CreateOperatorClass, CreateOperatorFamily, CreatePolicy,
75 CreatePolicyCommand, CreatePolicyType, CreateTable, CreateTextSearchConfiguration,
76 CreateTextSearchDictionary, CreateTextSearchParser, CreateTextSearchTemplate, CreateTrigger,
77 CreateView, Deduplicate, DeferrableInitial, DistStyle, DropBehavior, DropExtension,
78 DropFunction, DropOperator, DropOperatorClass, DropOperatorFamily, DropOperatorSignature,
79 DropPolicy, DropTrigger, FdwRoutineClause, ForValues, FunctionReturnType, GeneratedAs,
80 GeneratedExpressionMode, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
81 IdentityPropertyKind, IdentityPropertyOrder, IndexColumn, IndexOption, IndexType,
82 KeyOrIndexDisplay, Msck, NullsDistinctOption, OperatorArgTypes, OperatorClassItem,
83 OperatorFamilyDropItem, OperatorFamilyItem, OperatorOption, OperatorPurpose, Owner, Partition,
84 PartitionBoundValue, ProcedureParam, ReferentialAction, RenameTableNameKind, ReplicaIdentity,
85 TagsColumnOption, TriggerObjectKind, Truncate, UserDefinedTypeCompositeAttributeDef,
86 UserDefinedTypeInternalLength, UserDefinedTypeRangeOption, UserDefinedTypeRepresentation,
87 UserDefinedTypeSqlDefinitionOption, UserDefinedTypeStorage, ViewColumnDef,
88};
89pub use self::dml::{
90 Delete, Insert, Merge, MergeAction, MergeClause, MergeClauseKind, MergeInsertExpr,
91 MergeInsertKind, MergeUpdateExpr, MultiTableInsertIntoClause, MultiTableInsertType,
92 MultiTableInsertValue, MultiTableInsertValues, MultiTableInsertWhenClause, OutputClause,
93 Update,
94};
95pub use self::operator::{BinaryOperator, UnaryOperator};
96pub use self::query::{
97 AfterMatchSkip, ConnectByKind, Cte, CteAsMaterialized, Distinct, EmptyMatchesMode,
98 ExceptSelectItem, ExcludeSelectItem, ExprWithAlias, ExprWithAliasAndOrderBy, Fetch, ForClause,
99 ForJson, ForXml, FormatClause, GroupByExpr, GroupByWithModifier, IdentWithAlias,
100 IlikeSelectItem, InputFormatClause, Interpolate, InterpolateExpr, Join, JoinConstraint,
101 JoinOperator, JsonTableColumn, JsonTableColumnErrorHandling, JsonTableNamedColumn,
102 JsonTableNestedColumn, LateralView, LimitClause, LockClause, LockType, MatchRecognizePattern,
103 MatchRecognizeSymbol, Measure, NamedWindowDefinition, NamedWindowExpr, NonBlock, Offset,
104 OffsetRows, OpenJsonTableColumn, OrderBy, OrderByExpr, OrderByKind, OrderByOptions,
105 PipeOperator, PivotValueSource, ProjectionSelect, Query, RenameSelectItem,
106 RepetitionQuantifier, ReplaceSelectElement, ReplaceSelectItem, RowsPerMatch, Select,
107 SelectFlavor, SelectInto, SelectItem, SelectItemQualifiedWildcardKind, SelectModifiers,
108 SetExpr, SetOperator, SetQuantifier, Setting, SymbolDefinition, Table, TableAlias,
109 TableAliasColumnDef, TableFactor, TableFunctionArgs, TableIndexHintForClause,
110 TableIndexHintType, TableIndexHints, TableIndexType, TableSample, TableSampleBucket,
111 TableSampleKind, TableSampleMethod, TableSampleModifier, TableSampleQuantity, TableSampleSeed,
112 TableSampleSeedModifier, TableSampleUnit, TableVersion, TableWithJoins, Top, TopQuantity,
113 UpdateTableFromKind, ValueTableMode, Values, WildcardAdditionalOptions, With, WithFill,
114 XmlNamespaceDefinition, XmlPassingArgument, XmlPassingClause, XmlTableColumn,
115 XmlTableColumnOption,
116};
117
118pub use self::trigger::{
119 TriggerEvent, TriggerExecBody, TriggerExecBodyType, TriggerObject, TriggerPeriod,
120 TriggerReferencing, TriggerReferencingType,
121};
122
123pub use self::value::{
124 escape_double_quote_string, escape_quoted_string, DateTimeField, DollarQuotedString,
125 NormalizationForm, QuoteDelimitedString, TrimWhereField, Value, ValueWithSpan,
126};
127
128use crate::ast::helpers::key_value_options::KeyValueOptions;
129use crate::ast::helpers::stmt_data_loading::StageParamsObject;
130
131#[cfg(feature = "visitor")]
132pub use visitor::*;
133
134pub use self::data_type::GeometricTypeKind;
135
136mod data_type;
137mod dcl;
138mod ddl;
139mod dml;
140pub mod helpers;
142pub mod table_constraints;
143pub use table_constraints::{
144 CheckConstraint, ConstraintUsingIndex, ExclusionConstraint, ExclusionElement,
145 ForeignKeyConstraint, FullTextOrSpatialConstraint, IndexConstraint, PrimaryKeyConstraint,
146 TableConstraint, UniqueConstraint,
147};
148mod operator;
149mod query;
150mod spans;
151pub use spans::Spanned;
152
153pub mod comments;
154mod trigger;
155mod value;
156
157#[cfg(feature = "visitor")]
158mod visitor;
159
160pub struct DisplaySeparated<'a, T>
162where
163 T: fmt::Display,
164{
165 slice: &'a [T],
166 sep: &'static str,
167}
168
169impl<T> fmt::Display for DisplaySeparated<'_, T>
170where
171 T: fmt::Display,
172{
173 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
174 let mut delim = "";
175 for t in self.slice {
176 f.write_str(delim)?;
177 delim = self.sep;
178 t.fmt(f)?;
179 }
180 Ok(())
181 }
182}
183
184pub(crate) fn display_separated<'a, T>(slice: &'a [T], sep: &'static str) -> DisplaySeparated<'a, T>
185where
186 T: fmt::Display,
187{
188 DisplaySeparated { slice, sep }
189}
190
191pub(crate) fn display_comma_separated<T>(slice: &[T]) -> DisplaySeparated<'_, T>
192where
193 T: fmt::Display,
194{
195 DisplaySeparated { slice, sep: ", " }
196}
197
198fn format_statement_list(f: &mut fmt::Formatter, statements: &[Statement]) -> fmt::Result {
201 write!(f, "{}", display_separated(statements, "; "))?;
202 write!(f, ";")
205}
206
207#[derive(Debug, Clone)]
209#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
210#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
211pub struct Ident {
212 pub value: String,
214 pub quote_style: Option<char>,
217 pub span: Span,
219}
220
221impl PartialEq for Ident {
222 fn eq(&self, other: &Self) -> bool {
223 let Ident {
224 value,
225 quote_style,
226 span: _,
228 } = self;
229
230 value == &other.value && quote_style == &other.quote_style
231 }
232}
233
234impl core::hash::Hash for Ident {
235 fn hash<H: hash::Hasher>(&self, state: &mut H) {
236 let Ident {
237 value,
238 quote_style,
239 span: _,
241 } = self;
242
243 value.hash(state);
244 quote_style.hash(state);
245 }
246}
247
248impl Eq for Ident {}
249
250impl PartialOrd for Ident {
251 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
252 Some(self.cmp(other))
253 }
254}
255
256impl Ord for Ident {
257 fn cmp(&self, other: &Self) -> Ordering {
258 let Ident {
259 value,
260 quote_style,
261 span: _,
263 } = self;
264
265 let Ident {
266 value: other_value,
267 quote_style: other_quote_style,
268 span: _,
270 } = other;
271
272 value
274 .cmp(other_value)
275 .then_with(|| quote_style.cmp(other_quote_style))
276 }
277}
278
279impl Ident {
280 pub fn new<S>(value: S) -> Self
282 where
283 S: Into<String>,
284 {
285 Ident {
286 value: value.into(),
287 quote_style: None,
288 span: Span::empty(),
289 }
290 }
291
292 pub fn with_quote<S>(quote: char, value: S) -> Self
295 where
296 S: Into<String>,
297 {
298 assert!(quote == '\'' || quote == '"' || quote == '`' || quote == '[');
299 Ident {
300 value: value.into(),
301 quote_style: Some(quote),
302 span: Span::empty(),
303 }
304 }
305
306 pub fn with_span<S>(span: Span, value: S) -> Self
308 where
309 S: Into<String>,
310 {
311 Ident {
312 value: value.into(),
313 quote_style: None,
314 span,
315 }
316 }
317
318 pub fn with_quote_and_span<S>(quote: char, span: Span, value: S) -> Self
320 where
321 S: Into<String>,
322 {
323 assert!(quote == '\'' || quote == '"' || quote == '`' || quote == '[');
324 Ident {
325 value: value.into(),
326 quote_style: Some(quote),
327 span,
328 }
329 }
330}
331
332impl From<&str> for Ident {
333 fn from(value: &str) -> Self {
334 Ident {
335 value: value.to_string(),
336 quote_style: None,
337 span: Span::empty(),
338 }
339 }
340}
341
342impl fmt::Display for Ident {
343 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
344 match self.quote_style {
345 Some(q) if q == '"' || q == '\'' || q == '`' => {
346 let escaped = value::escape_quoted_string(&self.value, q);
347 write!(f, "{q}{escaped}{q}")
348 }
349 Some('[') => write!(f, "[{}]", self.value),
350 None => f.write_str(&self.value),
351 _ => panic!("unexpected quote style"),
352 }
353 }
354}
355
356#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
358#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
359#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
360pub struct ObjectName(pub Vec<ObjectNamePart>);
361
362impl From<Vec<Ident>> for ObjectName {
363 fn from(idents: Vec<Ident>) -> Self {
364 ObjectName(idents.into_iter().map(ObjectNamePart::Identifier).collect())
365 }
366}
367
368impl From<Ident> for ObjectName {
369 fn from(ident: Ident) -> Self {
370 ObjectName(vec![ObjectNamePart::Identifier(ident)])
371 }
372}
373
374impl fmt::Display for ObjectName {
375 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
376 write!(f, "{}", display_separated(&self.0, "."))
377 }
378}
379
380#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
382#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
383#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
384pub enum ObjectNamePart {
385 Identifier(Ident),
387 Function(ObjectNamePartFunction),
389}
390
391impl ObjectNamePart {
392 pub fn as_ident(&self) -> Option<&Ident> {
394 match self {
395 ObjectNamePart::Identifier(ident) => Some(ident),
396 ObjectNamePart::Function(_) => None,
397 }
398 }
399}
400
401impl fmt::Display for ObjectNamePart {
402 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
403 match self {
404 ObjectNamePart::Identifier(ident) => write!(f, "{ident}"),
405 ObjectNamePart::Function(func) => write!(f, "{func}"),
406 }
407 }
408}
409
410#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
415#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
416#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
417pub struct ObjectNamePartFunction {
418 pub name: Ident,
420 pub args: Vec<FunctionArg>,
422}
423
424impl fmt::Display for ObjectNamePartFunction {
425 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
426 write!(f, "{}(", self.name)?;
427 write!(f, "{})", display_comma_separated(&self.args))
428 }
429}
430
431#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
434#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
435#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
436pub struct Array {
437 pub elem: Vec<Expr>,
439
440 pub named: bool,
442}
443
444impl fmt::Display for Array {
445 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
446 write!(
447 f,
448 "{}[{}]",
449 if self.named { "ARRAY" } else { "" },
450 display_comma_separated(&self.elem)
451 )
452 }
453}
454
455#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
464#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
465#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
466pub struct Interval {
467 pub value: Box<Expr>,
469 pub leading_field: Option<DateTimeField>,
471 pub leading_precision: Option<u64>,
473 pub last_field: Option<DateTimeField>,
475 pub fractional_seconds_precision: Option<u64>,
479}
480
481impl fmt::Display for Interval {
482 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
483 let value = self.value.as_ref();
484 match (
485 &self.leading_field,
486 self.leading_precision,
487 self.fractional_seconds_precision,
488 ) {
489 (
490 Some(DateTimeField::Second),
491 Some(leading_precision),
492 Some(fractional_seconds_precision),
493 ) => {
494 assert!(self.last_field.is_none());
497 write!(
498 f,
499 "INTERVAL {value} SECOND ({leading_precision}, {fractional_seconds_precision})"
500 )
501 }
502 _ => {
503 write!(f, "INTERVAL {value}")?;
504 if let Some(leading_field) = &self.leading_field {
505 write!(f, " {leading_field}")?;
506 }
507 if let Some(leading_precision) = self.leading_precision {
508 write!(f, " ({leading_precision})")?;
509 }
510 if let Some(last_field) = &self.last_field {
511 write!(f, " TO {last_field}")?;
512 }
513 if let Some(fractional_seconds_precision) = self.fractional_seconds_precision {
514 write!(f, " ({fractional_seconds_precision})")?;
515 }
516 Ok(())
517 }
518 }
519 }
520}
521
522#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
526#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
527#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
528pub struct StructField {
529 pub field_name: Option<Ident>,
531 pub field_type: DataType,
533 pub options: Option<Vec<SqlOption>>,
536}
537
538impl fmt::Display for StructField {
539 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
540 if let Some(name) = &self.field_name {
541 write!(f, "{name} {}", self.field_type)?;
542 } else {
543 write!(f, "{}", self.field_type)?;
544 }
545 if let Some(options) = &self.options {
546 write!(f, " OPTIONS({})", display_separated(options, ", "))
547 } else {
548 Ok(())
549 }
550 }
551}
552
553#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
557#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
558#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
559pub struct UnionField {
560 pub field_name: Ident,
562 pub field_type: DataType,
564}
565
566impl fmt::Display for UnionField {
567 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
568 write!(f, "{} {}", self.field_name, self.field_type)
569 }
570}
571
572#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
576#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
577#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
578pub struct DictionaryField {
579 pub key: Ident,
581 pub value: Box<Expr>,
583}
584
585impl fmt::Display for DictionaryField {
586 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
587 write!(f, "{}: {}", self.key, self.value)
588 }
589}
590
591#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
593#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
594#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
595pub struct Map {
596 pub entries: Vec<MapEntry>,
598}
599
600impl Display for Map {
601 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
602 write!(f, "MAP {{{}}}", display_comma_separated(&self.entries))
603 }
604}
605
606#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
610#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
611#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
612pub struct MapEntry {
613 pub key: Box<Expr>,
615 pub value: Box<Expr>,
617}
618
619impl fmt::Display for MapEntry {
620 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
621 write!(f, "{}: {}", self.key, self.value)
622 }
623}
624
625#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
628#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
629#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
630pub enum CastFormat {
631 Value(ValueWithSpan),
633 ValueAtTimeZone(ValueWithSpan, ValueWithSpan),
635}
636
637#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
639#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
640#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
641pub enum JsonPathElem {
642 Dot {
646 key: String,
648 quoted: bool,
650 },
651 Bracket {
656 key: Expr,
658 },
659 ColonBracket {
664 key: Expr,
666 },
667}
668
669#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
674#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
675#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
676pub struct JsonPath {
677 pub path: Vec<JsonPathElem>,
679}
680
681impl fmt::Display for JsonPath {
682 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
683 for (i, elem) in self.path.iter().enumerate() {
684 match elem {
685 JsonPathElem::Dot { key, quoted } => {
686 if i == 0 {
687 write!(f, ":")?;
688 } else {
689 write!(f, ".")?;
690 }
691
692 if *quoted {
693 write!(f, "\"{}\"", escape_double_quote_string(key))?;
694 } else {
695 write!(f, "{key}")?;
696 }
697 }
698 JsonPathElem::Bracket { key } => {
699 write!(f, "[{key}]")?;
700 }
701 JsonPathElem::ColonBracket { key } => {
702 write!(f, ":[{key}]")?;
703 }
704 }
705 }
706 Ok(())
707 }
708}
709
710#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
712#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
713#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
714pub enum CastKind {
715 Cast,
717 TryCast,
722 SafeCast,
726 DoubleColon,
728}
729
730#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
734#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
735#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
736pub enum ConstraintReferenceMatchKind {
737 Full,
739 Partial,
741 Simple,
743}
744
745impl fmt::Display for ConstraintReferenceMatchKind {
746 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
747 match self {
748 Self::Full => write!(f, "MATCH FULL"),
749 Self::Partial => write!(f, "MATCH PARTIAL"),
750 Self::Simple => write!(f, "MATCH SIMPLE"),
751 }
752 }
753}
754
755#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
762#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
763#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
764pub enum ExtractSyntax {
765 From,
767 Comma,
769}
770
771#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
780#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
781#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
782pub enum CeilFloorKind {
783 DateTimeField(DateTimeField),
785 Scale(ValueWithSpan),
787}
788
789#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
792#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
793#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
794pub struct CaseWhen {
795 pub condition: Expr,
797 pub result: Expr,
799}
800
801impl fmt::Display for CaseWhen {
802 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
803 f.write_str("WHEN ")?;
804 self.condition.fmt(f)?;
805 f.write_str(" THEN")?;
806 SpaceOrNewline.fmt(f)?;
807 Indent(&self.result).fmt(f)?;
808 Ok(())
809 }
810}
811
812#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
830#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
831#[cfg_attr(
832 feature = "visitor",
833 derive(Visit, VisitMut),
834 visit(with = "visit_expr")
835)]
836pub enum Expr {
837 Identifier(Ident),
839 CompoundIdentifier(Vec<Ident>),
841 CompoundFieldAccess {
860 root: Box<Expr>,
862 access_chain: Vec<AccessExpr>,
864 },
865 JsonAccess {
871 value: Box<Expr>,
873 path: JsonPath,
875 },
876 IsFalse(Box<Expr>),
878 IsNotFalse(Box<Expr>),
880 IsTrue(Box<Expr>),
882 IsNotTrue(Box<Expr>),
884 IsNull(Box<Expr>),
886 IsNotNull(Box<Expr>),
888 IsUnknown(Box<Expr>),
890 IsNotUnknown(Box<Expr>),
892 IsDistinctFrom(Box<Expr>, Box<Expr>),
894 IsNotDistinctFrom(Box<Expr>, Box<Expr>),
896 IsNormalized {
898 expr: Box<Expr>,
900 form: Option<NormalizationForm>,
902 negated: bool,
904 },
905 InList {
907 expr: Box<Expr>,
909 list: Vec<Expr>,
911 negated: bool,
913 },
914 InSubquery {
916 expr: Box<Expr>,
918 subquery: Box<Query>,
920 negated: bool,
922 },
923 InUnnest {
925 expr: Box<Expr>,
927 array_expr: Box<Expr>,
929 negated: bool,
931 },
932 Between {
934 expr: Box<Expr>,
936 negated: bool,
938 low: Box<Expr>,
940 high: Box<Expr>,
942 },
943 BinaryOp {
945 left: Box<Expr>,
947 op: BinaryOperator,
949 right: Box<Expr>,
951 },
952 Like {
954 negated: bool,
956 any: bool,
959 expr: Box<Expr>,
961 pattern: Box<Expr>,
963 escape_char: Option<ValueWithSpan>,
965 },
966 ILike {
968 negated: bool,
970 any: bool,
973 expr: Box<Expr>,
975 pattern: Box<Expr>,
977 escape_char: Option<ValueWithSpan>,
979 },
980 SimilarTo {
982 negated: bool,
984 expr: Box<Expr>,
986 pattern: Box<Expr>,
988 escape_char: Option<ValueWithSpan>,
990 },
991 RLike {
993 negated: bool,
995 expr: Box<Expr>,
997 pattern: Box<Expr>,
999 regexp: bool,
1001 },
1002 AnyOp {
1005 left: Box<Expr>,
1007 compare_op: BinaryOperator,
1009 right: Box<Expr>,
1011 is_some: bool,
1013 },
1014 AllOp {
1017 left: Box<Expr>,
1019 compare_op: BinaryOperator,
1021 right: Box<Expr>,
1023 },
1024
1025 UnaryOp {
1027 op: UnaryOperator,
1029 expr: Box<Expr>,
1031 },
1032 Convert {
1034 is_try: bool,
1037 expr: Box<Expr>,
1039 data_type: Option<DataType>,
1041 charset: Option<ObjectName>,
1043 target_before_value: bool,
1045 styles: Vec<Expr>,
1049 },
1050 Cast {
1052 kind: CastKind,
1054 expr: Box<Expr>,
1056 data_type: DataType,
1058 array: bool,
1064 format: Option<CastFormat>,
1068 },
1069 AtTimeZone {
1071 timestamp: Box<Expr>,
1073 time_zone: Box<Expr>,
1075 },
1076 Extract {
1084 field: DateTimeField,
1086 syntax: ExtractSyntax,
1088 expr: Box<Expr>,
1090 },
1091 Ceil {
1098 expr: Box<Expr>,
1100 field: CeilFloorKind,
1102 },
1103 Floor {
1110 expr: Box<Expr>,
1112 field: CeilFloorKind,
1114 },
1115 Position {
1119 expr: Box<Expr>,
1121 r#in: Box<Expr>,
1123 },
1124 Substring {
1132 expr: Box<Expr>,
1134 substring_from: Option<Box<Expr>>,
1136 substring_for: Option<Box<Expr>>,
1138
1139 special: bool,
1143
1144 shorthand: bool,
1147 },
1148 Trim {
1154 trim_where: Option<TrimWhereField>,
1156 trim_what: Option<Box<Expr>>,
1158 expr: Box<Expr>,
1160 trim_characters: Option<Vec<Expr>>,
1162 },
1163 Overlay {
1167 expr: Box<Expr>,
1169 overlay_what: Box<Expr>,
1171 overlay_from: Box<Expr>,
1173 overlay_for: Option<Box<Expr>>,
1175 },
1176 Collate {
1178 expr: Box<Expr>,
1180 collation: ObjectName,
1182 },
1183 Nested(Box<Expr>),
1185 Value(ValueWithSpan),
1187 Prefixed {
1191 prefix: Ident,
1193 value: Box<Expr>,
1196 },
1197 TypedString(TypedString),
1201 Function(Function),
1203 Case {
1209 case_token: AttachedToken,
1211 end_token: AttachedToken,
1213 operand: Option<Box<Expr>>,
1215 conditions: Vec<CaseWhen>,
1217 else_result: Option<Box<Expr>>,
1219 },
1220 Exists {
1223 subquery: Box<Query>,
1225 negated: bool,
1227 },
1228 Subquery(Box<Query>),
1231 GroupingSets(Vec<Vec<Expr>>),
1233 Cube(Vec<Vec<Expr>>),
1235 Rollup(Vec<Vec<Expr>>),
1237 Tuple(Vec<Expr>),
1239 Struct {
1248 values: Vec<Expr>,
1250 fields: Vec<StructField>,
1252 },
1253 Named {
1261 expr: Box<Expr>,
1263 name: Ident,
1265 },
1266 Dictionary(Vec<DictionaryField>),
1274 Map(Map),
1282 Array(Array),
1284 Interval(Interval),
1286 MatchAgainst {
1297 columns: Vec<ObjectName>,
1299 match_value: ValueWithSpan,
1301 opt_search_modifier: Option<SearchModifier>,
1303 },
1304 Wildcard(AttachedToken),
1306 QualifiedWildcard(ObjectName, AttachedToken),
1309 OuterJoin(Box<Expr>),
1324 Prior(Box<Expr>),
1326 Lambda(LambdaFunction),
1337 MemberOf(MemberOf),
1339}
1340
1341impl Expr {
1342 pub fn value(value: impl Into<ValueWithSpan>) -> Self {
1344 Expr::Value(value.into())
1345 }
1346}
1347
1348#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1350#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1351#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1352pub enum Subscript {
1353 Index {
1355 index: Expr,
1357 },
1358
1359 Slice {
1381 lower_bound: Option<Expr>,
1383 upper_bound: Option<Expr>,
1385 stride: Option<Expr>,
1387 },
1388}
1389
1390impl fmt::Display for Subscript {
1391 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1392 match self {
1393 Subscript::Index { index } => write!(f, "{index}"),
1394 Subscript::Slice {
1395 lower_bound,
1396 upper_bound,
1397 stride,
1398 } => {
1399 if let Some(lower) = lower_bound {
1400 write!(f, "{lower}")?;
1401 }
1402 write!(f, ":")?;
1403 if let Some(upper) = upper_bound {
1404 write!(f, "{upper}")?;
1405 }
1406 if let Some(stride) = stride {
1407 write!(f, ":")?;
1408 write!(f, "{stride}")?;
1409 }
1410 Ok(())
1411 }
1412 }
1413 }
1414}
1415
1416#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1419#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1420#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1421pub enum AccessExpr {
1422 Dot(Expr),
1424 Subscript(Subscript),
1426}
1427
1428impl fmt::Display for AccessExpr {
1429 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1430 match self {
1431 AccessExpr::Dot(expr) => write!(f, ".{expr}"),
1432 AccessExpr::Subscript(subscript) => write!(f, "[{subscript}]"),
1433 }
1434 }
1435}
1436
1437#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1439#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1440#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1441pub struct LambdaFunction {
1442 pub params: OneOrManyWithParens<LambdaFunctionParameter>,
1444 pub body: Box<Expr>,
1446 pub syntax: LambdaSyntax,
1448}
1449
1450impl fmt::Display for LambdaFunction {
1451 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1452 match self.syntax {
1453 LambdaSyntax::Arrow => write!(f, "{} -> {}", self.params, self.body),
1454 LambdaSyntax::LambdaKeyword => {
1455 write!(f, "lambda ")?;
1458 match &self.params {
1459 OneOrManyWithParens::One(p) => write!(f, "{p}")?,
1460 OneOrManyWithParens::Many(ps) => write!(f, "{}", display_comma_separated(ps))?,
1461 };
1462 write!(f, " : {}", self.body)
1463 }
1464 }
1465 }
1466}
1467
1468#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1470#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1471#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1472pub struct LambdaFunctionParameter {
1473 pub name: Ident,
1475 pub data_type: Option<DataType>,
1478}
1479
1480impl fmt::Display for LambdaFunctionParameter {
1481 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1482 match &self.data_type {
1483 Some(dt) => write!(f, "{} {}", self.name, dt),
1484 None => write!(f, "{}", self.name),
1485 }
1486 }
1487}
1488
1489#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy)]
1491#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1492#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1493pub enum LambdaSyntax {
1494 Arrow,
1501 LambdaKeyword,
1506}
1507
1508#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1531#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1532#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1533pub enum OneOrManyWithParens<T> {
1534 One(T),
1536 Many(Vec<T>),
1538}
1539
1540impl<T> Deref for OneOrManyWithParens<T> {
1541 type Target = [T];
1542
1543 fn deref(&self) -> &[T] {
1544 match self {
1545 OneOrManyWithParens::One(one) => core::slice::from_ref(one),
1546 OneOrManyWithParens::Many(many) => many,
1547 }
1548 }
1549}
1550
1551impl<T> AsRef<[T]> for OneOrManyWithParens<T> {
1552 fn as_ref(&self) -> &[T] {
1553 self
1554 }
1555}
1556
1557impl<'a, T> IntoIterator for &'a OneOrManyWithParens<T> {
1558 type Item = &'a T;
1559 type IntoIter = core::slice::Iter<'a, T>;
1560
1561 fn into_iter(self) -> Self::IntoIter {
1562 self.iter()
1563 }
1564}
1565
1566#[derive(Debug, Clone)]
1568pub struct OneOrManyWithParensIntoIter<T> {
1569 inner: OneOrManyWithParensIntoIterInner<T>,
1570}
1571
1572#[derive(Debug, Clone)]
1573enum OneOrManyWithParensIntoIterInner<T> {
1574 One(core::iter::Once<T>),
1575 Many(<Vec<T> as IntoIterator>::IntoIter),
1576}
1577
1578impl<T> core::iter::FusedIterator for OneOrManyWithParensIntoIter<T>
1579where
1580 core::iter::Once<T>: core::iter::FusedIterator,
1581 <Vec<T> as IntoIterator>::IntoIter: core::iter::FusedIterator,
1582{
1583}
1584
1585impl<T> core::iter::ExactSizeIterator for OneOrManyWithParensIntoIter<T>
1586where
1587 core::iter::Once<T>: core::iter::ExactSizeIterator,
1588 <Vec<T> as IntoIterator>::IntoIter: core::iter::ExactSizeIterator,
1589{
1590}
1591
1592impl<T> core::iter::Iterator for OneOrManyWithParensIntoIter<T> {
1593 type Item = T;
1594
1595 fn next(&mut self) -> Option<Self::Item> {
1596 match &mut self.inner {
1597 OneOrManyWithParensIntoIterInner::One(one) => one.next(),
1598 OneOrManyWithParensIntoIterInner::Many(many) => many.next(),
1599 }
1600 }
1601
1602 fn size_hint(&self) -> (usize, Option<usize>) {
1603 match &self.inner {
1604 OneOrManyWithParensIntoIterInner::One(one) => one.size_hint(),
1605 OneOrManyWithParensIntoIterInner::Many(many) => many.size_hint(),
1606 }
1607 }
1608
1609 fn count(self) -> usize
1610 where
1611 Self: Sized,
1612 {
1613 match self.inner {
1614 OneOrManyWithParensIntoIterInner::One(one) => one.count(),
1615 OneOrManyWithParensIntoIterInner::Many(many) => many.count(),
1616 }
1617 }
1618
1619 fn fold<B, F>(mut self, init: B, f: F) -> B
1620 where
1621 Self: Sized,
1622 F: FnMut(B, Self::Item) -> B,
1623 {
1624 match &mut self.inner {
1625 OneOrManyWithParensIntoIterInner::One(one) => one.fold(init, f),
1626 OneOrManyWithParensIntoIterInner::Many(many) => many.fold(init, f),
1627 }
1628 }
1629}
1630
1631impl<T> core::iter::DoubleEndedIterator for OneOrManyWithParensIntoIter<T> {
1632 fn next_back(&mut self) -> Option<Self::Item> {
1633 match &mut self.inner {
1634 OneOrManyWithParensIntoIterInner::One(one) => one.next_back(),
1635 OneOrManyWithParensIntoIterInner::Many(many) => many.next_back(),
1636 }
1637 }
1638}
1639
1640impl<T> IntoIterator for OneOrManyWithParens<T> {
1641 type Item = T;
1642
1643 type IntoIter = OneOrManyWithParensIntoIter<T>;
1644
1645 fn into_iter(self) -> Self::IntoIter {
1646 let inner = match self {
1647 OneOrManyWithParens::One(one) => {
1648 OneOrManyWithParensIntoIterInner::One(core::iter::once(one))
1649 }
1650 OneOrManyWithParens::Many(many) => {
1651 OneOrManyWithParensIntoIterInner::Many(many.into_iter())
1652 }
1653 };
1654
1655 OneOrManyWithParensIntoIter { inner }
1656 }
1657}
1658
1659impl<T> fmt::Display for OneOrManyWithParens<T>
1660where
1661 T: fmt::Display,
1662{
1663 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1664 match self {
1665 OneOrManyWithParens::One(value) => write!(f, "{value}"),
1666 OneOrManyWithParens::Many(values) => {
1667 write!(f, "({})", display_comma_separated(values))
1668 }
1669 }
1670 }
1671}
1672
1673impl fmt::Display for CastFormat {
1674 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1675 match self {
1676 CastFormat::Value(v) => write!(f, "{v}"),
1677 CastFormat::ValueAtTimeZone(v, tz) => write!(f, "{v} AT TIME ZONE {tz}"),
1678 }
1679 }
1680}
1681
1682impl fmt::Display for Expr {
1683 #[cfg_attr(feature = "recursive-protection", recursive::recursive)]
1684 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1685 match self {
1686 Expr::Identifier(s) => write!(f, "{s}"),
1687 Expr::Wildcard(_) => f.write_str("*"),
1688 Expr::QualifiedWildcard(prefix, _) => write!(f, "{prefix}.*"),
1689 Expr::CompoundIdentifier(s) => write!(f, "{}", display_separated(s, ".")),
1690 Expr::CompoundFieldAccess { root, access_chain } => {
1691 write!(f, "{root}")?;
1692 for field in access_chain {
1693 write!(f, "{field}")?;
1694 }
1695 Ok(())
1696 }
1697 Expr::IsTrue(ast) => write!(f, "{ast} IS TRUE"),
1698 Expr::IsNotTrue(ast) => write!(f, "{ast} IS NOT TRUE"),
1699 Expr::IsFalse(ast) => write!(f, "{ast} IS FALSE"),
1700 Expr::IsNotFalse(ast) => write!(f, "{ast} IS NOT FALSE"),
1701 Expr::IsNull(ast) => write!(f, "{ast} IS NULL"),
1702 Expr::IsNotNull(ast) => write!(f, "{ast} IS NOT NULL"),
1703 Expr::IsUnknown(ast) => write!(f, "{ast} IS UNKNOWN"),
1704 Expr::IsNotUnknown(ast) => write!(f, "{ast} IS NOT UNKNOWN"),
1705 Expr::InList {
1706 expr,
1707 list,
1708 negated,
1709 } => write!(
1710 f,
1711 "{} {}IN ({})",
1712 expr,
1713 if *negated { "NOT " } else { "" },
1714 display_comma_separated(list)
1715 ),
1716 Expr::InSubquery {
1717 expr,
1718 subquery,
1719 negated,
1720 } => write!(
1721 f,
1722 "{} {}IN ({})",
1723 expr,
1724 if *negated { "NOT " } else { "" },
1725 subquery
1726 ),
1727 Expr::InUnnest {
1728 expr,
1729 array_expr,
1730 negated,
1731 } => write!(
1732 f,
1733 "{} {}IN UNNEST({})",
1734 expr,
1735 if *negated { "NOT " } else { "" },
1736 array_expr
1737 ),
1738 Expr::Between {
1739 expr,
1740 negated,
1741 low,
1742 high,
1743 } => write!(
1744 f,
1745 "{} {}BETWEEN {} AND {}",
1746 expr,
1747 if *negated { "NOT " } else { "" },
1748 low,
1749 high
1750 ),
1751 Expr::BinaryOp { left, op, right } => write!(f, "{left} {op} {right}"),
1752 Expr::Like {
1753 negated,
1754 expr,
1755 pattern,
1756 escape_char,
1757 any,
1758 } => match escape_char {
1759 Some(ch) => write!(
1760 f,
1761 "{} {}LIKE {}{} ESCAPE {}",
1762 expr,
1763 if *negated { "NOT " } else { "" },
1764 if *any { "ANY " } else { "" },
1765 pattern,
1766 ch
1767 ),
1768 _ => write!(
1769 f,
1770 "{} {}LIKE {}{}",
1771 expr,
1772 if *negated { "NOT " } else { "" },
1773 if *any { "ANY " } else { "" },
1774 pattern
1775 ),
1776 },
1777 Expr::ILike {
1778 negated,
1779 expr,
1780 pattern,
1781 escape_char,
1782 any,
1783 } => match escape_char {
1784 Some(ch) => write!(
1785 f,
1786 "{} {}ILIKE {}{} ESCAPE {}",
1787 expr,
1788 if *negated { "NOT " } else { "" },
1789 if *any { "ANY" } else { "" },
1790 pattern,
1791 ch
1792 ),
1793 _ => write!(
1794 f,
1795 "{} {}ILIKE {}{}",
1796 expr,
1797 if *negated { "NOT " } else { "" },
1798 if *any { "ANY " } else { "" },
1799 pattern
1800 ),
1801 },
1802 Expr::RLike {
1803 negated,
1804 expr,
1805 pattern,
1806 regexp,
1807 } => write!(
1808 f,
1809 "{} {}{} {}",
1810 expr,
1811 if *negated { "NOT " } else { "" },
1812 if *regexp { "REGEXP" } else { "RLIKE" },
1813 pattern
1814 ),
1815 Expr::IsNormalized {
1816 expr,
1817 form,
1818 negated,
1819 } => {
1820 let not_ = if *negated { "NOT " } else { "" };
1821 if form.is_none() {
1822 write!(f, "{expr} IS {not_}NORMALIZED")
1823 } else {
1824 write!(
1825 f,
1826 "{} IS {}{} NORMALIZED",
1827 expr,
1828 not_,
1829 form.as_ref().unwrap()
1830 )
1831 }
1832 }
1833 Expr::SimilarTo {
1834 negated,
1835 expr,
1836 pattern,
1837 escape_char,
1838 } => match escape_char {
1839 Some(ch) => write!(
1840 f,
1841 "{} {}SIMILAR TO {} ESCAPE {}",
1842 expr,
1843 if *negated { "NOT " } else { "" },
1844 pattern,
1845 ch
1846 ),
1847 _ => write!(
1848 f,
1849 "{} {}SIMILAR TO {}",
1850 expr,
1851 if *negated { "NOT " } else { "" },
1852 pattern
1853 ),
1854 },
1855 Expr::AnyOp {
1856 left,
1857 compare_op,
1858 right,
1859 is_some,
1860 } => {
1861 let add_parens = !matches!(right.as_ref(), Expr::Subquery(_));
1862 write!(
1863 f,
1864 "{left} {compare_op} {}{}{right}{}",
1865 if *is_some { "SOME" } else { "ANY" },
1866 if add_parens { "(" } else { "" },
1867 if add_parens { ")" } else { "" },
1868 )
1869 }
1870 Expr::AllOp {
1871 left,
1872 compare_op,
1873 right,
1874 } => {
1875 let add_parens = !matches!(right.as_ref(), Expr::Subquery(_));
1876 write!(
1877 f,
1878 "{left} {compare_op} ALL{}{right}{}",
1879 if add_parens { "(" } else { "" },
1880 if add_parens { ")" } else { "" },
1881 )
1882 }
1883 Expr::UnaryOp { op, expr } => {
1884 if op == &UnaryOperator::PGPostfixFactorial {
1885 write!(f, "{expr}{op}")
1886 } else if matches!(
1887 op,
1888 UnaryOperator::Not
1889 | UnaryOperator::Hash
1890 | UnaryOperator::AtDashAt
1891 | UnaryOperator::DoubleAt
1892 | UnaryOperator::QuestionDash
1893 | UnaryOperator::QuestionPipe
1894 ) {
1895 write!(f, "{op} {expr}")
1896 } else {
1897 write!(f, "{op}{expr}")
1898 }
1899 }
1900 Expr::Convert {
1901 is_try,
1902 expr,
1903 target_before_value,
1904 data_type,
1905 charset,
1906 styles,
1907 } => {
1908 write!(f, "{}CONVERT(", if *is_try { "TRY_" } else { "" })?;
1909 if let Some(data_type) = data_type {
1910 if let Some(charset) = charset {
1911 write!(f, "{expr}, {data_type} CHARACTER SET {charset}")
1912 } else if *target_before_value {
1913 write!(f, "{data_type}, {expr}")
1914 } else {
1915 write!(f, "{expr}, {data_type}")
1916 }
1917 } else if let Some(charset) = charset {
1918 write!(f, "{expr} USING {charset}")
1919 } else {
1920 write!(f, "{expr}") }?;
1922 if !styles.is_empty() {
1923 write!(f, ", {}", display_comma_separated(styles))?;
1924 }
1925 write!(f, ")")
1926 }
1927 Expr::Cast {
1928 kind,
1929 expr,
1930 data_type,
1931 array,
1932 format,
1933 } => match kind {
1934 CastKind::Cast => {
1935 write!(f, "CAST({expr} AS {data_type}")?;
1936 if *array {
1937 write!(f, " ARRAY")?;
1938 }
1939 if let Some(format) = format {
1940 write!(f, " FORMAT {format}")?;
1941 }
1942 write!(f, ")")
1943 }
1944 CastKind::TryCast => {
1945 if let Some(format) = format {
1946 write!(f, "TRY_CAST({expr} AS {data_type} FORMAT {format})")
1947 } else {
1948 write!(f, "TRY_CAST({expr} AS {data_type})")
1949 }
1950 }
1951 CastKind::SafeCast => {
1952 if let Some(format) = format {
1953 write!(f, "SAFE_CAST({expr} AS {data_type} FORMAT {format})")
1954 } else {
1955 write!(f, "SAFE_CAST({expr} AS {data_type})")
1956 }
1957 }
1958 CastKind::DoubleColon => {
1959 write!(f, "{expr}::{data_type}")
1960 }
1961 },
1962 Expr::Extract {
1963 field,
1964 syntax,
1965 expr,
1966 } => match syntax {
1967 ExtractSyntax::From => write!(f, "EXTRACT({field} FROM {expr})"),
1968 ExtractSyntax::Comma => write!(f, "EXTRACT({field}, {expr})"),
1969 },
1970 Expr::Ceil { expr, field } => match field {
1971 CeilFloorKind::DateTimeField(DateTimeField::NoDateTime) => {
1972 write!(f, "CEIL({expr})")
1973 }
1974 CeilFloorKind::DateTimeField(dt_field) => write!(f, "CEIL({expr} TO {dt_field})"),
1975 CeilFloorKind::Scale(s) => write!(f, "CEIL({expr}, {s})"),
1976 },
1977 Expr::Floor { expr, field } => match field {
1978 CeilFloorKind::DateTimeField(DateTimeField::NoDateTime) => {
1979 write!(f, "FLOOR({expr})")
1980 }
1981 CeilFloorKind::DateTimeField(dt_field) => write!(f, "FLOOR({expr} TO {dt_field})"),
1982 CeilFloorKind::Scale(s) => write!(f, "FLOOR({expr}, {s})"),
1983 },
1984 Expr::Position { expr, r#in } => write!(f, "POSITION({expr} IN {in})"),
1985 Expr::Collate { expr, collation } => write!(f, "{expr} COLLATE {collation}"),
1986 Expr::Nested(ast) => write!(f, "({ast})"),
1987 Expr::Value(v) => write!(f, "{v}"),
1988 Expr::Prefixed { prefix, value } => write!(f, "{prefix} {value}"),
1989 Expr::TypedString(ts) => ts.fmt(f),
1990 Expr::Function(fun) => fun.fmt(f),
1991 Expr::Case {
1992 case_token: _,
1993 end_token: _,
1994 operand,
1995 conditions,
1996 else_result,
1997 } => {
1998 f.write_str("CASE")?;
1999 if let Some(operand) = operand {
2000 f.write_str(" ")?;
2001 operand.fmt(f)?;
2002 }
2003 for when in conditions {
2004 SpaceOrNewline.fmt(f)?;
2005 Indent(when).fmt(f)?;
2006 }
2007 if let Some(else_result) = else_result {
2008 SpaceOrNewline.fmt(f)?;
2009 Indent("ELSE").fmt(f)?;
2010 SpaceOrNewline.fmt(f)?;
2011 Indent(Indent(else_result)).fmt(f)?;
2012 }
2013 SpaceOrNewline.fmt(f)?;
2014 f.write_str("END")
2015 }
2016 Expr::Exists { subquery, negated } => write!(
2017 f,
2018 "{}EXISTS ({})",
2019 if *negated { "NOT " } else { "" },
2020 subquery
2021 ),
2022 Expr::Subquery(s) => write!(f, "({s})"),
2023 Expr::GroupingSets(sets) => {
2024 write!(f, "GROUPING SETS (")?;
2025 let mut sep = "";
2026 for set in sets {
2027 write!(f, "{sep}")?;
2028 sep = ", ";
2029 write!(f, "({})", display_comma_separated(set))?;
2030 }
2031 write!(f, ")")
2032 }
2033 Expr::Cube(sets) => {
2034 write!(f, "CUBE (")?;
2035 let mut sep = "";
2036 for set in sets {
2037 write!(f, "{sep}")?;
2038 sep = ", ";
2039 if set.len() == 1 {
2040 write!(f, "{}", set[0])?;
2041 } else {
2042 write!(f, "({})", display_comma_separated(set))?;
2043 }
2044 }
2045 write!(f, ")")
2046 }
2047 Expr::Rollup(sets) => {
2048 write!(f, "ROLLUP (")?;
2049 let mut sep = "";
2050 for set in sets {
2051 write!(f, "{sep}")?;
2052 sep = ", ";
2053 if set.len() == 1 {
2054 write!(f, "{}", set[0])?;
2055 } else {
2056 write!(f, "({})", display_comma_separated(set))?;
2057 }
2058 }
2059 write!(f, ")")
2060 }
2061 Expr::Substring {
2062 expr,
2063 substring_from,
2064 substring_for,
2065 special,
2066 shorthand,
2067 } => {
2068 f.write_str("SUBSTR")?;
2069 if !*shorthand {
2070 f.write_str("ING")?;
2071 }
2072 write!(f, "({expr}")?;
2073 if let Some(from_part) = substring_from {
2074 if *special {
2075 write!(f, ", {from_part}")?;
2076 } else {
2077 write!(f, " FROM {from_part}")?;
2078 }
2079 }
2080 if let Some(for_part) = substring_for {
2081 if *special {
2082 write!(f, ", {for_part}")?;
2083 } else {
2084 write!(f, " FOR {for_part}")?;
2085 }
2086 }
2087
2088 write!(f, ")")
2089 }
2090 Expr::Overlay {
2091 expr,
2092 overlay_what,
2093 overlay_from,
2094 overlay_for,
2095 } => {
2096 write!(
2097 f,
2098 "OVERLAY({expr} PLACING {overlay_what} FROM {overlay_from}"
2099 )?;
2100 if let Some(for_part) = overlay_for {
2101 write!(f, " FOR {for_part}")?;
2102 }
2103
2104 write!(f, ")")
2105 }
2106 Expr::IsDistinctFrom(a, b) => write!(f, "{a} IS DISTINCT FROM {b}"),
2107 Expr::IsNotDistinctFrom(a, b) => write!(f, "{a} IS NOT DISTINCT FROM {b}"),
2108 Expr::Trim {
2109 expr,
2110 trim_where,
2111 trim_what,
2112 trim_characters,
2113 } => {
2114 write!(f, "TRIM(")?;
2115 if let Some(ident) = trim_where {
2116 write!(f, "{ident} ")?;
2117 }
2118 if let Some(trim_char) = trim_what {
2119 write!(f, "{trim_char} FROM {expr}")?;
2120 } else {
2121 write!(f, "{expr}")?;
2122 }
2123 if let Some(characters) = trim_characters {
2124 write!(f, ", {}", display_comma_separated(characters))?;
2125 }
2126
2127 write!(f, ")")
2128 }
2129 Expr::Tuple(exprs) => {
2130 write!(f, "({})", display_comma_separated(exprs))
2131 }
2132 Expr::Struct { values, fields } => {
2133 if !fields.is_empty() {
2134 write!(
2135 f,
2136 "STRUCT<{}>({})",
2137 display_comma_separated(fields),
2138 display_comma_separated(values)
2139 )
2140 } else {
2141 write!(f, "STRUCT({})", display_comma_separated(values))
2142 }
2143 }
2144 Expr::Named { expr, name } => {
2145 write!(f, "{expr} AS {name}")
2146 }
2147 Expr::Dictionary(fields) => {
2148 write!(f, "{{{}}}", display_comma_separated(fields))
2149 }
2150 Expr::Map(map) => {
2151 write!(f, "{map}")
2152 }
2153 Expr::Array(set) => {
2154 write!(f, "{set}")
2155 }
2156 Expr::JsonAccess { value, path } => {
2157 write!(f, "{value}{path}")
2158 }
2159 Expr::AtTimeZone {
2160 timestamp,
2161 time_zone,
2162 } => {
2163 write!(f, "{timestamp} AT TIME ZONE {time_zone}")
2164 }
2165 Expr::Interval(interval) => {
2166 write!(f, "{interval}")
2167 }
2168 Expr::MatchAgainst {
2169 columns,
2170 match_value: match_expr,
2171 opt_search_modifier,
2172 } => {
2173 write!(f, "MATCH ({}) AGAINST ", display_comma_separated(columns),)?;
2174
2175 if let Some(search_modifier) = opt_search_modifier {
2176 write!(f, "({match_expr} {search_modifier})")?;
2177 } else {
2178 write!(f, "({match_expr})")?;
2179 }
2180
2181 Ok(())
2182 }
2183 Expr::OuterJoin(expr) => {
2184 write!(f, "{expr} (+)")
2185 }
2186 Expr::Prior(expr) => write!(f, "PRIOR {expr}"),
2187 Expr::Lambda(lambda) => write!(f, "{lambda}"),
2188 Expr::MemberOf(member_of) => write!(f, "{member_of}"),
2189 }
2190 }
2191}
2192
2193#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2202#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2203#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2204pub enum WindowType {
2205 WindowSpec(WindowSpec),
2207 NamedWindow(Ident),
2209}
2210
2211impl Display for WindowType {
2212 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2213 match self {
2214 WindowType::WindowSpec(spec) => {
2215 f.write_str("(")?;
2216 NewLine.fmt(f)?;
2217 Indent(spec).fmt(f)?;
2218 NewLine.fmt(f)?;
2219 f.write_str(")")
2220 }
2221 WindowType::NamedWindow(name) => name.fmt(f),
2222 }
2223 }
2224}
2225
2226#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2228#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2229#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2230pub struct WindowSpec {
2231 pub window_name: Option<Ident>,
2239 pub partition_by: Vec<Expr>,
2241 pub order_by: Vec<OrderByExpr>,
2243 pub window_frame: Option<WindowFrame>,
2245}
2246
2247impl fmt::Display for WindowSpec {
2248 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2249 let mut is_first = true;
2250 if let Some(window_name) = &self.window_name {
2251 if !is_first {
2252 SpaceOrNewline.fmt(f)?;
2253 }
2254 is_first = false;
2255 write!(f, "{window_name}")?;
2256 }
2257 if !self.partition_by.is_empty() {
2258 if !is_first {
2259 SpaceOrNewline.fmt(f)?;
2260 }
2261 is_first = false;
2262 write!(
2263 f,
2264 "PARTITION BY {}",
2265 display_comma_separated(&self.partition_by)
2266 )?;
2267 }
2268 if !self.order_by.is_empty() {
2269 if !is_first {
2270 SpaceOrNewline.fmt(f)?;
2271 }
2272 is_first = false;
2273 write!(f, "ORDER BY {}", display_comma_separated(&self.order_by))?;
2274 }
2275 if let Some(window_frame) = &self.window_frame {
2276 if !is_first {
2277 SpaceOrNewline.fmt(f)?;
2278 }
2279 if let Some(end_bound) = &window_frame.end_bound {
2280 write!(
2281 f,
2282 "{} BETWEEN {} AND {}",
2283 window_frame.units, window_frame.start_bound, end_bound
2284 )?;
2285 } else {
2286 write!(f, "{} {}", window_frame.units, window_frame.start_bound)?;
2287 }
2288 }
2289 Ok(())
2290 }
2291}
2292
2293#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2299#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2300#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2301pub struct WindowFrame {
2302 pub units: WindowFrameUnits,
2304 pub start_bound: WindowFrameBound,
2306 pub end_bound: Option<WindowFrameBound>,
2310 }
2312
2313impl Default for WindowFrame {
2314 fn default() -> Self {
2318 Self {
2319 units: WindowFrameUnits::Range,
2320 start_bound: WindowFrameBound::Preceding(None),
2321 end_bound: None,
2322 }
2323 }
2324}
2325
2326#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2327#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2328#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2329pub enum WindowFrameUnits {
2331 Rows,
2333 Range,
2335 Groups,
2337}
2338
2339impl fmt::Display for WindowFrameUnits {
2340 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2341 f.write_str(match self {
2342 WindowFrameUnits::Rows => "ROWS",
2343 WindowFrameUnits::Range => "RANGE",
2344 WindowFrameUnits::Groups => "GROUPS",
2345 })
2346 }
2347}
2348
2349#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2353#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2354#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2355pub enum NullTreatment {
2357 IgnoreNulls,
2359 RespectNulls,
2361}
2362
2363impl fmt::Display for NullTreatment {
2364 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2365 f.write_str(match self {
2366 NullTreatment::IgnoreNulls => "IGNORE NULLS",
2367 NullTreatment::RespectNulls => "RESPECT NULLS",
2368 })
2369 }
2370}
2371
2372#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2374#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2375#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2376pub enum WindowFrameBound {
2377 CurrentRow,
2379 Preceding(Option<Box<Expr>>),
2381 Following(Option<Box<Expr>>),
2383}
2384
2385impl fmt::Display for WindowFrameBound {
2386 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2387 match self {
2388 WindowFrameBound::CurrentRow => f.write_str("CURRENT ROW"),
2389 WindowFrameBound::Preceding(None) => f.write_str("UNBOUNDED PRECEDING"),
2390 WindowFrameBound::Following(None) => f.write_str("UNBOUNDED FOLLOWING"),
2391 WindowFrameBound::Preceding(Some(n)) => write!(f, "{n} PRECEDING"),
2392 WindowFrameBound::Following(Some(n)) => write!(f, "{n} FOLLOWING"),
2393 }
2394 }
2395}
2396
2397#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2398#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2399#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2400pub enum AddDropSync {
2402 ADD,
2404 DROP,
2406 SYNC,
2408}
2409
2410impl fmt::Display for AddDropSync {
2411 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2412 match self {
2413 AddDropSync::SYNC => f.write_str("SYNC PARTITIONS"),
2414 AddDropSync::DROP => f.write_str("DROP PARTITIONS"),
2415 AddDropSync::ADD => f.write_str("ADD PARTITIONS"),
2416 }
2417 }
2418}
2419
2420#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2421#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2422#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2423pub enum ShowCreateObject {
2425 Event,
2427 Function,
2429 Procedure,
2431 Table,
2433 Trigger,
2435 View,
2437}
2438
2439impl fmt::Display for ShowCreateObject {
2440 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2441 match self {
2442 ShowCreateObject::Event => f.write_str("EVENT"),
2443 ShowCreateObject::Function => f.write_str("FUNCTION"),
2444 ShowCreateObject::Procedure => f.write_str("PROCEDURE"),
2445 ShowCreateObject::Table => f.write_str("TABLE"),
2446 ShowCreateObject::Trigger => f.write_str("TRIGGER"),
2447 ShowCreateObject::View => f.write_str("VIEW"),
2448 }
2449 }
2450}
2451
2452#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2453#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2454#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2455pub enum CommentObject {
2457 Collation,
2459 Column,
2461 Database,
2463 Domain,
2465 Extension,
2467 Function,
2469 Index,
2471 MaterializedView,
2473 Procedure,
2475 Role,
2477 Schema,
2479 Sequence,
2481 Table,
2483 Type,
2485 User,
2487 View,
2489}
2490
2491impl fmt::Display for CommentObject {
2492 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2493 match self {
2494 CommentObject::Collation => f.write_str("COLLATION"),
2495 CommentObject::Column => f.write_str("COLUMN"),
2496 CommentObject::Database => f.write_str("DATABASE"),
2497 CommentObject::Domain => f.write_str("DOMAIN"),
2498 CommentObject::Extension => f.write_str("EXTENSION"),
2499 CommentObject::Function => f.write_str("FUNCTION"),
2500 CommentObject::Index => f.write_str("INDEX"),
2501 CommentObject::MaterializedView => f.write_str("MATERIALIZED VIEW"),
2502 CommentObject::Procedure => f.write_str("PROCEDURE"),
2503 CommentObject::Role => f.write_str("ROLE"),
2504 CommentObject::Schema => f.write_str("SCHEMA"),
2505 CommentObject::Sequence => f.write_str("SEQUENCE"),
2506 CommentObject::Table => f.write_str("TABLE"),
2507 CommentObject::Type => f.write_str("TYPE"),
2508 CommentObject::User => f.write_str("USER"),
2509 CommentObject::View => f.write_str("VIEW"),
2510 }
2511 }
2512}
2513
2514#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2515#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2516#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2517pub enum Password {
2519 Password(Expr),
2521 NullPassword,
2523}
2524
2525#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2542#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2543#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2544pub struct CaseStatement {
2545 pub case_token: AttachedToken,
2547 pub match_expr: Option<Expr>,
2549 pub when_blocks: Vec<ConditionalStatementBlock>,
2551 pub else_block: Option<ConditionalStatementBlock>,
2553 pub end_case_token: AttachedToken,
2555}
2556
2557impl fmt::Display for CaseStatement {
2558 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2559 let CaseStatement {
2560 case_token: _,
2561 match_expr,
2562 when_blocks,
2563 else_block,
2564 end_case_token: AttachedToken(end),
2565 } = self;
2566
2567 write!(f, "CASE")?;
2568
2569 if let Some(expr) = match_expr {
2570 write!(f, " {expr}")?;
2571 }
2572
2573 if !when_blocks.is_empty() {
2574 write!(f, " {}", display_separated(when_blocks, " "))?;
2575 }
2576
2577 if let Some(else_block) = else_block {
2578 write!(f, " {else_block}")?;
2579 }
2580
2581 write!(f, " END")?;
2582
2583 if let Token::Word(w) = &end.token {
2584 if w.keyword == Keyword::CASE {
2585 write!(f, " CASE")?;
2586 }
2587 }
2588
2589 Ok(())
2590 }
2591}
2592
2593#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2615#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2616#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2617pub struct IfStatement {
2618 pub if_block: ConditionalStatementBlock,
2620 pub elseif_blocks: Vec<ConditionalStatementBlock>,
2622 pub else_block: Option<ConditionalStatementBlock>,
2624 pub end_token: Option<AttachedToken>,
2626}
2627
2628impl fmt::Display for IfStatement {
2629 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2630 let IfStatement {
2631 if_block,
2632 elseif_blocks,
2633 else_block,
2634 end_token,
2635 } = self;
2636
2637 write!(f, "{if_block}")?;
2638
2639 for elseif_block in elseif_blocks {
2640 write!(f, " {elseif_block}")?;
2641 }
2642
2643 if let Some(else_block) = else_block {
2644 write!(f, " {else_block}")?;
2645 }
2646
2647 if let Some(AttachedToken(end_token)) = end_token {
2648 write!(f, " END {end_token}")?;
2649 }
2650
2651 Ok(())
2652 }
2653}
2654
2655#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2667#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2668#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2669pub struct WhileStatement {
2670 pub while_block: ConditionalStatementBlock,
2672}
2673
2674impl fmt::Display for WhileStatement {
2675 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2676 let WhileStatement { while_block } = self;
2677 write!(f, "{while_block}")?;
2678 Ok(())
2679 }
2680}
2681
2682#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2707#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2708#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2709pub struct ConditionalStatementBlock {
2710 pub start_token: AttachedToken,
2712 pub condition: Option<Expr>,
2714 pub then_token: Option<AttachedToken>,
2716 pub conditional_statements: ConditionalStatements,
2718}
2719
2720impl ConditionalStatementBlock {
2721 pub fn statements(&self) -> &Vec<Statement> {
2723 self.conditional_statements.statements()
2724 }
2725}
2726
2727impl fmt::Display for ConditionalStatementBlock {
2728 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2729 let ConditionalStatementBlock {
2730 start_token: AttachedToken(start_token),
2731 condition,
2732 then_token,
2733 conditional_statements,
2734 } = self;
2735
2736 write!(f, "{start_token}")?;
2737
2738 if let Some(condition) = condition {
2739 write!(f, " {condition}")?;
2740 }
2741
2742 if then_token.is_some() {
2743 write!(f, " THEN")?;
2744 }
2745
2746 if !conditional_statements.statements().is_empty() {
2747 write!(f, " {conditional_statements}")?;
2748 }
2749
2750 Ok(())
2751 }
2752}
2753
2754#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2756#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2757#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2758pub enum ConditionalStatements {
2760 Sequence {
2762 statements: Vec<Statement>,
2764 },
2765 BeginEnd(BeginEndStatements),
2767}
2768
2769impl ConditionalStatements {
2770 pub fn statements(&self) -> &Vec<Statement> {
2772 match self {
2773 ConditionalStatements::Sequence { statements } => statements,
2774 ConditionalStatements::BeginEnd(bes) => &bes.statements,
2775 }
2776 }
2777}
2778
2779impl fmt::Display for ConditionalStatements {
2780 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2781 match self {
2782 ConditionalStatements::Sequence { statements } => {
2783 if !statements.is_empty() {
2784 format_statement_list(f, statements)?;
2785 }
2786 Ok(())
2787 }
2788 ConditionalStatements::BeginEnd(bes) => write!(f, "{bes}"),
2789 }
2790 }
2791}
2792
2793#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2802#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2803#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2804pub struct BeginEndStatements {
2805 pub begin_token: AttachedToken,
2807 pub statements: Vec<Statement>,
2809 pub end_token: AttachedToken,
2811}
2812
2813impl fmt::Display for BeginEndStatements {
2814 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2815 let BeginEndStatements {
2816 begin_token: AttachedToken(begin_token),
2817 statements,
2818 end_token: AttachedToken(end_token),
2819 } = self;
2820
2821 if begin_token.token != Token::EOF {
2822 write!(f, "{begin_token} ")?;
2823 }
2824 if !statements.is_empty() {
2825 format_statement_list(f, statements)?;
2826 }
2827 if end_token.token != Token::EOF {
2828 write!(f, " {end_token}")?;
2829 }
2830 Ok(())
2831 }
2832}
2833
2834#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2846#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2847#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2848pub struct RaiseStatement {
2849 pub value: Option<RaiseStatementValue>,
2851}
2852
2853impl fmt::Display for RaiseStatement {
2854 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2855 let RaiseStatement { value } = self;
2856
2857 write!(f, "RAISE")?;
2858 if let Some(value) = value {
2859 write!(f, " {value}")?;
2860 }
2861
2862 Ok(())
2863 }
2864}
2865
2866#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2868#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2869#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2870pub enum RaiseStatementValue {
2871 UsingMessage(Expr),
2873 Expr(Expr),
2875}
2876
2877impl fmt::Display for RaiseStatementValue {
2878 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2879 match self {
2880 RaiseStatementValue::Expr(expr) => write!(f, "{expr}"),
2881 RaiseStatementValue::UsingMessage(expr) => write!(f, "USING MESSAGE = {expr}"),
2882 }
2883 }
2884}
2885
2886#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2894#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2895#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2896pub struct ThrowStatement {
2897 pub error_number: Option<Box<Expr>>,
2899 pub message: Option<Box<Expr>>,
2901 pub state: Option<Box<Expr>>,
2903}
2904
2905impl fmt::Display for ThrowStatement {
2906 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2907 let ThrowStatement {
2908 error_number,
2909 message,
2910 state,
2911 } = self;
2912
2913 write!(f, "THROW")?;
2914 if let (Some(error_number), Some(message), Some(state)) = (error_number, message, state) {
2915 write!(f, " {error_number}, {message}, {state}")?;
2916 }
2917 Ok(())
2918 }
2919}
2920
2921#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2929#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2930#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2931pub enum DeclareAssignment {
2932 Expr(Box<Expr>),
2934
2935 Default(Box<Expr>),
2937
2938 DuckAssignment(Box<Expr>),
2945
2946 For(Box<Expr>),
2953
2954 MsSqlAssignment(Box<Expr>),
2961}
2962
2963impl fmt::Display for DeclareAssignment {
2964 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2965 match self {
2966 DeclareAssignment::Expr(expr) => {
2967 write!(f, "{expr}")
2968 }
2969 DeclareAssignment::Default(expr) => {
2970 write!(f, "DEFAULT {expr}")
2971 }
2972 DeclareAssignment::DuckAssignment(expr) => {
2973 write!(f, ":= {expr}")
2974 }
2975 DeclareAssignment::MsSqlAssignment(expr) => {
2976 write!(f, "= {expr}")
2977 }
2978 DeclareAssignment::For(expr) => {
2979 write!(f, "FOR {expr}")
2980 }
2981 }
2982 }
2983}
2984
2985#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2987#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2988#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2989pub enum DeclareType {
2990 Cursor,
2996
2997 ResultSet,
3005
3006 Exception,
3014}
3015
3016impl fmt::Display for DeclareType {
3017 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3018 match self {
3019 DeclareType::Cursor => {
3020 write!(f, "CURSOR")
3021 }
3022 DeclareType::ResultSet => {
3023 write!(f, "RESULTSET")
3024 }
3025 DeclareType::Exception => {
3026 write!(f, "EXCEPTION")
3027 }
3028 }
3029 }
3030}
3031
3032#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3045#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3046#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3047pub struct Declare {
3048 pub names: Vec<Ident>,
3051 pub data_type: Option<DataType>,
3054 pub assignment: Option<DeclareAssignment>,
3056 pub declare_type: Option<DeclareType>,
3058 pub binary: Option<bool>,
3060 pub sensitive: Option<bool>,
3064 pub scroll: Option<bool>,
3068 pub hold: Option<bool>,
3072 pub for_query: Option<Box<Query>>,
3074}
3075
3076impl fmt::Display for Declare {
3077 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3078 let Declare {
3079 names,
3080 data_type,
3081 assignment,
3082 declare_type,
3083 binary,
3084 sensitive,
3085 scroll,
3086 hold,
3087 for_query,
3088 } = self;
3089 write!(f, "{}", display_comma_separated(names))?;
3090
3091 if let Some(true) = binary {
3092 write!(f, " BINARY")?;
3093 }
3094
3095 if let Some(sensitive) = sensitive {
3096 if *sensitive {
3097 write!(f, " INSENSITIVE")?;
3098 } else {
3099 write!(f, " ASENSITIVE")?;
3100 }
3101 }
3102
3103 if let Some(scroll) = scroll {
3104 if *scroll {
3105 write!(f, " SCROLL")?;
3106 } else {
3107 write!(f, " NO SCROLL")?;
3108 }
3109 }
3110
3111 if let Some(declare_type) = declare_type {
3112 write!(f, " {declare_type}")?;
3113 }
3114
3115 if let Some(hold) = hold {
3116 if *hold {
3117 write!(f, " WITH HOLD")?;
3118 } else {
3119 write!(f, " WITHOUT HOLD")?;
3120 }
3121 }
3122
3123 if let Some(query) = for_query {
3124 write!(f, " FOR {query}")?;
3125 }
3126
3127 if let Some(data_type) = data_type {
3128 write!(f, " {data_type}")?;
3129 }
3130
3131 if let Some(expr) = assignment {
3132 write!(f, " {expr}")?;
3133 }
3134 Ok(())
3135 }
3136}
3137
3138#[derive(Debug, Default, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3140#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3141#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3142pub enum CreateTableOptions {
3144 #[default]
3146 None,
3147 With(Vec<SqlOption>),
3149 Options(Vec<SqlOption>),
3151 Plain(Vec<SqlOption>),
3153 TableProperties(Vec<SqlOption>),
3155}
3156
3157impl fmt::Display for CreateTableOptions {
3158 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3159 match self {
3160 CreateTableOptions::With(with_options) => {
3161 write!(f, "WITH ({})", display_comma_separated(with_options))
3162 }
3163 CreateTableOptions::Options(options) => {
3164 write!(f, "OPTIONS({})", display_comma_separated(options))
3165 }
3166 CreateTableOptions::TableProperties(options) => {
3167 write!(f, "TBLPROPERTIES ({})", display_comma_separated(options))
3168 }
3169 CreateTableOptions::Plain(options) => {
3170 write!(f, "{}", display_separated(options, " "))
3171 }
3172 CreateTableOptions::None => Ok(()),
3173 }
3174 }
3175}
3176
3177#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3184#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3185#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3186pub enum FromTable {
3187 WithFromKeyword(Vec<TableWithJoins>),
3189 WithoutKeyword(Vec<TableWithJoins>),
3192}
3193impl Display for FromTable {
3194 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3195 match self {
3196 FromTable::WithFromKeyword(tables) => {
3197 write!(f, "FROM {}", display_comma_separated(tables))
3198 }
3199 FromTable::WithoutKeyword(tables) => {
3200 write!(f, "{}", display_comma_separated(tables))
3201 }
3202 }
3203 }
3204}
3205
3206#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3207#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3208#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3209pub enum Set {
3211 SingleAssignment {
3215 scope: Option<ContextModifier>,
3217 hivevar: bool,
3219 variable: ObjectName,
3221 values: Vec<Expr>,
3223 },
3224 ParenthesizedAssignments {
3228 variables: Vec<ObjectName>,
3230 values: Vec<Expr>,
3232 },
3233 MultipleAssignments {
3237 assignments: Vec<SetAssignment>,
3239 },
3240 SetSessionAuthorization(SetSessionAuthorizationParam),
3249 SetSessionParam(SetSessionParamKind),
3253 SetRole {
3264 context_modifier: Option<ContextModifier>,
3266 role_name: Option<Ident>,
3268 },
3269 SetTimeZone {
3279 local: bool,
3281 value: Expr,
3283 },
3284 SetNames {
3288 charset_name: Ident,
3290 collation_name: Option<String>,
3292 },
3293 SetNamesDefault {},
3299 SetTransaction {
3303 modes: Vec<TransactionMode>,
3305 snapshot: Option<ValueWithSpan>,
3307 session: bool,
3309 },
3310}
3311
3312impl Display for Set {
3313 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3314 match self {
3315 Self::ParenthesizedAssignments { variables, values } => write!(
3316 f,
3317 "SET ({}) = ({})",
3318 display_comma_separated(variables),
3319 display_comma_separated(values)
3320 ),
3321 Self::MultipleAssignments { assignments } => {
3322 write!(f, "SET {}", display_comma_separated(assignments))
3323 }
3324 Self::SetRole {
3325 context_modifier,
3326 role_name,
3327 } => {
3328 let role_name = role_name.clone().unwrap_or_else(|| Ident::new("NONE"));
3329 write!(
3330 f,
3331 "SET {modifier}ROLE {role_name}",
3332 modifier = context_modifier.map(|m| format!("{m}")).unwrap_or_default()
3333 )
3334 }
3335 Self::SetSessionAuthorization(kind) => write!(f, "SET SESSION AUTHORIZATION {kind}"),
3336 Self::SetSessionParam(kind) => write!(f, "SET {kind}"),
3337 Self::SetTransaction {
3338 modes,
3339 snapshot,
3340 session,
3341 } => {
3342 if *session {
3343 write!(f, "SET SESSION CHARACTERISTICS AS TRANSACTION")?;
3344 } else {
3345 write!(f, "SET TRANSACTION")?;
3346 }
3347 if !modes.is_empty() {
3348 write!(f, " {}", display_comma_separated(modes))?;
3349 }
3350 if let Some(snapshot_id) = snapshot {
3351 write!(f, " SNAPSHOT {snapshot_id}")?;
3352 }
3353 Ok(())
3354 }
3355 Self::SetTimeZone { local, value } => {
3356 f.write_str("SET ")?;
3357 if *local {
3358 f.write_str("LOCAL ")?;
3359 }
3360 write!(f, "TIME ZONE {value}")
3361 }
3362 Self::SetNames {
3363 charset_name,
3364 collation_name,
3365 } => {
3366 write!(f, "SET NAMES {charset_name}")?;
3367
3368 if let Some(collation) = collation_name {
3369 f.write_str(" COLLATE ")?;
3370 f.write_str(collation)?;
3371 };
3372
3373 Ok(())
3374 }
3375 Self::SetNamesDefault {} => {
3376 f.write_str("SET NAMES DEFAULT")?;
3377
3378 Ok(())
3379 }
3380 Set::SingleAssignment {
3381 scope,
3382 hivevar,
3383 variable,
3384 values,
3385 } => {
3386 write!(
3387 f,
3388 "SET {}{}{} = {}",
3389 scope.map(|s| format!("{s}")).unwrap_or_default(),
3390 if *hivevar { "HIVEVAR:" } else { "" },
3391 variable,
3392 display_comma_separated(values)
3393 )
3394 }
3395 }
3396 }
3397}
3398
3399#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3405#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3406#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3407pub struct ExceptionWhen {
3408 pub idents: Vec<Ident>,
3410 pub statements: Vec<Statement>,
3412}
3413
3414impl Display for ExceptionWhen {
3415 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3416 write!(
3417 f,
3418 "WHEN {idents} THEN",
3419 idents = display_separated(&self.idents, " OR ")
3420 )?;
3421
3422 if !self.statements.is_empty() {
3423 write!(f, " ")?;
3424 format_statement_list(f, &self.statements)?;
3425 }
3426
3427 Ok(())
3428 }
3429}
3430
3431#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3438#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3439#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3440pub struct Analyze {
3441 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3442 pub table_name: Option<ObjectName>,
3444 pub partitions: Option<Vec<Expr>>,
3446 pub for_columns: bool,
3448 pub columns: Vec<Ident>,
3450 pub cache_metadata: bool,
3452 pub noscan: bool,
3454 pub compute_statistics: bool,
3456 pub has_table_keyword: bool,
3458}
3459
3460impl fmt::Display for Analyze {
3461 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3462 write!(f, "ANALYZE")?;
3463 if let Some(ref table_name) = self.table_name {
3464 if self.has_table_keyword {
3465 write!(f, " TABLE")?;
3466 }
3467 write!(f, " {table_name}")?;
3468 }
3469 if !self.for_columns && !self.columns.is_empty() {
3470 write!(f, " ({})", display_comma_separated(&self.columns))?;
3471 }
3472 if let Some(ref parts) = self.partitions {
3473 if !parts.is_empty() {
3474 write!(f, " PARTITION ({})", display_comma_separated(parts))?;
3475 }
3476 }
3477 if self.compute_statistics {
3478 write!(f, " COMPUTE STATISTICS")?;
3479 }
3480 if self.noscan {
3481 write!(f, " NOSCAN")?;
3482 }
3483 if self.cache_metadata {
3484 write!(f, " CACHE METADATA")?;
3485 }
3486 if self.for_columns {
3487 write!(f, " FOR COLUMNS")?;
3488 if !self.columns.is_empty() {
3489 write!(f, " {}", display_comma_separated(&self.columns))?;
3490 }
3491 }
3492 Ok(())
3493 }
3494}
3495
3496#[allow(clippy::large_enum_variant)]
3498#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3499#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3500#[cfg_attr(
3501 feature = "visitor",
3502 derive(Visit, VisitMut),
3503 visit(with = "visit_statement")
3504)]
3505pub enum Statement {
3506 Analyze(Analyze),
3511 Set(Set),
3513 Truncate(Truncate),
3518 Msck(Msck),
3523 Query(Box<Query>),
3527 Insert(Insert),
3531 Install {
3535 extension_name: Ident,
3537 },
3538 Load {
3542 extension_name: Ident,
3544 },
3545 Directory {
3548 overwrite: bool,
3550 local: bool,
3552 path: String,
3554 file_format: Option<FileFormat>,
3556 source: Box<Query>,
3558 },
3559 Case(CaseStatement),
3561 If(IfStatement),
3563 While(WhileStatement),
3565 Raise(RaiseStatement),
3567 Call(Function),
3571 Copy {
3575 source: CopySource,
3577 to: bool,
3579 target: CopyTarget,
3581 options: Vec<CopyOption>,
3583 legacy_options: Vec<CopyLegacyOption>,
3585 values: Vec<Option<String>>,
3587 },
3588 CopyIntoSnowflake {
3600 kind: CopyIntoSnowflakeKind,
3602 into: ObjectName,
3604 into_columns: Option<Vec<Ident>>,
3606 from_obj: Option<ObjectName>,
3608 from_obj_alias: Option<Ident>,
3610 stage_params: StageParamsObject,
3612 from_transformations: Option<Vec<StageLoadSelectItemKind>>,
3614 from_query: Option<Box<Query>>,
3616 files: Option<Vec<String>>,
3618 pattern: Option<String>,
3620 file_format: KeyValueOptions,
3622 copy_options: KeyValueOptions,
3624 validation_mode: Option<String>,
3626 partition: Option<Box<Expr>>,
3628 },
3629 Open(OpenStatement),
3634 Close {
3639 cursor: CloseCursor,
3641 },
3642 Update(Update),
3646 Delete(Delete),
3650 CreateView(CreateView),
3654 CreateTable(CreateTable),
3658 CreateVirtualTable {
3663 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3664 name: ObjectName,
3666 if_not_exists: bool,
3668 module_name: Ident,
3670 module_args: Vec<Ident>,
3672 },
3673 CreateIndex(CreateIndex),
3677 CreateRole(CreateRole),
3682 CreateSecret {
3687 or_replace: bool,
3689 temporary: Option<bool>,
3691 if_not_exists: bool,
3693 name: Option<Ident>,
3695 storage_specifier: Option<Ident>,
3697 secret_type: Ident,
3699 options: Vec<SecretOption>,
3701 },
3702 CreateServer(CreateServerStatement),
3704 CreateForeignDataWrapper(CreateForeignDataWrapper),
3709 CreateForeignTable(CreateForeignTable),
3714 CreatePolicy(CreatePolicy),
3719 CreateConnector(CreateConnector),
3724 CreateOperator(CreateOperator),
3729 CreateOperatorFamily(CreateOperatorFamily),
3734 CreateOperatorClass(CreateOperatorClass),
3739 CreateAggregate(CreateAggregate),
3744 AlterTable(AlterTable),
3748 AlterSchema(AlterSchema),
3753 AlterIndex {
3757 name: ObjectName,
3759 operation: AlterIndexOperation,
3761 },
3762 AlterView {
3766 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3768 name: ObjectName,
3769 columns: Vec<Ident>,
3771 query: Box<Query>,
3773 with_options: Vec<SqlOption>,
3775 },
3776 AlterFunction(AlterFunction),
3783 AlterType(AlterType),
3788 AlterCollation(AlterCollation),
3793 AlterOperator(AlterOperator),
3798 AlterOperatorFamily(AlterOperatorFamily),
3803 AlterOperatorClass(AlterOperatorClass),
3808 AlterRole {
3812 name: Ident,
3814 operation: AlterRoleOperation,
3816 },
3817 AlterPolicy(AlterPolicy),
3822 AlterConnector {
3831 name: Ident,
3833 properties: Option<Vec<SqlOption>>,
3835 url: Option<String>,
3837 owner: Option<ddl::AlterConnectorOwner>,
3839 },
3840 AlterSession {
3846 set: bool,
3848 session_params: KeyValueOptions,
3850 },
3851 AttachDatabase {
3856 schema_name: Ident,
3858 database_file_name: Expr,
3860 database: bool,
3862 },
3863 AttachDuckDBDatabase {
3869 if_not_exists: bool,
3871 database: bool,
3873 database_path: Ident,
3875 database_alias: Option<Ident>,
3877 attach_options: Vec<AttachDuckDBDatabaseOption>,
3879 },
3880 DetachDuckDBDatabase {
3886 if_exists: bool,
3888 database: bool,
3890 database_alias: Ident,
3892 },
3893 Drop {
3897 object_type: ObjectType,
3899 if_exists: bool,
3901 names: Vec<ObjectName>,
3903 cascade: bool,
3906 restrict: bool,
3909 purge: bool,
3912 temporary: bool,
3914 table: Option<ObjectName>,
3917 },
3918 DropFunction(DropFunction),
3922 DropDomain(DropDomain),
3930 DropProcedure {
3934 if_exists: bool,
3936 proc_desc: Vec<FunctionDesc>,
3938 drop_behavior: Option<DropBehavior>,
3940 },
3941 DropSecret {
3945 if_exists: bool,
3947 temporary: Option<bool>,
3949 name: Ident,
3951 storage_specifier: Option<Ident>,
3953 },
3954 DropPolicy(DropPolicy),
3959 DropConnector {
3964 if_exists: bool,
3966 name: Ident,
3968 },
3969 Declare {
3977 stmts: Vec<Declare>,
3979 },
3980 CreateExtension(CreateExtension),
3989 CreateCollation(CreateCollation),
3995 CreateTextSearchConfiguration(CreateTextSearchConfiguration),
4001 CreateTextSearchDictionary(CreateTextSearchDictionary),
4007 CreateTextSearchParser(CreateTextSearchParser),
4013 CreateTextSearchTemplate(CreateTextSearchTemplate),
4019 DropExtension(DropExtension),
4025 DropOperator(DropOperator),
4031 DropOperatorFamily(DropOperatorFamily),
4037 DropOperatorClass(DropOperatorClass),
4043 Fetch {
4051 name: Ident,
4053 direction: FetchDirection,
4055 position: FetchPosition,
4057 into: Option<ObjectName>,
4059 },
4060 Flush {
4067 object_type: FlushType,
4069 location: Option<FlushLocation>,
4071 channel: Option<String>,
4073 read_lock: bool,
4075 export: bool,
4077 tables: Vec<ObjectName>,
4079 },
4080 Discard {
4087 object_type: DiscardObject,
4089 },
4090 ShowFunctions {
4094 filter: Option<ShowStatementFilter>,
4096 },
4097 ShowVariable {
4103 variable: Vec<Ident>,
4105 },
4106 ShowStatus {
4112 filter: Option<ShowStatementFilter>,
4114 global: bool,
4116 session: bool,
4118 },
4119 ShowVariables {
4125 filter: Option<ShowStatementFilter>,
4127 global: bool,
4129 session: bool,
4131 },
4132 ShowCreate {
4138 obj_type: ShowCreateObject,
4140 obj_name: ObjectName,
4142 },
4143 ShowColumns {
4147 extended: bool,
4149 full: bool,
4151 show_options: ShowStatementOptions,
4153 },
4154 ShowCatalogs {
4158 terse: bool,
4160 history: bool,
4162 show_options: ShowStatementOptions,
4164 },
4165 ShowDatabases {
4169 terse: bool,
4171 history: bool,
4173 show_options: ShowStatementOptions,
4175 },
4176 ShowProcessList {
4182 full: bool,
4184 },
4185 ShowSchemas {
4189 terse: bool,
4191 history: bool,
4193 show_options: ShowStatementOptions,
4195 },
4196 ShowCharset(ShowCharset),
4203 ShowObjects(ShowObjects),
4209 ShowTables {
4213 terse: bool,
4215 history: bool,
4217 extended: bool,
4219 full: bool,
4221 external: bool,
4223 show_options: ShowStatementOptions,
4225 },
4226 ShowViews {
4230 terse: bool,
4232 materialized: bool,
4234 show_options: ShowStatementOptions,
4236 },
4237 ShowCollation {
4243 filter: Option<ShowStatementFilter>,
4245 },
4246 Use(Use),
4250 StartTransaction {
4260 modes: Vec<TransactionMode>,
4262 begin: bool,
4264 transaction: Option<BeginTransactionKind>,
4266 modifier: Option<TransactionModifier>,
4268 statements: Vec<Statement>,
4277 exception: Option<Vec<ExceptionWhen>>,
4291 has_end_keyword: bool,
4293 },
4294 Comment {
4300 object_type: CommentObject,
4302 object_name: ObjectName,
4304 comment: Option<String>,
4306 if_exists: bool,
4309 },
4310 Commit {
4320 chain: bool,
4322 end: bool,
4324 modifier: Option<TransactionModifier>,
4326 },
4327 Rollback {
4331 chain: bool,
4333 savepoint: Option<Ident>,
4335 },
4336 CreateSchema {
4340 schema_name: SchemaName,
4342 if_not_exists: bool,
4344 with: Option<Vec<SqlOption>>,
4352 options: Option<Vec<SqlOption>>,
4360 default_collate_spec: Option<Expr>,
4368 clone: Option<ObjectName>,
4376 },
4377 CreateDatabase {
4383 db_name: ObjectName,
4385 if_not_exists: bool,
4387 location: Option<String>,
4389 managed_location: Option<String>,
4391 or_replace: bool,
4393 transient: bool,
4395 clone: Option<ObjectName>,
4397 data_retention_time_in_days: Option<u64>,
4399 max_data_extension_time_in_days: Option<u64>,
4401 external_volume: Option<String>,
4403 catalog: Option<String>,
4405 replace_invalid_characters: Option<bool>,
4407 default_ddl_collation: Option<String>,
4409 storage_serialization_policy: Option<StorageSerializationPolicy>,
4411 comment: Option<String>,
4413 default_charset: Option<String>,
4415 default_collation: Option<String>,
4417 catalog_sync: Option<String>,
4419 catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
4421 catalog_sync_namespace_flatten_delimiter: Option<String>,
4423 with_tags: Option<Vec<Tag>>,
4425 with_contacts: Option<Vec<ContactEntry>>,
4427 },
4428 CreateFunction(CreateFunction),
4438 CreateTrigger(CreateTrigger),
4440 DropTrigger(DropTrigger),
4442 CreateProcedure {
4446 or_alter: bool,
4448 name: ObjectName,
4450 params: Option<Vec<ProcedureParam>>,
4452 language: Option<Ident>,
4454 body: ConditionalStatements,
4456 },
4457 CreateMacro {
4464 or_replace: bool,
4466 temporary: bool,
4468 name: ObjectName,
4470 args: Option<Vec<MacroArg>>,
4472 definition: MacroDefinition,
4474 },
4475 CreateStage {
4480 or_replace: bool,
4482 temporary: bool,
4484 if_not_exists: bool,
4486 name: ObjectName,
4488 stage_params: StageParamsObject,
4490 directory_table_params: KeyValueOptions,
4492 file_format: KeyValueOptions,
4494 copy_options: KeyValueOptions,
4496 comment: Option<String>,
4498 },
4499 Assert {
4503 condition: Expr,
4505 message: Option<Expr>,
4507 },
4508 Grant(Grant),
4512 Deny(DenyStatement),
4516 Revoke(Revoke),
4520 Deallocate {
4526 name: Ident,
4528 prepare: bool,
4530 },
4531 Execute {
4540 name: Option<ObjectName>,
4542 parameters: Vec<Expr>,
4544 has_parentheses: bool,
4546 immediate: bool,
4548 into: Vec<Ident>,
4550 using: Vec<ExprWithAlias>,
4552 output: bool,
4555 default: bool,
4558 },
4559 Prepare {
4565 name: Ident,
4567 data_types: Vec<DataType>,
4569 statement: Box<Statement>,
4571 },
4572 Kill {
4579 modifier: Option<KillType>,
4581 id: u64,
4584 },
4585 ExplainTable {
4590 describe_alias: DescribeAlias,
4592 hive_format: Option<HiveDescribeFormat>,
4594 has_table_keyword: bool,
4599 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4601 table_name: ObjectName,
4602 },
4603 Explain {
4607 describe_alias: DescribeAlias,
4609 analyze: bool,
4611 verbose: bool,
4613 query_plan: bool,
4618 estimate: bool,
4621 statement: Box<Statement>,
4623 format: Option<AnalyzeFormatKind>,
4625 options: Option<Vec<UtilityOption>>,
4627 },
4628 Savepoint {
4633 name: Ident,
4635 },
4636 ReleaseSavepoint {
4640 name: Ident,
4642 },
4643 Merge(Merge),
4652 Cache {
4660 table_flag: Option<ObjectName>,
4662 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4664 table_name: ObjectName,
4665 has_as: bool,
4667 options: Vec<SqlOption>,
4669 query: Option<Box<Query>>,
4671 },
4672 UNCache {
4676 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4678 table_name: ObjectName,
4679 if_exists: bool,
4681 },
4682 CreateSequence {
4687 temporary: bool,
4689 if_not_exists: bool,
4691 name: ObjectName,
4693 data_type: Option<DataType>,
4695 sequence_options: Vec<SequenceOptions>,
4697 owned_by: Option<ObjectName>,
4699 },
4700 CreateDomain(CreateDomain),
4702 CreateType {
4706 name: ObjectName,
4708 representation: Option<UserDefinedTypeRepresentation>,
4710 },
4711 Pragma {
4715 name: ObjectName,
4717 value: Option<ValueWithSpan>,
4719 is_eq: bool,
4721 },
4722 Lock(Lock),
4728 LockTables {
4733 tables: Vec<LockTable>,
4735 },
4736 UnlockTables,
4741 Unload {
4753 query: Option<Box<Query>>,
4755 query_text: Option<String>,
4757 to: Ident,
4759 auth: Option<IamRoleKind>,
4761 with: Vec<SqlOption>,
4763 options: Vec<CopyLegacyOption>,
4765 },
4766 OptimizeTable {
4778 name: ObjectName,
4780 has_table_keyword: bool,
4782 on_cluster: Option<Ident>,
4785 partition: Option<Partition>,
4788 include_final: bool,
4791 deduplicate: Option<Deduplicate>,
4794 predicate: Option<Expr>,
4797 zorder: Option<Vec<Expr>>,
4800 },
4801 LISTEN {
4808 channel: Ident,
4810 },
4811 UNLISTEN {
4818 channel: Ident,
4820 },
4821 NOTIFY {
4828 channel: Ident,
4830 payload: Option<String>,
4832 },
4833 LoadData {
4842 local: bool,
4844 inpath: String,
4846 overwrite: bool,
4848 table_name: ObjectName,
4850 partitioned: Option<Vec<Expr>>,
4852 table_format: Option<HiveLoadDataFormat>,
4854 },
4855 RenameTable(Vec<RenameTable>),
4862 List(FileStagingCommand),
4865 Remove(FileStagingCommand),
4868 RaisError {
4875 message: Box<Expr>,
4877 severity: Box<Expr>,
4879 state: Box<Expr>,
4881 arguments: Vec<Expr>,
4883 options: Vec<RaisErrorOption>,
4885 },
4886 Throw(ThrowStatement),
4888 Print(PrintStatement),
4894 WaitFor(WaitForStatement),
4898 Return(ReturnStatement),
4904 ExportData(ExportData),
4913 CreateUser(CreateUser),
4918 AlterUser(AlterUser),
4923 Vacuum(VacuumStatement),
4930 Reset(ResetStatement),
4938}
4939
4940impl From<Analyze> for Statement {
4941 fn from(analyze: Analyze) -> Self {
4942 Statement::Analyze(analyze)
4943 }
4944}
4945
4946impl From<ddl::Truncate> for Statement {
4947 fn from(truncate: ddl::Truncate) -> Self {
4948 Statement::Truncate(truncate)
4949 }
4950}
4951
4952impl From<Lock> for Statement {
4953 fn from(lock: Lock) -> Self {
4954 Statement::Lock(lock)
4955 }
4956}
4957
4958impl From<ddl::Msck> for Statement {
4959 fn from(msck: ddl::Msck) -> Self {
4960 Statement::Msck(msck)
4961 }
4962}
4963
4964#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4970#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4971#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4972pub enum CurrentGrantsKind {
4973 CopyCurrentGrants,
4975 RevokeCurrentGrants,
4977}
4978
4979impl fmt::Display for CurrentGrantsKind {
4980 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4981 match self {
4982 CurrentGrantsKind::CopyCurrentGrants => write!(f, "COPY CURRENT GRANTS"),
4983 CurrentGrantsKind::RevokeCurrentGrants => write!(f, "REVOKE CURRENT GRANTS"),
4984 }
4985 }
4986}
4987
4988#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4989#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4990#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4991pub enum RaisErrorOption {
4994 Log,
4996 NoWait,
4998 SetError,
5000}
5001
5002impl fmt::Display for RaisErrorOption {
5003 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5004 match self {
5005 RaisErrorOption::Log => write!(f, "LOG"),
5006 RaisErrorOption::NoWait => write!(f, "NOWAIT"),
5007 RaisErrorOption::SetError => write!(f, "SETERROR"),
5008 }
5009 }
5010}
5011
5012impl fmt::Display for Statement {
5013 #[allow(clippy::cognitive_complexity)]
5038 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5039 match self {
5040 Statement::Flush {
5041 object_type,
5042 location,
5043 channel,
5044 read_lock,
5045 export,
5046 tables,
5047 } => {
5048 write!(f, "FLUSH")?;
5049 if let Some(location) = location {
5050 f.write_str(" ")?;
5051 location.fmt(f)?;
5052 }
5053 write!(f, " {object_type}")?;
5054
5055 if let Some(channel) = channel {
5056 write!(f, " FOR CHANNEL {channel}")?;
5057 }
5058
5059 write!(
5060 f,
5061 "{tables}{read}{export}",
5062 tables = if !tables.is_empty() {
5063 format!(" {}", display_comma_separated(tables))
5064 } else {
5065 String::new()
5066 },
5067 export = if *export { " FOR EXPORT" } else { "" },
5068 read = if *read_lock { " WITH READ LOCK" } else { "" }
5069 )
5070 }
5071 Statement::Kill { modifier, id } => {
5072 write!(f, "KILL ")?;
5073
5074 if let Some(m) = modifier {
5075 write!(f, "{m} ")?;
5076 }
5077
5078 write!(f, "{id}")
5079 }
5080 Statement::ExplainTable {
5081 describe_alias,
5082 hive_format,
5083 has_table_keyword,
5084 table_name,
5085 } => {
5086 write!(f, "{describe_alias} ")?;
5087
5088 if let Some(format) = hive_format {
5089 write!(f, "{format} ")?;
5090 }
5091 if *has_table_keyword {
5092 write!(f, "TABLE ")?;
5093 }
5094
5095 write!(f, "{table_name}")
5096 }
5097 Statement::Explain {
5098 describe_alias,
5099 verbose,
5100 analyze,
5101 query_plan,
5102 estimate,
5103 statement,
5104 format,
5105 options,
5106 } => {
5107 write!(f, "{describe_alias} ")?;
5108
5109 if *query_plan {
5110 write!(f, "QUERY PLAN ")?;
5111 }
5112 if *analyze {
5113 write!(f, "ANALYZE ")?;
5114 }
5115 if *estimate {
5116 write!(f, "ESTIMATE ")?;
5117 }
5118
5119 if *verbose {
5120 write!(f, "VERBOSE ")?;
5121 }
5122
5123 if let Some(format) = format {
5124 write!(f, "{format} ")?;
5125 }
5126
5127 if let Some(options) = options {
5128 write!(f, "({}) ", display_comma_separated(options))?;
5129 }
5130
5131 write!(f, "{statement}")
5132 }
5133 Statement::Query(s) => s.fmt(f),
5134 Statement::Declare { stmts } => {
5135 write!(f, "DECLARE ")?;
5136 write!(f, "{}", display_separated(stmts, "; "))
5137 }
5138 Statement::Fetch {
5139 name,
5140 direction,
5141 position,
5142 into,
5143 } => {
5144 write!(f, "FETCH {direction} {position} {name}")?;
5145
5146 if let Some(into) = into {
5147 write!(f, " INTO {into}")?;
5148 }
5149
5150 Ok(())
5151 }
5152 Statement::Directory {
5153 overwrite,
5154 local,
5155 path,
5156 file_format,
5157 source,
5158 } => {
5159 write!(
5160 f,
5161 "INSERT{overwrite}{local} DIRECTORY '{path}'",
5162 overwrite = if *overwrite { " OVERWRITE" } else { "" },
5163 local = if *local { " LOCAL" } else { "" },
5164 path = path
5165 )?;
5166 if let Some(ref ff) = file_format {
5167 write!(f, " STORED AS {ff}")?
5168 }
5169 write!(f, " {source}")
5170 }
5171 Statement::Msck(msck) => msck.fmt(f),
5172 Statement::Truncate(truncate) => truncate.fmt(f),
5173 Statement::Case(stmt) => {
5174 write!(f, "{stmt}")
5175 }
5176 Statement::If(stmt) => {
5177 write!(f, "{stmt}")
5178 }
5179 Statement::While(stmt) => {
5180 write!(f, "{stmt}")
5181 }
5182 Statement::Raise(stmt) => {
5183 write!(f, "{stmt}")
5184 }
5185 Statement::AttachDatabase {
5186 schema_name,
5187 database_file_name,
5188 database,
5189 } => {
5190 let keyword = if *database { "DATABASE " } else { "" };
5191 write!(f, "ATTACH {keyword}{database_file_name} AS {schema_name}")
5192 }
5193 Statement::AttachDuckDBDatabase {
5194 if_not_exists,
5195 database,
5196 database_path,
5197 database_alias,
5198 attach_options,
5199 } => {
5200 write!(
5201 f,
5202 "ATTACH{database}{if_not_exists} {database_path}",
5203 database = if *database { " DATABASE" } else { "" },
5204 if_not_exists = if *if_not_exists { " IF NOT EXISTS" } else { "" },
5205 )?;
5206 if let Some(alias) = database_alias {
5207 write!(f, " AS {alias}")?;
5208 }
5209 if !attach_options.is_empty() {
5210 write!(f, " ({})", display_comma_separated(attach_options))?;
5211 }
5212 Ok(())
5213 }
5214 Statement::DetachDuckDBDatabase {
5215 if_exists,
5216 database,
5217 database_alias,
5218 } => {
5219 write!(
5220 f,
5221 "DETACH{database}{if_exists} {database_alias}",
5222 database = if *database { " DATABASE" } else { "" },
5223 if_exists = if *if_exists { " IF EXISTS" } else { "" },
5224 )?;
5225 Ok(())
5226 }
5227 Statement::Analyze(analyze) => analyze.fmt(f),
5228 Statement::Insert(insert) => insert.fmt(f),
5229 Statement::Install {
5230 extension_name: name,
5231 } => write!(f, "INSTALL {name}"),
5232
5233 Statement::Load {
5234 extension_name: name,
5235 } => write!(f, "LOAD {name}"),
5236
5237 Statement::Call(function) => write!(f, "CALL {function}"),
5238
5239 Statement::Copy {
5240 source,
5241 to,
5242 target,
5243 options,
5244 legacy_options,
5245 values,
5246 } => {
5247 write!(f, "COPY")?;
5248 match source {
5249 CopySource::Query(query) => write!(f, " ({query})")?,
5250 CopySource::Table {
5251 table_name,
5252 columns,
5253 } => {
5254 write!(f, " {table_name}")?;
5255 if !columns.is_empty() {
5256 write!(f, " ({})", display_comma_separated(columns))?;
5257 }
5258 }
5259 }
5260 write!(f, " {} {}", if *to { "TO" } else { "FROM" }, target)?;
5261 if !options.is_empty() {
5262 write!(f, " ({})", display_comma_separated(options))?;
5263 }
5264 if !legacy_options.is_empty() {
5265 write!(f, " {}", display_separated(legacy_options, " "))?;
5266 }
5267 if !values.is_empty() {
5268 writeln!(f, ";")?;
5269 let mut delim = "";
5270 for v in values {
5271 write!(f, "{delim}")?;
5272 delim = "\t";
5273 if let Some(v) = v {
5274 write!(f, "{v}")?;
5275 } else {
5276 write!(f, "\\N")?;
5277 }
5278 }
5279 write!(f, "\n\\.")?;
5280 }
5281 Ok(())
5282 }
5283 Statement::Update(update) => update.fmt(f),
5284 Statement::Delete(delete) => delete.fmt(f),
5285 Statement::Open(open) => open.fmt(f),
5286 Statement::Close { cursor } => {
5287 write!(f, "CLOSE {cursor}")?;
5288
5289 Ok(())
5290 }
5291 Statement::CreateDatabase {
5292 db_name,
5293 if_not_exists,
5294 location,
5295 managed_location,
5296 or_replace,
5297 transient,
5298 clone,
5299 data_retention_time_in_days,
5300 max_data_extension_time_in_days,
5301 external_volume,
5302 catalog,
5303 replace_invalid_characters,
5304 default_ddl_collation,
5305 storage_serialization_policy,
5306 comment,
5307 default_charset,
5308 default_collation,
5309 catalog_sync,
5310 catalog_sync_namespace_mode,
5311 catalog_sync_namespace_flatten_delimiter,
5312 with_tags,
5313 with_contacts,
5314 } => {
5315 write!(
5316 f,
5317 "CREATE {or_replace}{transient}DATABASE {if_not_exists}{name}",
5318 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5319 transient = if *transient { "TRANSIENT " } else { "" },
5320 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5321 name = db_name,
5322 )?;
5323
5324 if let Some(l) = location {
5325 write!(f, " LOCATION '{l}'")?;
5326 }
5327 if let Some(ml) = managed_location {
5328 write!(f, " MANAGEDLOCATION '{ml}'")?;
5329 }
5330 if let Some(clone) = clone {
5331 write!(f, " CLONE {clone}")?;
5332 }
5333
5334 if let Some(value) = data_retention_time_in_days {
5335 write!(f, " DATA_RETENTION_TIME_IN_DAYS = {value}")?;
5336 }
5337
5338 if let Some(value) = max_data_extension_time_in_days {
5339 write!(f, " MAX_DATA_EXTENSION_TIME_IN_DAYS = {value}")?;
5340 }
5341
5342 if let Some(vol) = external_volume {
5343 write!(f, " EXTERNAL_VOLUME = '{vol}'")?;
5344 }
5345
5346 if let Some(cat) = catalog {
5347 write!(f, " CATALOG = '{cat}'")?;
5348 }
5349
5350 if let Some(true) = replace_invalid_characters {
5351 write!(f, " REPLACE_INVALID_CHARACTERS = TRUE")?;
5352 } else if let Some(false) = replace_invalid_characters {
5353 write!(f, " REPLACE_INVALID_CHARACTERS = FALSE")?;
5354 }
5355
5356 if let Some(collation) = default_ddl_collation {
5357 write!(f, " DEFAULT_DDL_COLLATION = '{collation}'")?;
5358 }
5359
5360 if let Some(policy) = storage_serialization_policy {
5361 write!(f, " STORAGE_SERIALIZATION_POLICY = {policy}")?;
5362 }
5363
5364 if let Some(comment) = comment {
5365 write!(f, " COMMENT = '{comment}'")?;
5366 }
5367
5368 if let Some(charset) = default_charset {
5369 write!(f, " DEFAULT CHARACTER SET {charset}")?;
5370 }
5371
5372 if let Some(collation) = default_collation {
5373 write!(f, " DEFAULT COLLATE {collation}")?;
5374 }
5375
5376 if let Some(sync) = catalog_sync {
5377 write!(f, " CATALOG_SYNC = '{sync}'")?;
5378 }
5379
5380 if let Some(mode) = catalog_sync_namespace_mode {
5381 write!(f, " CATALOG_SYNC_NAMESPACE_MODE = {mode}")?;
5382 }
5383
5384 if let Some(delim) = catalog_sync_namespace_flatten_delimiter {
5385 write!(f, " CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '{delim}'")?;
5386 }
5387
5388 if let Some(tags) = with_tags {
5389 write!(f, " WITH TAG ({})", display_comma_separated(tags))?;
5390 }
5391
5392 if let Some(contacts) = with_contacts {
5393 write!(f, " WITH CONTACT ({})", display_comma_separated(contacts))?;
5394 }
5395 Ok(())
5396 }
5397 Statement::CreateFunction(create_function) => create_function.fmt(f),
5398 Statement::CreateDomain(create_domain) => create_domain.fmt(f),
5399 Statement::CreateTrigger(create_trigger) => create_trigger.fmt(f),
5400 Statement::DropTrigger(drop_trigger) => drop_trigger.fmt(f),
5401 Statement::CreateProcedure {
5402 name,
5403 or_alter,
5404 params,
5405 language,
5406 body,
5407 } => {
5408 write!(
5409 f,
5410 "CREATE {or_alter}PROCEDURE {name}",
5411 or_alter = if *or_alter { "OR ALTER " } else { "" },
5412 name = name
5413 )?;
5414
5415 if let Some(p) = params {
5416 if !p.is_empty() {
5417 write!(f, " ({})", display_comma_separated(p))?;
5418 }
5419 }
5420
5421 if let Some(language) = language {
5422 write!(f, " LANGUAGE {language}")?;
5423 }
5424
5425 write!(f, " AS {body}")
5426 }
5427 Statement::CreateMacro {
5428 or_replace,
5429 temporary,
5430 name,
5431 args,
5432 definition,
5433 } => {
5434 write!(
5435 f,
5436 "CREATE {or_replace}{temp}MACRO {name}",
5437 temp = if *temporary { "TEMPORARY " } else { "" },
5438 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5439 )?;
5440 if let Some(args) = args {
5441 write!(f, "({})", display_comma_separated(args))?;
5442 }
5443 match definition {
5444 MacroDefinition::Expr(expr) => write!(f, " AS {expr}")?,
5445 MacroDefinition::Table(query) => write!(f, " AS TABLE {query}")?,
5446 }
5447 Ok(())
5448 }
5449 Statement::CreateView(create_view) => create_view.fmt(f),
5450 Statement::CreateTable(create_table) => create_table.fmt(f),
5451 Statement::LoadData {
5452 local,
5453 inpath,
5454 overwrite,
5455 table_name,
5456 partitioned,
5457 table_format,
5458 } => {
5459 write!(
5460 f,
5461 "LOAD DATA {local}INPATH '{inpath}' {overwrite}INTO TABLE {table_name}",
5462 local = if *local { "LOCAL " } else { "" },
5463 inpath = inpath,
5464 overwrite = if *overwrite { "OVERWRITE " } else { "" },
5465 table_name = table_name,
5466 )?;
5467 if let Some(ref parts) = &partitioned {
5468 if !parts.is_empty() {
5469 write!(f, " PARTITION ({})", display_comma_separated(parts))?;
5470 }
5471 }
5472 if let Some(HiveLoadDataFormat {
5473 serde,
5474 input_format,
5475 }) = &table_format
5476 {
5477 write!(f, " INPUTFORMAT {input_format} SERDE {serde}")?;
5478 }
5479 Ok(())
5480 }
5481 Statement::CreateVirtualTable {
5482 name,
5483 if_not_exists,
5484 module_name,
5485 module_args,
5486 } => {
5487 write!(
5488 f,
5489 "CREATE VIRTUAL TABLE {if_not_exists}{name} USING {module_name}",
5490 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5491 name = name,
5492 module_name = module_name
5493 )?;
5494 if !module_args.is_empty() {
5495 write!(f, " ({})", display_comma_separated(module_args))?;
5496 }
5497 Ok(())
5498 }
5499 Statement::CreateIndex(create_index) => create_index.fmt(f),
5500 Statement::CreateExtension(create_extension) => write!(f, "{create_extension}"),
5501 Statement::CreateCollation(create_collation) => write!(f, "{create_collation}"),
5502 Statement::CreateTextSearchConfiguration(v) => write!(f, "{v}"),
5503 Statement::CreateTextSearchDictionary(v) => write!(f, "{v}"),
5504 Statement::CreateTextSearchParser(v) => write!(f, "{v}"),
5505 Statement::CreateTextSearchTemplate(v) => write!(f, "{v}"),
5506 Statement::DropExtension(drop_extension) => write!(f, "{drop_extension}"),
5507 Statement::DropOperator(drop_operator) => write!(f, "{drop_operator}"),
5508 Statement::DropOperatorFamily(drop_operator_family) => {
5509 write!(f, "{drop_operator_family}")
5510 }
5511 Statement::DropOperatorClass(drop_operator_class) => {
5512 write!(f, "{drop_operator_class}")
5513 }
5514 Statement::CreateRole(create_role) => write!(f, "{create_role}"),
5515 Statement::CreateSecret {
5516 or_replace,
5517 temporary,
5518 if_not_exists,
5519 name,
5520 storage_specifier,
5521 secret_type,
5522 options,
5523 } => {
5524 write!(
5525 f,
5526 "CREATE {or_replace}",
5527 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5528 )?;
5529 if let Some(t) = temporary {
5530 write!(f, "{}", if *t { "TEMPORARY " } else { "PERSISTENT " })?;
5531 }
5532 write!(
5533 f,
5534 "SECRET {if_not_exists}",
5535 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5536 )?;
5537 if let Some(n) = name {
5538 write!(f, "{n} ")?;
5539 };
5540 if let Some(s) = storage_specifier {
5541 write!(f, "IN {s} ")?;
5542 }
5543 write!(f, "( TYPE {secret_type}",)?;
5544 if !options.is_empty() {
5545 write!(f, ", {o}", o = display_comma_separated(options))?;
5546 }
5547 write!(f, " )")?;
5548 Ok(())
5549 }
5550 Statement::CreateServer(stmt) => {
5551 write!(f, "{stmt}")
5552 }
5553 Statement::CreateForeignDataWrapper(stmt) => write!(f, "{stmt}"),
5554 Statement::CreateForeignTable(stmt) => write!(f, "{stmt}"),
5555 Statement::CreatePolicy(policy) => write!(f, "{policy}"),
5556 Statement::CreateConnector(create_connector) => create_connector.fmt(f),
5557 Statement::CreateOperator(create_operator) => create_operator.fmt(f),
5558 Statement::CreateOperatorFamily(create_operator_family) => {
5559 create_operator_family.fmt(f)
5560 }
5561 Statement::CreateOperatorClass(create_operator_class) => create_operator_class.fmt(f),
5562 Statement::CreateAggregate(create_aggregate) => create_aggregate.fmt(f),
5563 Statement::AlterTable(alter_table) => write!(f, "{alter_table}"),
5564 Statement::AlterIndex { name, operation } => {
5565 write!(f, "ALTER INDEX {name} {operation}")
5566 }
5567 Statement::AlterView {
5568 name,
5569 columns,
5570 query,
5571 with_options,
5572 } => {
5573 write!(f, "ALTER VIEW {name}")?;
5574 if !with_options.is_empty() {
5575 write!(f, " WITH ({})", display_comma_separated(with_options))?;
5576 }
5577 if !columns.is_empty() {
5578 write!(f, " ({})", display_comma_separated(columns))?;
5579 }
5580 write!(f, " AS {query}")
5581 }
5582 Statement::AlterFunction(alter_function) => write!(f, "{alter_function}"),
5583 Statement::AlterType(AlterType { name, operation }) => {
5584 write!(f, "ALTER TYPE {name} {operation}")
5585 }
5586 Statement::AlterCollation(alter_collation) => write!(f, "{alter_collation}"),
5587 Statement::AlterOperator(alter_operator) => write!(f, "{alter_operator}"),
5588 Statement::AlterOperatorFamily(alter_operator_family) => {
5589 write!(f, "{alter_operator_family}")
5590 }
5591 Statement::AlterOperatorClass(alter_operator_class) => {
5592 write!(f, "{alter_operator_class}")
5593 }
5594 Statement::AlterRole { name, operation } => {
5595 write!(f, "ALTER ROLE {name} {operation}")
5596 }
5597 Statement::AlterPolicy(alter_policy) => write!(f, "{alter_policy}"),
5598 Statement::AlterConnector {
5599 name,
5600 properties,
5601 url,
5602 owner,
5603 } => {
5604 write!(f, "ALTER CONNECTOR {name}")?;
5605 if let Some(properties) = properties {
5606 write!(
5607 f,
5608 " SET DCPROPERTIES({})",
5609 display_comma_separated(properties)
5610 )?;
5611 }
5612 if let Some(url) = url {
5613 write!(f, " SET URL '{url}'")?;
5614 }
5615 if let Some(owner) = owner {
5616 write!(f, " SET OWNER {owner}")?;
5617 }
5618 Ok(())
5619 }
5620 Statement::AlterSession {
5621 set,
5622 session_params,
5623 } => {
5624 write!(
5625 f,
5626 "ALTER SESSION {set}",
5627 set = if *set { "SET" } else { "UNSET" }
5628 )?;
5629 if !session_params.options.is_empty() {
5630 if *set {
5631 write!(f, " {session_params}")?;
5632 } else {
5633 let options = session_params
5634 .options
5635 .iter()
5636 .map(|p| p.option_name.clone())
5637 .collect::<Vec<_>>();
5638 write!(f, " {}", display_separated(&options, ", "))?;
5639 }
5640 }
5641 Ok(())
5642 }
5643 Statement::Drop {
5644 object_type,
5645 if_exists,
5646 names,
5647 cascade,
5648 restrict,
5649 purge,
5650 temporary,
5651 table,
5652 } => {
5653 write!(
5654 f,
5655 "DROP {}{}{} {}{}{}{}",
5656 if *temporary { "TEMPORARY " } else { "" },
5657 object_type,
5658 if *if_exists { " IF EXISTS" } else { "" },
5659 display_comma_separated(names),
5660 if *cascade { " CASCADE" } else { "" },
5661 if *restrict { " RESTRICT" } else { "" },
5662 if *purge { " PURGE" } else { "" },
5663 )?;
5664 if let Some(table_name) = table.as_ref() {
5665 write!(f, " ON {table_name}")?;
5666 };
5667 Ok(())
5668 }
5669 Statement::DropFunction(drop_function) => write!(f, "{drop_function}"),
5670 Statement::DropDomain(DropDomain {
5671 if_exists,
5672 name,
5673 drop_behavior,
5674 }) => {
5675 write!(
5676 f,
5677 "DROP DOMAIN{} {name}",
5678 if *if_exists { " IF EXISTS" } else { "" },
5679 )?;
5680 if let Some(op) = drop_behavior {
5681 write!(f, " {op}")?;
5682 }
5683 Ok(())
5684 }
5685 Statement::DropProcedure {
5686 if_exists,
5687 proc_desc,
5688 drop_behavior,
5689 } => {
5690 write!(
5691 f,
5692 "DROP PROCEDURE{} {}",
5693 if *if_exists { " IF EXISTS" } else { "" },
5694 display_comma_separated(proc_desc),
5695 )?;
5696 if let Some(op) = drop_behavior {
5697 write!(f, " {op}")?;
5698 }
5699 Ok(())
5700 }
5701 Statement::DropSecret {
5702 if_exists,
5703 temporary,
5704 name,
5705 storage_specifier,
5706 } => {
5707 write!(f, "DROP ")?;
5708 if let Some(t) = temporary {
5709 write!(f, "{}", if *t { "TEMPORARY " } else { "PERSISTENT " })?;
5710 }
5711 write!(
5712 f,
5713 "SECRET {if_exists}{name}",
5714 if_exists = if *if_exists { "IF EXISTS " } else { "" },
5715 )?;
5716 if let Some(s) = storage_specifier {
5717 write!(f, " FROM {s}")?;
5718 }
5719 Ok(())
5720 }
5721 Statement::DropPolicy(policy) => write!(f, "{policy}"),
5722 Statement::DropConnector { if_exists, name } => {
5723 write!(
5724 f,
5725 "DROP CONNECTOR {if_exists}{name}",
5726 if_exists = if *if_exists { "IF EXISTS " } else { "" }
5727 )?;
5728 Ok(())
5729 }
5730 Statement::Discard { object_type } => {
5731 write!(f, "DISCARD {object_type}")?;
5732 Ok(())
5733 }
5734 Self::Set(set) => write!(f, "{set}"),
5735 Statement::ShowVariable { variable } => {
5736 write!(f, "SHOW")?;
5737 if !variable.is_empty() {
5738 write!(f, " {}", display_separated(variable, " "))?;
5739 }
5740 Ok(())
5741 }
5742 Statement::ShowStatus {
5743 filter,
5744 global,
5745 session,
5746 } => {
5747 write!(f, "SHOW")?;
5748 if *global {
5749 write!(f, " GLOBAL")?;
5750 }
5751 if *session {
5752 write!(f, " SESSION")?;
5753 }
5754 write!(f, " STATUS")?;
5755 if filter.is_some() {
5756 write!(f, " {}", filter.as_ref().unwrap())?;
5757 }
5758 Ok(())
5759 }
5760 Statement::ShowVariables {
5761 filter,
5762 global,
5763 session,
5764 } => {
5765 write!(f, "SHOW")?;
5766 if *global {
5767 write!(f, " GLOBAL")?;
5768 }
5769 if *session {
5770 write!(f, " SESSION")?;
5771 }
5772 write!(f, " VARIABLES")?;
5773 if filter.is_some() {
5774 write!(f, " {}", filter.as_ref().unwrap())?;
5775 }
5776 Ok(())
5777 }
5778 Statement::ShowCreate { obj_type, obj_name } => {
5779 write!(f, "SHOW CREATE {obj_type} {obj_name}",)?;
5780 Ok(())
5781 }
5782 Statement::ShowColumns {
5783 extended,
5784 full,
5785 show_options,
5786 } => {
5787 write!(
5788 f,
5789 "SHOW {extended}{full}COLUMNS{show_options}",
5790 extended = if *extended { "EXTENDED " } else { "" },
5791 full = if *full { "FULL " } else { "" },
5792 )?;
5793 Ok(())
5794 }
5795 Statement::ShowDatabases {
5796 terse,
5797 history,
5798 show_options,
5799 } => {
5800 write!(
5801 f,
5802 "SHOW {terse}DATABASES{history}{show_options}",
5803 terse = if *terse { "TERSE " } else { "" },
5804 history = if *history { " HISTORY" } else { "" },
5805 )?;
5806 Ok(())
5807 }
5808 Statement::ShowCatalogs {
5809 terse,
5810 history,
5811 show_options,
5812 } => {
5813 write!(
5814 f,
5815 "SHOW {terse}CATALOGS{history}{show_options}",
5816 terse = if *terse { "TERSE " } else { "" },
5817 history = if *history { " HISTORY" } else { "" },
5818 )?;
5819 Ok(())
5820 }
5821 Statement::ShowProcessList { full } => {
5822 write!(
5823 f,
5824 "SHOW {full}PROCESSLIST",
5825 full = if *full { "FULL " } else { "" },
5826 )?;
5827 Ok(())
5828 }
5829 Statement::ShowSchemas {
5830 terse,
5831 history,
5832 show_options,
5833 } => {
5834 write!(
5835 f,
5836 "SHOW {terse}SCHEMAS{history}{show_options}",
5837 terse = if *terse { "TERSE " } else { "" },
5838 history = if *history { " HISTORY" } else { "" },
5839 )?;
5840 Ok(())
5841 }
5842 Statement::ShowObjects(ShowObjects {
5843 terse,
5844 show_options,
5845 }) => {
5846 write!(
5847 f,
5848 "SHOW {terse}OBJECTS{show_options}",
5849 terse = if *terse { "TERSE " } else { "" },
5850 )?;
5851 Ok(())
5852 }
5853 Statement::ShowTables {
5854 terse,
5855 history,
5856 extended,
5857 full,
5858 external,
5859 show_options,
5860 } => {
5861 write!(
5862 f,
5863 "SHOW {terse}{extended}{full}{external}TABLES{history}{show_options}",
5864 terse = if *terse { "TERSE " } else { "" },
5865 extended = if *extended { "EXTENDED " } else { "" },
5866 full = if *full { "FULL " } else { "" },
5867 external = if *external { "EXTERNAL " } else { "" },
5868 history = if *history { " HISTORY" } else { "" },
5869 )?;
5870 Ok(())
5871 }
5872 Statement::ShowViews {
5873 terse,
5874 materialized,
5875 show_options,
5876 } => {
5877 write!(
5878 f,
5879 "SHOW {terse}{materialized}VIEWS{show_options}",
5880 terse = if *terse { "TERSE " } else { "" },
5881 materialized = if *materialized { "MATERIALIZED " } else { "" }
5882 )?;
5883 Ok(())
5884 }
5885 Statement::ShowFunctions { filter } => {
5886 write!(f, "SHOW FUNCTIONS")?;
5887 if let Some(filter) = filter {
5888 write!(f, " {filter}")?;
5889 }
5890 Ok(())
5891 }
5892 Statement::Use(use_expr) => use_expr.fmt(f),
5893 Statement::ShowCollation { filter } => {
5894 write!(f, "SHOW COLLATION")?;
5895 if let Some(filter) = filter {
5896 write!(f, " {filter}")?;
5897 }
5898 Ok(())
5899 }
5900 Statement::ShowCharset(show_stm) => show_stm.fmt(f),
5901 Statement::StartTransaction {
5902 modes,
5903 begin: syntax_begin,
5904 transaction,
5905 modifier,
5906 statements,
5907 exception,
5908 has_end_keyword,
5909 } => {
5910 if *syntax_begin {
5911 if let Some(modifier) = *modifier {
5912 write!(f, "BEGIN {modifier}")?;
5913 } else {
5914 write!(f, "BEGIN")?;
5915 }
5916 } else {
5917 write!(f, "START")?;
5918 }
5919 if let Some(transaction) = transaction {
5920 write!(f, " {transaction}")?;
5921 }
5922 if !modes.is_empty() {
5923 write!(f, " {}", display_comma_separated(modes))?;
5924 }
5925 if !statements.is_empty() {
5926 write!(f, " ")?;
5927 format_statement_list(f, statements)?;
5928 }
5929 if let Some(exception_when) = exception {
5930 write!(f, " EXCEPTION")?;
5931 for when in exception_when {
5932 write!(f, " {when}")?;
5933 }
5934 }
5935 if *has_end_keyword {
5936 write!(f, " END")?;
5937 }
5938 Ok(())
5939 }
5940 Statement::Commit {
5941 chain,
5942 end: end_syntax,
5943 modifier,
5944 } => {
5945 if *end_syntax {
5946 write!(f, "END")?;
5947 if let Some(modifier) = *modifier {
5948 write!(f, " {modifier}")?;
5949 }
5950 if *chain {
5951 write!(f, " AND CHAIN")?;
5952 }
5953 } else {
5954 write!(f, "COMMIT{}", if *chain { " AND CHAIN" } else { "" })?;
5955 }
5956 Ok(())
5957 }
5958 Statement::Rollback { chain, savepoint } => {
5959 write!(f, "ROLLBACK")?;
5960
5961 if *chain {
5962 write!(f, " AND CHAIN")?;
5963 }
5964
5965 if let Some(savepoint) = savepoint {
5966 write!(f, " TO SAVEPOINT {savepoint}")?;
5967 }
5968
5969 Ok(())
5970 }
5971 Statement::CreateSchema {
5972 schema_name,
5973 if_not_exists,
5974 with,
5975 options,
5976 default_collate_spec,
5977 clone,
5978 } => {
5979 write!(
5980 f,
5981 "CREATE SCHEMA {if_not_exists}{name}",
5982 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5983 name = schema_name
5984 )?;
5985
5986 if let Some(collate) = default_collate_spec {
5987 write!(f, " DEFAULT COLLATE {collate}")?;
5988 }
5989
5990 if let Some(with) = with {
5991 write!(f, " WITH ({})", display_comma_separated(with))?;
5992 }
5993
5994 if let Some(options) = options {
5995 write!(f, " OPTIONS({})", display_comma_separated(options))?;
5996 }
5997
5998 if let Some(clone) = clone {
5999 write!(f, " CLONE {clone}")?;
6000 }
6001 Ok(())
6002 }
6003 Statement::Assert { condition, message } => {
6004 write!(f, "ASSERT {condition}")?;
6005 if let Some(m) = message {
6006 write!(f, " AS {m}")?;
6007 }
6008 Ok(())
6009 }
6010 Statement::Grant(grant) => write!(f, "{grant}"),
6011 Statement::Deny(s) => write!(f, "{s}"),
6012 Statement::Revoke(revoke) => write!(f, "{revoke}"),
6013 Statement::Deallocate { name, prepare } => write!(
6014 f,
6015 "DEALLOCATE {prepare}{name}",
6016 prepare = if *prepare { "PREPARE " } else { "" },
6017 name = name,
6018 ),
6019 Statement::Execute {
6020 name,
6021 parameters,
6022 has_parentheses,
6023 immediate,
6024 into,
6025 using,
6026 output,
6027 default,
6028 } => {
6029 let (open, close) = if *has_parentheses {
6030 (if name.is_some() { "(" } else { " (" }, ")")
6032 } else {
6033 (if parameters.is_empty() { "" } else { " " }, "")
6034 };
6035 write!(f, "EXECUTE")?;
6036 if *immediate {
6037 write!(f, " IMMEDIATE")?;
6038 }
6039 if let Some(name) = name {
6040 write!(f, " {name}")?;
6041 }
6042 write!(f, "{open}{}{close}", display_comma_separated(parameters),)?;
6043 if !into.is_empty() {
6044 write!(f, " INTO {}", display_comma_separated(into))?;
6045 }
6046 if !using.is_empty() {
6047 write!(f, " USING {}", display_comma_separated(using))?;
6048 };
6049 if *output {
6050 write!(f, " OUTPUT")?;
6051 }
6052 if *default {
6053 write!(f, " DEFAULT")?;
6054 }
6055 Ok(())
6056 }
6057 Statement::Prepare {
6058 name,
6059 data_types,
6060 statement,
6061 } => {
6062 write!(f, "PREPARE {name} ")?;
6063 if !data_types.is_empty() {
6064 write!(f, "({}) ", display_comma_separated(data_types))?;
6065 }
6066 write!(f, "AS {statement}")
6067 }
6068 Statement::Comment {
6069 object_type,
6070 object_name,
6071 comment,
6072 if_exists,
6073 } => {
6074 write!(f, "COMMENT ")?;
6075 if *if_exists {
6076 write!(f, "IF EXISTS ")?
6077 };
6078 write!(f, "ON {object_type} {object_name} IS ")?;
6079 if let Some(c) = comment {
6080 write!(f, "'{c}'")
6081 } else {
6082 write!(f, "NULL")
6083 }
6084 }
6085 Statement::Savepoint { name } => {
6086 write!(f, "SAVEPOINT ")?;
6087 write!(f, "{name}")
6088 }
6089 Statement::ReleaseSavepoint { name } => {
6090 write!(f, "RELEASE SAVEPOINT {name}")
6091 }
6092 Statement::Merge(merge) => merge.fmt(f),
6093 Statement::Cache {
6094 table_name,
6095 table_flag,
6096 has_as,
6097 options,
6098 query,
6099 } => {
6100 if let Some(table_flag) = table_flag {
6101 write!(f, "CACHE {table_flag} TABLE {table_name}")?;
6102 } else {
6103 write!(f, "CACHE TABLE {table_name}")?;
6104 }
6105
6106 if !options.is_empty() {
6107 write!(f, " OPTIONS({})", display_comma_separated(options))?;
6108 }
6109
6110 match (*has_as, query) {
6111 (true, Some(query)) => write!(f, " AS {query}"),
6112 (true, None) => f.write_str(" AS"),
6113 (false, Some(query)) => write!(f, " {query}"),
6114 (false, None) => Ok(()),
6115 }
6116 }
6117 Statement::UNCache {
6118 table_name,
6119 if_exists,
6120 } => {
6121 if *if_exists {
6122 write!(f, "UNCACHE TABLE IF EXISTS {table_name}")
6123 } else {
6124 write!(f, "UNCACHE TABLE {table_name}")
6125 }
6126 }
6127 Statement::CreateSequence {
6128 temporary,
6129 if_not_exists,
6130 name,
6131 data_type,
6132 sequence_options,
6133 owned_by,
6134 } => {
6135 let as_type: String = if let Some(dt) = data_type.as_ref() {
6136 [" AS ", &dt.to_string()].concat()
6139 } else {
6140 "".to_string()
6141 };
6142 write!(
6143 f,
6144 "CREATE {temporary}SEQUENCE {if_not_exists}{name}{as_type}",
6145 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
6146 temporary = if *temporary { "TEMPORARY " } else { "" },
6147 name = name,
6148 as_type = as_type
6149 )?;
6150 for sequence_option in sequence_options {
6151 write!(f, "{sequence_option}")?;
6152 }
6153 if let Some(ob) = owned_by.as_ref() {
6154 write!(f, " OWNED BY {ob}")?;
6155 }
6156 write!(f, "")
6157 }
6158 Statement::CreateStage {
6159 or_replace,
6160 temporary,
6161 if_not_exists,
6162 name,
6163 stage_params,
6164 directory_table_params,
6165 file_format,
6166 copy_options,
6167 comment,
6168 ..
6169 } => {
6170 write!(
6171 f,
6172 "CREATE {or_replace}{temp}STAGE {if_not_exists}{name}{stage_params}",
6173 temp = if *temporary { "TEMPORARY " } else { "" },
6174 or_replace = if *or_replace { "OR REPLACE " } else { "" },
6175 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
6176 )?;
6177 if !directory_table_params.options.is_empty() {
6178 write!(f, " DIRECTORY=({directory_table_params})")?;
6179 }
6180 if !file_format.options.is_empty() {
6181 write!(f, " FILE_FORMAT=({file_format})")?;
6182 }
6183 if !copy_options.options.is_empty() {
6184 write!(f, " COPY_OPTIONS=({copy_options})")?;
6185 }
6186 if comment.is_some() {
6187 write!(f, " COMMENT='{}'", comment.as_ref().unwrap())?;
6188 }
6189 Ok(())
6190 }
6191 Statement::CopyIntoSnowflake {
6192 kind,
6193 into,
6194 into_columns,
6195 from_obj,
6196 from_obj_alias,
6197 stage_params,
6198 from_transformations,
6199 from_query,
6200 files,
6201 pattern,
6202 file_format,
6203 copy_options,
6204 validation_mode,
6205 partition,
6206 } => {
6207 write!(f, "COPY INTO {into}")?;
6208 if let Some(into_columns) = into_columns {
6209 write!(f, " ({})", display_comma_separated(into_columns))?;
6210 }
6211 if let Some(from_transformations) = from_transformations {
6212 if let Some(from_stage) = from_obj {
6214 write!(
6215 f,
6216 " FROM (SELECT {} FROM {}{}",
6217 display_separated(from_transformations, ", "),
6218 from_stage,
6219 stage_params
6220 )?;
6221 }
6222 if let Some(from_obj_alias) = from_obj_alias {
6223 write!(f, " AS {from_obj_alias}")?;
6224 }
6225 write!(f, ")")?;
6226 } else if let Some(from_obj) = from_obj {
6227 write!(f, " FROM {from_obj}{stage_params}")?;
6229 if let Some(from_obj_alias) = from_obj_alias {
6230 write!(f, " AS {from_obj_alias}")?;
6231 }
6232 } else if let Some(from_query) = from_query {
6233 write!(f, " FROM ({from_query})")?;
6235 }
6236
6237 if let Some(files) = files {
6238 write!(f, " FILES = ('{}')", display_separated(files, "', '"))?;
6239 }
6240 if let Some(pattern) = pattern {
6241 write!(f, " PATTERN = '{pattern}'")?;
6242 }
6243 if let Some(partition) = partition {
6244 write!(f, " PARTITION BY {partition}")?;
6245 }
6246 if !file_format.options.is_empty() {
6247 write!(f, " FILE_FORMAT=({file_format})")?;
6248 }
6249 if !copy_options.options.is_empty() {
6250 match kind {
6251 CopyIntoSnowflakeKind::Table => {
6252 write!(f, " COPY_OPTIONS=({copy_options})")?
6253 }
6254 CopyIntoSnowflakeKind::Location => write!(f, " {copy_options}")?,
6255 }
6256 }
6257 if let Some(validation_mode) = validation_mode {
6258 write!(f, " VALIDATION_MODE = {validation_mode}")?;
6259 }
6260 Ok(())
6261 }
6262 Statement::CreateType {
6263 name,
6264 representation,
6265 } => {
6266 write!(f, "CREATE TYPE {name}")?;
6267 if let Some(repr) = representation {
6268 write!(f, " {repr}")?;
6269 }
6270 Ok(())
6271 }
6272 Statement::Pragma { name, value, is_eq } => {
6273 write!(f, "PRAGMA {name}")?;
6274 if value.is_some() {
6275 let val = value.as_ref().unwrap();
6276 if *is_eq {
6277 write!(f, " = {val}")?;
6278 } else {
6279 write!(f, "({val})")?;
6280 }
6281 }
6282 Ok(())
6283 }
6284 Statement::Lock(lock) => lock.fmt(f),
6285 Statement::LockTables { tables } => {
6286 write!(f, "LOCK TABLES {}", display_comma_separated(tables))
6287 }
6288 Statement::UnlockTables => {
6289 write!(f, "UNLOCK TABLES")
6290 }
6291 Statement::Unload {
6292 query,
6293 query_text,
6294 to,
6295 auth,
6296 with,
6297 options,
6298 } => {
6299 write!(f, "UNLOAD(")?;
6300 if let Some(query) = query {
6301 write!(f, "{query}")?;
6302 }
6303 if let Some(query_text) = query_text {
6304 write!(f, "'{query_text}'")?;
6305 }
6306 write!(f, ") TO {to}")?;
6307 if let Some(auth) = auth {
6308 write!(f, " IAM_ROLE {auth}")?;
6309 }
6310 if !with.is_empty() {
6311 write!(f, " WITH ({})", display_comma_separated(with))?;
6312 }
6313 if !options.is_empty() {
6314 write!(f, " {}", display_separated(options, " "))?;
6315 }
6316 Ok(())
6317 }
6318 Statement::OptimizeTable {
6319 name,
6320 has_table_keyword,
6321 on_cluster,
6322 partition,
6323 include_final,
6324 deduplicate,
6325 predicate,
6326 zorder,
6327 } => {
6328 write!(f, "OPTIMIZE")?;
6329 if *has_table_keyword {
6330 write!(f, " TABLE")?;
6331 }
6332 write!(f, " {name}")?;
6333 if let Some(on_cluster) = on_cluster {
6334 write!(f, " ON CLUSTER {on_cluster}")?;
6335 }
6336 if let Some(partition) = partition {
6337 write!(f, " {partition}")?;
6338 }
6339 if *include_final {
6340 write!(f, " FINAL")?;
6341 }
6342 if let Some(deduplicate) = deduplicate {
6343 write!(f, " {deduplicate}")?;
6344 }
6345 if let Some(predicate) = predicate {
6346 write!(f, " WHERE {predicate}")?;
6347 }
6348 if let Some(zorder) = zorder {
6349 write!(f, " ZORDER BY ({})", display_comma_separated(zorder))?;
6350 }
6351 Ok(())
6352 }
6353 Statement::LISTEN { channel } => {
6354 write!(f, "LISTEN {channel}")?;
6355 Ok(())
6356 }
6357 Statement::UNLISTEN { channel } => {
6358 write!(f, "UNLISTEN {channel}")?;
6359 Ok(())
6360 }
6361 Statement::NOTIFY { channel, payload } => {
6362 write!(f, "NOTIFY {channel}")?;
6363 if let Some(payload) = payload {
6364 write!(f, ", '{payload}'")?;
6365 }
6366 Ok(())
6367 }
6368 Statement::RenameTable(rename_tables) => {
6369 write!(f, "RENAME TABLE {}", display_comma_separated(rename_tables))
6370 }
6371 Statement::RaisError {
6372 message,
6373 severity,
6374 state,
6375 arguments,
6376 options,
6377 } => {
6378 write!(f, "RAISERROR({message}, {severity}, {state}")?;
6379 if !arguments.is_empty() {
6380 write!(f, ", {}", display_comma_separated(arguments))?;
6381 }
6382 write!(f, ")")?;
6383 if !options.is_empty() {
6384 write!(f, " WITH {}", display_comma_separated(options))?;
6385 }
6386 Ok(())
6387 }
6388 Statement::Throw(s) => write!(f, "{s}"),
6389 Statement::Print(s) => write!(f, "{s}"),
6390 Statement::WaitFor(s) => write!(f, "{s}"),
6391 Statement::Return(r) => write!(f, "{r}"),
6392 Statement::List(command) => write!(f, "LIST {command}"),
6393 Statement::Remove(command) => write!(f, "REMOVE {command}"),
6394 Statement::ExportData(e) => write!(f, "{e}"),
6395 Statement::CreateUser(s) => write!(f, "{s}"),
6396 Statement::AlterSchema(s) => write!(f, "{s}"),
6397 Statement::Vacuum(s) => write!(f, "{s}"),
6398 Statement::AlterUser(s) => write!(f, "{s}"),
6399 Statement::Reset(s) => write!(f, "{s}"),
6400 }
6401 }
6402}
6403
6404#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6411#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6412#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6413pub enum SequenceOptions {
6414 IncrementBy(Expr, bool),
6416 MinValue(Option<Expr>),
6418 MaxValue(Option<Expr>),
6420 StartWith(Expr, bool),
6422 Cache(Expr),
6424 Cycle(bool),
6426}
6427
6428impl fmt::Display for SequenceOptions {
6429 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6430 match self {
6431 SequenceOptions::IncrementBy(increment, by) => {
6432 write!(
6433 f,
6434 " INCREMENT{by} {increment}",
6435 by = if *by { " BY" } else { "" },
6436 increment = increment
6437 )
6438 }
6439 SequenceOptions::MinValue(Some(expr)) => {
6440 write!(f, " MINVALUE {expr}")
6441 }
6442 SequenceOptions::MinValue(None) => {
6443 write!(f, " NO MINVALUE")
6444 }
6445 SequenceOptions::MaxValue(Some(expr)) => {
6446 write!(f, " MAXVALUE {expr}")
6447 }
6448 SequenceOptions::MaxValue(None) => {
6449 write!(f, " NO MAXVALUE")
6450 }
6451 SequenceOptions::StartWith(start, with) => {
6452 write!(
6453 f,
6454 " START{with} {start}",
6455 with = if *with { " WITH" } else { "" },
6456 start = start
6457 )
6458 }
6459 SequenceOptions::Cache(cache) => {
6460 write!(f, " CACHE {}", *cache)
6461 }
6462 SequenceOptions::Cycle(no) => {
6463 write!(f, " {}CYCLE", if *no { "NO " } else { "" })
6464 }
6465 }
6466 }
6467}
6468
6469#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6471#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6472#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6473pub struct SetAssignment {
6474 pub scope: Option<ContextModifier>,
6476 pub name: ObjectName,
6478 pub value: Expr,
6480}
6481
6482impl fmt::Display for SetAssignment {
6483 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6484 write!(
6485 f,
6486 "{}{} = {}",
6487 self.scope.map(|s| format!("{s}")).unwrap_or_default(),
6488 self.name,
6489 self.value
6490 )
6491 }
6492}
6493
6494#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6498#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6499#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6500pub struct TruncateTableTarget {
6501 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
6503 pub name: ObjectName,
6504 pub only: bool,
6510 pub has_asterisk: bool,
6516}
6517
6518impl fmt::Display for TruncateTableTarget {
6519 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6520 if self.only {
6521 write!(f, "ONLY ")?;
6522 };
6523 write!(f, "{}", self.name)?;
6524 if self.has_asterisk {
6525 write!(f, " *")?;
6526 };
6527 Ok(())
6528 }
6529}
6530
6531#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6535#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6536#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6537pub struct Lock {
6538 pub tables: Vec<LockTableTarget>,
6540 pub lock_mode: Option<LockTableMode>,
6542 pub nowait: bool,
6544}
6545
6546impl fmt::Display for Lock {
6547 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6548 write!(f, "LOCK TABLE {}", display_comma_separated(&self.tables))?;
6549 if let Some(lock_mode) = &self.lock_mode {
6550 write!(f, " IN {lock_mode} MODE")?;
6551 }
6552 if self.nowait {
6553 write!(f, " NOWAIT")?;
6554 }
6555 Ok(())
6556 }
6557}
6558
6559#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6563#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6564#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6565pub struct LockTableTarget {
6566 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
6568 pub name: ObjectName,
6569 pub only: bool,
6571 pub has_asterisk: bool,
6573}
6574
6575impl fmt::Display for LockTableTarget {
6576 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6577 if self.only {
6578 write!(f, "ONLY ")?;
6579 }
6580 write!(f, "{}", self.name)?;
6581 if self.has_asterisk {
6582 write!(f, " *")?;
6583 }
6584 Ok(())
6585 }
6586}
6587
6588#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6592#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6593#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6594pub enum LockTableMode {
6595 AccessShare,
6597 RowShare,
6599 RowExclusive,
6601 ShareUpdateExclusive,
6603 Share,
6605 ShareRowExclusive,
6607 Exclusive,
6609 AccessExclusive,
6611}
6612
6613impl fmt::Display for LockTableMode {
6614 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6615 let text = match self {
6616 Self::AccessShare => "ACCESS SHARE",
6617 Self::RowShare => "ROW SHARE",
6618 Self::RowExclusive => "ROW EXCLUSIVE",
6619 Self::ShareUpdateExclusive => "SHARE UPDATE EXCLUSIVE",
6620 Self::Share => "SHARE",
6621 Self::ShareRowExclusive => "SHARE ROW EXCLUSIVE",
6622 Self::Exclusive => "EXCLUSIVE",
6623 Self::AccessExclusive => "ACCESS EXCLUSIVE",
6624 };
6625 write!(f, "{text}")
6626 }
6627}
6628
6629#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6632#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6633#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6634pub enum TruncateIdentityOption {
6635 Restart,
6637 Continue,
6639}
6640
6641#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6644#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6645#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6646pub enum CascadeOption {
6647 Cascade,
6649 Restrict,
6651}
6652
6653impl Display for CascadeOption {
6654 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6655 match self {
6656 CascadeOption::Cascade => write!(f, "CASCADE"),
6657 CascadeOption::Restrict => write!(f, "RESTRICT"),
6658 }
6659 }
6660}
6661
6662#[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 BeginTransactionKind {
6667 Transaction,
6669 Work,
6671 Tran,
6674}
6675
6676impl Display for BeginTransactionKind {
6677 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6678 match self {
6679 BeginTransactionKind::Transaction => write!(f, "TRANSACTION"),
6680 BeginTransactionKind::Work => write!(f, "WORK"),
6681 BeginTransactionKind::Tran => write!(f, "TRAN"),
6682 }
6683 }
6684}
6685
6686#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6689#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6690#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6691pub enum MinMaxValue {
6692 Empty,
6694 None,
6696 Some(Expr),
6698}
6699
6700#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6701#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6702#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6703#[non_exhaustive]
6704pub enum OnInsert {
6706 DuplicateKeyUpdate(Vec<Assignment>),
6708 OnConflict(OnConflict),
6710}
6711
6712#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6713#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6714#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6715pub struct InsertAliases {
6717 pub row_alias: ObjectName,
6719 pub col_aliases: Option<Vec<Ident>>,
6721}
6722
6723#[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 TableAliasWithoutColumns {
6728 pub explicit: bool,
6730 pub alias: Ident,
6732}
6733
6734#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6735#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6736#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6737pub struct OnConflict {
6739 pub conflict_target: Option<ConflictTarget>,
6741 pub action: OnConflictAction,
6743}
6744#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6745#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6746#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6747pub enum ConflictTarget {
6749 Columns(Vec<Ident>),
6751 OnConstraint(ObjectName),
6753}
6754#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6755#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6756#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6757pub enum OnConflictAction {
6759 DoNothing,
6761 DoUpdate(DoUpdate),
6763}
6764
6765#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6766#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6767#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6768pub struct DoUpdate {
6770 pub assignments: Vec<Assignment>,
6772 pub selection: Option<Expr>,
6774}
6775
6776impl fmt::Display for OnInsert {
6777 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6778 match self {
6779 Self::DuplicateKeyUpdate(expr) => write!(
6780 f,
6781 " ON DUPLICATE KEY UPDATE {}",
6782 display_comma_separated(expr)
6783 ),
6784 Self::OnConflict(o) => write!(f, "{o}"),
6785 }
6786 }
6787}
6788impl fmt::Display for OnConflict {
6789 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6790 write!(f, " ON CONFLICT")?;
6791 if let Some(target) = &self.conflict_target {
6792 write!(f, "{target}")?;
6793 }
6794 write!(f, " {}", self.action)
6795 }
6796}
6797impl fmt::Display for ConflictTarget {
6798 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6799 match self {
6800 ConflictTarget::Columns(cols) => write!(f, "({})", display_comma_separated(cols)),
6801 ConflictTarget::OnConstraint(name) => write!(f, " ON CONSTRAINT {name}"),
6802 }
6803 }
6804}
6805impl fmt::Display for OnConflictAction {
6806 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6807 match self {
6808 Self::DoNothing => write!(f, "DO NOTHING"),
6809 Self::DoUpdate(do_update) => {
6810 write!(f, "DO UPDATE")?;
6811 if !do_update.assignments.is_empty() {
6812 write!(
6813 f,
6814 " SET {}",
6815 display_comma_separated(&do_update.assignments)
6816 )?;
6817 }
6818 if let Some(selection) = &do_update.selection {
6819 write!(f, " WHERE {selection}")?;
6820 }
6821 Ok(())
6822 }
6823 }
6824 }
6825}
6826
6827#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6829#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6830#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6831pub enum Privileges {
6832 All {
6834 with_privileges_keyword: bool,
6836 },
6837 Actions(Vec<Action>),
6839}
6840
6841impl fmt::Display for Privileges {
6842 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6843 match self {
6844 Privileges::All {
6845 with_privileges_keyword,
6846 } => {
6847 write!(
6848 f,
6849 "ALL{}",
6850 if *with_privileges_keyword {
6851 " PRIVILEGES"
6852 } else {
6853 ""
6854 }
6855 )
6856 }
6857 Privileges::Actions(actions) => {
6858 write!(f, "{}", display_comma_separated(actions))
6859 }
6860 }
6861 }
6862}
6863
6864#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6866#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6867#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6868pub enum FetchDirection {
6869 Count {
6871 limit: ValueWithSpan,
6873 },
6874 Next,
6876 Prior,
6878 First,
6880 Last,
6882 Absolute {
6884 limit: ValueWithSpan,
6886 },
6887 Relative {
6889 limit: ValueWithSpan,
6891 },
6892 All,
6894 Forward {
6898 limit: Option<ValueWithSpan>,
6900 },
6901 ForwardAll,
6903 Backward {
6907 limit: Option<ValueWithSpan>,
6909 },
6910 BackwardAll,
6912}
6913
6914impl fmt::Display for FetchDirection {
6915 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6916 match self {
6917 FetchDirection::Count { limit } => f.write_str(&limit.to_string())?,
6918 FetchDirection::Next => f.write_str("NEXT")?,
6919 FetchDirection::Prior => f.write_str("PRIOR")?,
6920 FetchDirection::First => f.write_str("FIRST")?,
6921 FetchDirection::Last => f.write_str("LAST")?,
6922 FetchDirection::Absolute { limit } => {
6923 f.write_str("ABSOLUTE ")?;
6924 f.write_str(&limit.to_string())?;
6925 }
6926 FetchDirection::Relative { limit } => {
6927 f.write_str("RELATIVE ")?;
6928 f.write_str(&limit.to_string())?;
6929 }
6930 FetchDirection::All => f.write_str("ALL")?,
6931 FetchDirection::Forward { limit } => {
6932 f.write_str("FORWARD")?;
6933
6934 if let Some(l) = limit {
6935 f.write_str(" ")?;
6936 f.write_str(&l.to_string())?;
6937 }
6938 }
6939 FetchDirection::ForwardAll => f.write_str("FORWARD ALL")?,
6940 FetchDirection::Backward { limit } => {
6941 f.write_str("BACKWARD")?;
6942
6943 if let Some(l) = limit {
6944 f.write_str(" ")?;
6945 f.write_str(&l.to_string())?;
6946 }
6947 }
6948 FetchDirection::BackwardAll => f.write_str("BACKWARD ALL")?,
6949 };
6950
6951 Ok(())
6952 }
6953}
6954
6955#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6959#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6960#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6961pub enum FetchPosition {
6962 From,
6964 In,
6966}
6967
6968impl fmt::Display for FetchPosition {
6969 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6970 match self {
6971 FetchPosition::From => f.write_str("FROM")?,
6972 FetchPosition::In => f.write_str("IN")?,
6973 };
6974
6975 Ok(())
6976 }
6977}
6978
6979#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6981#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6982#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6983pub enum Action {
6984 AddSearchOptimization,
6986 Apply {
6988 apply_type: ActionApplyType,
6990 },
6991 ApplyBudget,
6993 AttachListing,
6995 AttachPolicy,
6997 Audit,
6999 BindServiceEndpoint,
7001 Connect,
7003 Create {
7005 obj_type: Option<ActionCreateObjectType>,
7007 },
7008 DatabaseRole {
7010 role: ObjectName,
7012 },
7013 Delete,
7015 Drop,
7017 EvolveSchema,
7019 Exec {
7021 obj_type: Option<ActionExecuteObjectType>,
7023 },
7024 Execute {
7026 obj_type: Option<ActionExecuteObjectType>,
7028 },
7029 Failover,
7031 ImportedPrivileges,
7033 ImportShare,
7035 Insert {
7037 columns: Option<Vec<Ident>>,
7039 },
7040 Manage {
7042 manage_type: ActionManageType,
7044 },
7045 ManageReleases,
7047 ManageVersions,
7049 Modify {
7051 modify_type: Option<ActionModifyType>,
7053 },
7054 Monitor {
7056 monitor_type: Option<ActionMonitorType>,
7058 },
7059 Operate,
7061 OverrideShareRestrictions,
7063 Ownership,
7065 PurchaseDataExchangeListing,
7067
7068 Read,
7070 ReadSession,
7072 References {
7074 columns: Option<Vec<Ident>>,
7076 },
7077 Replicate,
7079 ResolveAll,
7081 Role {
7083 role: ObjectName,
7085 },
7086 Select {
7088 columns: Option<Vec<Ident>>,
7090 },
7091 Temporary,
7093 Trigger,
7095 Truncate,
7097 Update {
7099 columns: Option<Vec<Ident>>,
7101 },
7102 Usage,
7104}
7105
7106impl fmt::Display for Action {
7107 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7108 match self {
7109 Action::AddSearchOptimization => f.write_str("ADD SEARCH OPTIMIZATION")?,
7110 Action::Apply { apply_type } => write!(f, "APPLY {apply_type}")?,
7111 Action::ApplyBudget => f.write_str("APPLYBUDGET")?,
7112 Action::AttachListing => f.write_str("ATTACH LISTING")?,
7113 Action::AttachPolicy => f.write_str("ATTACH POLICY")?,
7114 Action::Audit => f.write_str("AUDIT")?,
7115 Action::BindServiceEndpoint => f.write_str("BIND SERVICE ENDPOINT")?,
7116 Action::Connect => f.write_str("CONNECT")?,
7117 Action::Create { obj_type } => {
7118 f.write_str("CREATE")?;
7119 if let Some(obj_type) = obj_type {
7120 write!(f, " {obj_type}")?
7121 }
7122 }
7123 Action::DatabaseRole { role } => write!(f, "DATABASE ROLE {role}")?,
7124 Action::Delete => f.write_str("DELETE")?,
7125 Action::Drop => f.write_str("DROP")?,
7126 Action::EvolveSchema => f.write_str("EVOLVE SCHEMA")?,
7127 Action::Exec { obj_type } => {
7128 f.write_str("EXEC")?;
7129 if let Some(obj_type) = obj_type {
7130 write!(f, " {obj_type}")?
7131 }
7132 }
7133 Action::Execute { obj_type } => {
7134 f.write_str("EXECUTE")?;
7135 if let Some(obj_type) = obj_type {
7136 write!(f, " {obj_type}")?
7137 }
7138 }
7139 Action::Failover => f.write_str("FAILOVER")?,
7140 Action::ImportedPrivileges => f.write_str("IMPORTED PRIVILEGES")?,
7141 Action::ImportShare => f.write_str("IMPORT SHARE")?,
7142 Action::Insert { .. } => f.write_str("INSERT")?,
7143 Action::Manage { manage_type } => write!(f, "MANAGE {manage_type}")?,
7144 Action::ManageReleases => f.write_str("MANAGE RELEASES")?,
7145 Action::ManageVersions => f.write_str("MANAGE VERSIONS")?,
7146 Action::Modify { modify_type } => {
7147 write!(f, "MODIFY")?;
7148 if let Some(modify_type) = modify_type {
7149 write!(f, " {modify_type}")?;
7150 }
7151 }
7152 Action::Monitor { monitor_type } => {
7153 write!(f, "MONITOR")?;
7154 if let Some(monitor_type) = monitor_type {
7155 write!(f, " {monitor_type}")?
7156 }
7157 }
7158 Action::Operate => f.write_str("OPERATE")?,
7159 Action::OverrideShareRestrictions => f.write_str("OVERRIDE SHARE RESTRICTIONS")?,
7160 Action::Ownership => f.write_str("OWNERSHIP")?,
7161 Action::PurchaseDataExchangeListing => f.write_str("PURCHASE DATA EXCHANGE LISTING")?,
7162 Action::Read => f.write_str("READ")?,
7163 Action::ReadSession => f.write_str("READ SESSION")?,
7164 Action::References { .. } => f.write_str("REFERENCES")?,
7165 Action::Replicate => f.write_str("REPLICATE")?,
7166 Action::ResolveAll => f.write_str("RESOLVE ALL")?,
7167 Action::Role { role } => write!(f, "ROLE {role}")?,
7168 Action::Select { .. } => f.write_str("SELECT")?,
7169 Action::Temporary => f.write_str("TEMPORARY")?,
7170 Action::Trigger => f.write_str("TRIGGER")?,
7171 Action::Truncate => f.write_str("TRUNCATE")?,
7172 Action::Update { .. } => f.write_str("UPDATE")?,
7173 Action::Usage => f.write_str("USAGE")?,
7174 };
7175 match self {
7176 Action::Insert { columns }
7177 | Action::References { columns }
7178 | Action::Select { columns }
7179 | Action::Update { columns } => {
7180 if let Some(columns) = columns {
7181 write!(f, " ({})", display_comma_separated(columns))?;
7182 }
7183 }
7184 _ => (),
7185 };
7186 Ok(())
7187 }
7188}
7189
7190#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7191#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7192#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7193pub enum ActionCreateObjectType {
7196 Account,
7198 Application,
7200 ApplicationPackage,
7202 ComputePool,
7204 DataExchangeListing,
7206 Database,
7208 ExternalVolume,
7210 FailoverGroup,
7212 Integration,
7214 NetworkPolicy,
7216 OrganiationListing,
7218 ReplicationGroup,
7220 Role,
7222 Schema,
7224 Share,
7226 User,
7228 Warehouse,
7230}
7231
7232impl fmt::Display for ActionCreateObjectType {
7233 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7234 match self {
7235 ActionCreateObjectType::Account => write!(f, "ACCOUNT"),
7236 ActionCreateObjectType::Application => write!(f, "APPLICATION"),
7237 ActionCreateObjectType::ApplicationPackage => write!(f, "APPLICATION PACKAGE"),
7238 ActionCreateObjectType::ComputePool => write!(f, "COMPUTE POOL"),
7239 ActionCreateObjectType::DataExchangeListing => write!(f, "DATA EXCHANGE LISTING"),
7240 ActionCreateObjectType::Database => write!(f, "DATABASE"),
7241 ActionCreateObjectType::ExternalVolume => write!(f, "EXTERNAL VOLUME"),
7242 ActionCreateObjectType::FailoverGroup => write!(f, "FAILOVER GROUP"),
7243 ActionCreateObjectType::Integration => write!(f, "INTEGRATION"),
7244 ActionCreateObjectType::NetworkPolicy => write!(f, "NETWORK POLICY"),
7245 ActionCreateObjectType::OrganiationListing => write!(f, "ORGANIZATION LISTING"),
7246 ActionCreateObjectType::ReplicationGroup => write!(f, "REPLICATION GROUP"),
7247 ActionCreateObjectType::Role => write!(f, "ROLE"),
7248 ActionCreateObjectType::Schema => write!(f, "SCHEMA"),
7249 ActionCreateObjectType::Share => write!(f, "SHARE"),
7250 ActionCreateObjectType::User => write!(f, "USER"),
7251 ActionCreateObjectType::Warehouse => write!(f, "WAREHOUSE"),
7252 }
7253 }
7254}
7255
7256#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7257#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7258#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7259pub enum ActionApplyType {
7262 AggregationPolicy,
7264 AuthenticationPolicy,
7266 JoinPolicy,
7268 MaskingPolicy,
7270 PackagesPolicy,
7272 PasswordPolicy,
7274 ProjectionPolicy,
7276 RowAccessPolicy,
7278 SessionPolicy,
7280 Tag,
7282}
7283
7284impl fmt::Display for ActionApplyType {
7285 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7286 match self {
7287 ActionApplyType::AggregationPolicy => write!(f, "AGGREGATION POLICY"),
7288 ActionApplyType::AuthenticationPolicy => write!(f, "AUTHENTICATION POLICY"),
7289 ActionApplyType::JoinPolicy => write!(f, "JOIN POLICY"),
7290 ActionApplyType::MaskingPolicy => write!(f, "MASKING POLICY"),
7291 ActionApplyType::PackagesPolicy => write!(f, "PACKAGES POLICY"),
7292 ActionApplyType::PasswordPolicy => write!(f, "PASSWORD POLICY"),
7293 ActionApplyType::ProjectionPolicy => write!(f, "PROJECTION POLICY"),
7294 ActionApplyType::RowAccessPolicy => write!(f, "ROW ACCESS POLICY"),
7295 ActionApplyType::SessionPolicy => write!(f, "SESSION POLICY"),
7296 ActionApplyType::Tag => write!(f, "TAG"),
7297 }
7298 }
7299}
7300
7301#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7302#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7303#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7304pub enum ActionExecuteObjectType {
7307 Alert,
7309 DataMetricFunction,
7311 ManagedAlert,
7313 ManagedTask,
7315 Task,
7317}
7318
7319impl fmt::Display for ActionExecuteObjectType {
7320 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7321 match self {
7322 ActionExecuteObjectType::Alert => write!(f, "ALERT"),
7323 ActionExecuteObjectType::DataMetricFunction => write!(f, "DATA METRIC FUNCTION"),
7324 ActionExecuteObjectType::ManagedAlert => write!(f, "MANAGED ALERT"),
7325 ActionExecuteObjectType::ManagedTask => write!(f, "MANAGED TASK"),
7326 ActionExecuteObjectType::Task => write!(f, "TASK"),
7327 }
7328 }
7329}
7330
7331#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7332#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7333#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7334pub enum ActionManageType {
7337 AccountSupportCases,
7339 EventSharing,
7341 Grants,
7343 ListingAutoFulfillment,
7345 OrganizationSupportCases,
7347 UserSupportCases,
7349 Warehouses,
7351}
7352
7353impl fmt::Display for ActionManageType {
7354 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7355 match self {
7356 ActionManageType::AccountSupportCases => write!(f, "ACCOUNT SUPPORT CASES"),
7357 ActionManageType::EventSharing => write!(f, "EVENT SHARING"),
7358 ActionManageType::Grants => write!(f, "GRANTS"),
7359 ActionManageType::ListingAutoFulfillment => write!(f, "LISTING AUTO FULFILLMENT"),
7360 ActionManageType::OrganizationSupportCases => write!(f, "ORGANIZATION SUPPORT CASES"),
7361 ActionManageType::UserSupportCases => write!(f, "USER SUPPORT CASES"),
7362 ActionManageType::Warehouses => write!(f, "WAREHOUSES"),
7363 }
7364 }
7365}
7366
7367#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7368#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7369#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7370pub enum ActionModifyType {
7373 LogLevel,
7375 TraceLevel,
7377 SessionLogLevel,
7379 SessionTraceLevel,
7381}
7382
7383impl fmt::Display for ActionModifyType {
7384 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7385 match self {
7386 ActionModifyType::LogLevel => write!(f, "LOG LEVEL"),
7387 ActionModifyType::TraceLevel => write!(f, "TRACE LEVEL"),
7388 ActionModifyType::SessionLogLevel => write!(f, "SESSION LOG LEVEL"),
7389 ActionModifyType::SessionTraceLevel => write!(f, "SESSION TRACE LEVEL"),
7390 }
7391 }
7392}
7393
7394#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7395#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7396#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7397pub enum ActionMonitorType {
7400 Execution,
7402 Security,
7404 Usage,
7406}
7407
7408impl fmt::Display for ActionMonitorType {
7409 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7410 match self {
7411 ActionMonitorType::Execution => write!(f, "EXECUTION"),
7412 ActionMonitorType::Security => write!(f, "SECURITY"),
7413 ActionMonitorType::Usage => write!(f, "USAGE"),
7414 }
7415 }
7416}
7417
7418#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7420#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7421#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7422pub struct Grantee {
7423 pub grantee_type: GranteesType,
7425 pub name: Option<GranteeName>,
7427}
7428
7429impl fmt::Display for Grantee {
7430 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7431 match self.grantee_type {
7432 GranteesType::Role => {
7433 write!(f, "ROLE ")?;
7434 }
7435 GranteesType::Share => {
7436 write!(f, "SHARE ")?;
7437 }
7438 GranteesType::User => {
7439 write!(f, "USER ")?;
7440 }
7441 GranteesType::Group => {
7442 write!(f, "GROUP ")?;
7443 }
7444 GranteesType::Public => {
7445 write!(f, "PUBLIC ")?;
7446 }
7447 GranteesType::DatabaseRole => {
7448 write!(f, "DATABASE ROLE ")?;
7449 }
7450 GranteesType::Application => {
7451 write!(f, "APPLICATION ")?;
7452 }
7453 GranteesType::ApplicationRole => {
7454 write!(f, "APPLICATION ROLE ")?;
7455 }
7456 GranteesType::None => (),
7457 }
7458 if let Some(ref name) = self.name {
7459 name.fmt(f)?;
7460 }
7461 Ok(())
7462 }
7463}
7464
7465#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7466#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7467#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7468pub enum GranteesType {
7470 Role,
7472 Share,
7474 User,
7476 Group,
7478 Public,
7480 DatabaseRole,
7482 Application,
7484 ApplicationRole,
7486 None,
7488}
7489
7490#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7492#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7493#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7494pub enum GranteeName {
7495 ObjectName(ObjectName),
7497 UserHost {
7499 user: Ident,
7501 host: Ident,
7503 },
7504}
7505
7506impl fmt::Display for GranteeName {
7507 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7508 match self {
7509 GranteeName::ObjectName(name) => name.fmt(f),
7510 GranteeName::UserHost { user, host } => {
7511 write!(f, "{user}@{host}")
7512 }
7513 }
7514 }
7515}
7516
7517#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7519#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7520#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7521pub enum GrantObjects {
7522 AllSequencesInSchema {
7524 schemas: Vec<ObjectName>,
7526 },
7527 AllTablesInSchema {
7529 schemas: Vec<ObjectName>,
7531 },
7532 AllViewsInSchema {
7534 schemas: Vec<ObjectName>,
7536 },
7537 AllMaterializedViewsInSchema {
7539 schemas: Vec<ObjectName>,
7541 },
7542 AllExternalTablesInSchema {
7544 schemas: Vec<ObjectName>,
7546 },
7547 AllFunctionsInSchema {
7549 schemas: Vec<ObjectName>,
7551 },
7552 FutureSchemasInDatabase {
7554 databases: Vec<ObjectName>,
7556 },
7557 FutureTablesInSchema {
7559 schemas: Vec<ObjectName>,
7561 },
7562 FutureViewsInSchema {
7564 schemas: Vec<ObjectName>,
7566 },
7567 FutureExternalTablesInSchema {
7569 schemas: Vec<ObjectName>,
7571 },
7572 FutureMaterializedViewsInSchema {
7574 schemas: Vec<ObjectName>,
7576 },
7577 FutureSequencesInSchema {
7579 schemas: Vec<ObjectName>,
7581 },
7582 Databases(Vec<ObjectName>),
7584 Schemas(Vec<ObjectName>),
7586 Sequences(Vec<ObjectName>),
7588 Tables(Vec<ObjectName>),
7590 Views(Vec<ObjectName>),
7592 Warehouses(Vec<ObjectName>),
7594 Integrations(Vec<ObjectName>),
7596 ResourceMonitors(Vec<ObjectName>),
7598 Users(Vec<ObjectName>),
7600 ComputePools(Vec<ObjectName>),
7602 Connections(Vec<ObjectName>),
7604 FailoverGroup(Vec<ObjectName>),
7606 ReplicationGroup(Vec<ObjectName>),
7608 ExternalVolumes(Vec<ObjectName>),
7610 Procedure {
7616 name: ObjectName,
7618 arg_types: Vec<DataType>,
7620 },
7621
7622 Function {
7628 name: ObjectName,
7630 arg_types: Vec<DataType>,
7632 },
7633}
7634
7635impl fmt::Display for GrantObjects {
7636 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7637 match self {
7638 GrantObjects::Sequences(sequences) => {
7639 write!(f, "SEQUENCE {}", display_comma_separated(sequences))
7640 }
7641 GrantObjects::Databases(databases) => {
7642 write!(f, "DATABASE {}", display_comma_separated(databases))
7643 }
7644 GrantObjects::Schemas(schemas) => {
7645 write!(f, "SCHEMA {}", display_comma_separated(schemas))
7646 }
7647 GrantObjects::Tables(tables) => {
7648 write!(f, "{}", display_comma_separated(tables))
7649 }
7650 GrantObjects::Views(views) => {
7651 write!(f, "VIEW {}", display_comma_separated(views))
7652 }
7653 GrantObjects::Warehouses(warehouses) => {
7654 write!(f, "WAREHOUSE {}", display_comma_separated(warehouses))
7655 }
7656 GrantObjects::Integrations(integrations) => {
7657 write!(f, "INTEGRATION {}", display_comma_separated(integrations))
7658 }
7659 GrantObjects::AllSequencesInSchema { schemas } => {
7660 write!(
7661 f,
7662 "ALL SEQUENCES IN SCHEMA {}",
7663 display_comma_separated(schemas)
7664 )
7665 }
7666 GrantObjects::AllTablesInSchema { schemas } => {
7667 write!(
7668 f,
7669 "ALL TABLES IN SCHEMA {}",
7670 display_comma_separated(schemas)
7671 )
7672 }
7673 GrantObjects::AllExternalTablesInSchema { schemas } => {
7674 write!(
7675 f,
7676 "ALL EXTERNAL TABLES IN SCHEMA {}",
7677 display_comma_separated(schemas)
7678 )
7679 }
7680 GrantObjects::AllViewsInSchema { schemas } => {
7681 write!(
7682 f,
7683 "ALL VIEWS IN SCHEMA {}",
7684 display_comma_separated(schemas)
7685 )
7686 }
7687 GrantObjects::AllMaterializedViewsInSchema { schemas } => {
7688 write!(
7689 f,
7690 "ALL MATERIALIZED VIEWS IN SCHEMA {}",
7691 display_comma_separated(schemas)
7692 )
7693 }
7694 GrantObjects::AllFunctionsInSchema { schemas } => {
7695 write!(
7696 f,
7697 "ALL FUNCTIONS IN SCHEMA {}",
7698 display_comma_separated(schemas)
7699 )
7700 }
7701 GrantObjects::FutureSchemasInDatabase { databases } => {
7702 write!(
7703 f,
7704 "FUTURE SCHEMAS IN DATABASE {}",
7705 display_comma_separated(databases)
7706 )
7707 }
7708 GrantObjects::FutureTablesInSchema { schemas } => {
7709 write!(
7710 f,
7711 "FUTURE TABLES IN SCHEMA {}",
7712 display_comma_separated(schemas)
7713 )
7714 }
7715 GrantObjects::FutureExternalTablesInSchema { schemas } => {
7716 write!(
7717 f,
7718 "FUTURE EXTERNAL TABLES IN SCHEMA {}",
7719 display_comma_separated(schemas)
7720 )
7721 }
7722 GrantObjects::FutureViewsInSchema { schemas } => {
7723 write!(
7724 f,
7725 "FUTURE VIEWS IN SCHEMA {}",
7726 display_comma_separated(schemas)
7727 )
7728 }
7729 GrantObjects::FutureMaterializedViewsInSchema { schemas } => {
7730 write!(
7731 f,
7732 "FUTURE MATERIALIZED VIEWS IN SCHEMA {}",
7733 display_comma_separated(schemas)
7734 )
7735 }
7736 GrantObjects::FutureSequencesInSchema { schemas } => {
7737 write!(
7738 f,
7739 "FUTURE SEQUENCES IN SCHEMA {}",
7740 display_comma_separated(schemas)
7741 )
7742 }
7743 GrantObjects::ResourceMonitors(objects) => {
7744 write!(f, "RESOURCE MONITOR {}", display_comma_separated(objects))
7745 }
7746 GrantObjects::Users(objects) => {
7747 write!(f, "USER {}", display_comma_separated(objects))
7748 }
7749 GrantObjects::ComputePools(objects) => {
7750 write!(f, "COMPUTE POOL {}", display_comma_separated(objects))
7751 }
7752 GrantObjects::Connections(objects) => {
7753 write!(f, "CONNECTION {}", display_comma_separated(objects))
7754 }
7755 GrantObjects::FailoverGroup(objects) => {
7756 write!(f, "FAILOVER GROUP {}", display_comma_separated(objects))
7757 }
7758 GrantObjects::ReplicationGroup(objects) => {
7759 write!(f, "REPLICATION GROUP {}", display_comma_separated(objects))
7760 }
7761 GrantObjects::ExternalVolumes(objects) => {
7762 write!(f, "EXTERNAL VOLUME {}", display_comma_separated(objects))
7763 }
7764 GrantObjects::Procedure { name, arg_types } => {
7765 write!(f, "PROCEDURE {name}")?;
7766 if !arg_types.is_empty() {
7767 write!(f, "({})", display_comma_separated(arg_types))?;
7768 }
7769 Ok(())
7770 }
7771 GrantObjects::Function { name, arg_types } => {
7772 write!(f, "FUNCTION {name}")?;
7773 if !arg_types.is_empty() {
7774 write!(f, "({})", display_comma_separated(arg_types))?;
7775 }
7776 Ok(())
7777 }
7778 }
7779 }
7780}
7781
7782#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7786#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7787#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7788pub struct DenyStatement {
7789 pub privileges: Privileges,
7791 pub objects: GrantObjects,
7793 pub grantees: Vec<Grantee>,
7795 pub granted_by: Option<Ident>,
7797 pub cascade: Option<CascadeOption>,
7799}
7800
7801impl fmt::Display for DenyStatement {
7802 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7803 write!(f, "DENY {}", self.privileges)?;
7804 write!(f, " ON {}", self.objects)?;
7805 if !self.grantees.is_empty() {
7806 write!(f, " TO {}", display_comma_separated(&self.grantees))?;
7807 }
7808 if let Some(cascade) = &self.cascade {
7809 write!(f, " {cascade}")?;
7810 }
7811 if let Some(granted_by) = &self.granted_by {
7812 write!(f, " AS {granted_by}")?;
7813 }
7814 Ok(())
7815 }
7816}
7817
7818#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7820#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7821#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7822pub struct Assignment {
7823 pub target: AssignmentTarget,
7825 pub value: Expr,
7827}
7828
7829impl fmt::Display for Assignment {
7830 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7831 write!(f, "{} = {}", self.target, self.value)
7832 }
7833}
7834
7835#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7839#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7840#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7841pub enum AssignmentTarget {
7842 ColumnName(ObjectName),
7844 Tuple(Vec<ObjectName>),
7846}
7847
7848impl fmt::Display for AssignmentTarget {
7849 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7850 match self {
7851 AssignmentTarget::ColumnName(column) => write!(f, "{column}"),
7852 AssignmentTarget::Tuple(columns) => write!(f, "({})", display_comma_separated(columns)),
7853 }
7854 }
7855}
7856
7857#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7858#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7859#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7860pub enum FunctionArgExpr {
7862 Expr(Expr),
7864 QualifiedWildcard(ObjectName),
7866 Wildcard,
7868 WildcardWithOptions(WildcardAdditionalOptions),
7872}
7873
7874impl From<Expr> for FunctionArgExpr {
7875 fn from(wildcard_expr: Expr) -> Self {
7876 match wildcard_expr {
7877 Expr::QualifiedWildcard(prefix, _) => Self::QualifiedWildcard(prefix),
7878 Expr::Wildcard(_) => Self::Wildcard,
7879 expr => Self::Expr(expr),
7880 }
7881 }
7882}
7883
7884impl fmt::Display for FunctionArgExpr {
7885 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7886 match self {
7887 FunctionArgExpr::Expr(expr) => write!(f, "{expr}"),
7888 FunctionArgExpr::QualifiedWildcard(prefix) => write!(f, "{prefix}.*"),
7889 FunctionArgExpr::Wildcard => f.write_str("*"),
7890 FunctionArgExpr::WildcardWithOptions(opts) => write!(f, "*{opts}"),
7891 }
7892 }
7893}
7894
7895#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7896#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7897#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7898pub enum FunctionArgOperator {
7900 Equals,
7902 RightArrow,
7904 Assignment,
7906 Colon,
7908 Value,
7910}
7911
7912impl fmt::Display for FunctionArgOperator {
7913 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7914 match self {
7915 FunctionArgOperator::Equals => f.write_str("="),
7916 FunctionArgOperator::RightArrow => f.write_str("=>"),
7917 FunctionArgOperator::Assignment => f.write_str(":="),
7918 FunctionArgOperator::Colon => f.write_str(":"),
7919 FunctionArgOperator::Value => f.write_str("VALUE"),
7920 }
7921 }
7922}
7923
7924#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7925#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7926#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7927pub enum FunctionArg {
7929 Named {
7933 name: Ident,
7935 arg: FunctionArgExpr,
7937 operator: FunctionArgOperator,
7939 },
7940 ExprNamed {
7944 name: Expr,
7946 arg: FunctionArgExpr,
7948 operator: FunctionArgOperator,
7950 },
7951 Unnamed(FunctionArgExpr),
7953}
7954
7955impl fmt::Display for FunctionArg {
7956 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7957 match self {
7958 FunctionArg::Named {
7959 name,
7960 arg,
7961 operator,
7962 } => write!(f, "{name} {operator} {arg}"),
7963 FunctionArg::ExprNamed {
7964 name,
7965 arg,
7966 operator,
7967 } => write!(f, "{name} {operator} {arg}"),
7968 FunctionArg::Unnamed(unnamed_arg) => write!(f, "{unnamed_arg}"),
7969 }
7970 }
7971}
7972
7973#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7974#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7975#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7976pub enum CloseCursor {
7978 All,
7980 Specific {
7982 name: Ident,
7984 },
7985}
7986
7987impl fmt::Display for CloseCursor {
7988 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7989 match self {
7990 CloseCursor::All => write!(f, "ALL"),
7991 CloseCursor::Specific { name } => write!(f, "{name}"),
7992 }
7993 }
7994}
7995
7996#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7998#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7999#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8000pub struct DropDomain {
8001 pub if_exists: bool,
8003 pub name: ObjectName,
8005 pub drop_behavior: Option<DropBehavior>,
8007}
8008
8009#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8013#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8014#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8015pub struct TypedString {
8016 pub data_type: DataType,
8018 pub value: ValueWithSpan,
8021 pub uses_odbc_syntax: bool,
8032}
8033
8034impl fmt::Display for TypedString {
8035 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8036 let data_type = &self.data_type;
8037 let value = &self.value;
8038 match self.uses_odbc_syntax {
8039 false => {
8040 write!(f, "{data_type}")?;
8041 write!(f, " {value}")
8042 }
8043 true => {
8044 let prefix = match data_type {
8045 DataType::Date => "d",
8046 DataType::Time(..) => "t",
8047 DataType::Timestamp(..) => "ts",
8048 _ => "?",
8049 };
8050 write!(f, "{{{prefix} {value}}}")
8051 }
8052 }
8053 }
8054}
8055
8056#[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 Function {
8061 pub name: ObjectName,
8063 pub uses_odbc_syntax: bool,
8072 pub parameters: FunctionArguments,
8082 pub args: FunctionArguments,
8085 pub filter: Option<Box<Expr>>,
8087 pub null_treatment: Option<NullTreatment>,
8096 pub over: Option<WindowType>,
8098 pub within_group: Vec<OrderByExpr>,
8106}
8107
8108impl fmt::Display for Function {
8109 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8110 if self.uses_odbc_syntax {
8111 write!(f, "{{fn ")?;
8112 }
8113
8114 write!(f, "{}{}{}", self.name, self.parameters, self.args)?;
8115
8116 if !self.within_group.is_empty() {
8117 write!(
8118 f,
8119 " WITHIN GROUP (ORDER BY {})",
8120 display_comma_separated(&self.within_group)
8121 )?;
8122 }
8123
8124 if let Some(filter_cond) = &self.filter {
8125 write!(f, " FILTER (WHERE {filter_cond})")?;
8126 }
8127
8128 if let Some(null_treatment) = &self.null_treatment {
8129 write!(f, " {null_treatment}")?;
8130 }
8131
8132 if let Some(o) = &self.over {
8133 f.write_str(" OVER ")?;
8134 o.fmt(f)?;
8135 }
8136
8137 if self.uses_odbc_syntax {
8138 write!(f, "}}")?;
8139 }
8140
8141 Ok(())
8142 }
8143}
8144
8145#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8147#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8148#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8149pub enum FunctionArguments {
8150 None,
8153 Subquery(Box<Query>),
8156 List(FunctionArgumentList),
8159}
8160
8161impl fmt::Display for FunctionArguments {
8162 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8163 match self {
8164 FunctionArguments::None => Ok(()),
8165 FunctionArguments::Subquery(query) => write!(f, "({query})"),
8166 FunctionArguments::List(args) => write!(f, "({args})"),
8167 }
8168 }
8169}
8170
8171#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8173#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8174#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8175pub struct FunctionArgumentList {
8176 pub duplicate_treatment: Option<DuplicateTreatment>,
8178 pub args: Vec<FunctionArg>,
8180 pub clauses: Vec<FunctionArgumentClause>,
8182}
8183
8184impl fmt::Display for FunctionArgumentList {
8185 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8186 if let Some(duplicate_treatment) = self.duplicate_treatment {
8187 write!(f, "{duplicate_treatment} ")?;
8188 }
8189 write!(f, "{}", display_comma_separated(&self.args))?;
8190 if !self.clauses.is_empty() {
8191 if !self.args.is_empty() {
8192 write!(f, " ")?;
8193 }
8194 write!(f, "{}", display_separated(&self.clauses, " "))?;
8195 }
8196 Ok(())
8197 }
8198}
8199
8200#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8201#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8202#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8203pub enum FunctionArgumentClause {
8205 IgnoreOrRespectNulls(NullTreatment),
8214 OrderBy(Vec<OrderByExpr>),
8218 Limit(Expr),
8220 OnOverflow(ListAggOnOverflow),
8224 Having(HavingBound),
8233 Separator(ValueWithSpan),
8237 JsonNullClause(JsonNullClause),
8243 JsonReturningClause(JsonReturningClause),
8247}
8248
8249impl fmt::Display for FunctionArgumentClause {
8250 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8251 match self {
8252 FunctionArgumentClause::IgnoreOrRespectNulls(null_treatment) => {
8253 write!(f, "{null_treatment}")
8254 }
8255 FunctionArgumentClause::OrderBy(order_by) => {
8256 write!(f, "ORDER BY {}", display_comma_separated(order_by))
8257 }
8258 FunctionArgumentClause::Limit(limit) => write!(f, "LIMIT {limit}"),
8259 FunctionArgumentClause::OnOverflow(on_overflow) => write!(f, "{on_overflow}"),
8260 FunctionArgumentClause::Having(bound) => write!(f, "{bound}"),
8261 FunctionArgumentClause::Separator(sep) => write!(f, "SEPARATOR {sep}"),
8262 FunctionArgumentClause::JsonNullClause(null_clause) => write!(f, "{null_clause}"),
8263 FunctionArgumentClause::JsonReturningClause(returning_clause) => {
8264 write!(f, "{returning_clause}")
8265 }
8266 }
8267 }
8268}
8269
8270#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8272#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8273#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8274pub struct Method {
8275 pub expr: Box<Expr>,
8277 pub method_chain: Vec<Function>,
8280}
8281
8282impl fmt::Display for Method {
8283 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8284 write!(
8285 f,
8286 "{}.{}",
8287 self.expr,
8288 display_separated(&self.method_chain, ".")
8289 )
8290 }
8291}
8292
8293#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8294#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8295#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8296pub enum DuplicateTreatment {
8298 Distinct,
8300 All,
8302}
8303
8304impl fmt::Display for DuplicateTreatment {
8305 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8306 match self {
8307 DuplicateTreatment::Distinct => write!(f, "DISTINCT"),
8308 DuplicateTreatment::All => write!(f, "ALL"),
8309 }
8310 }
8311}
8312
8313#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8314#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8315#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8316pub enum AnalyzeFormatKind {
8318 Keyword(AnalyzeFormat),
8320 Assignment(AnalyzeFormat),
8322}
8323
8324impl fmt::Display for AnalyzeFormatKind {
8325 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8326 match self {
8327 AnalyzeFormatKind::Keyword(format) => write!(f, "FORMAT {format}"),
8328 AnalyzeFormatKind::Assignment(format) => write!(f, "FORMAT={format}"),
8329 }
8330 }
8331}
8332
8333#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8334#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8335#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8336pub enum AnalyzeFormat {
8338 TEXT,
8340 GRAPHVIZ,
8342 JSON,
8344 TRADITIONAL,
8346 TREE,
8348}
8349
8350impl fmt::Display for AnalyzeFormat {
8351 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8352 f.write_str(match self {
8353 AnalyzeFormat::TEXT => "TEXT",
8354 AnalyzeFormat::GRAPHVIZ => "GRAPHVIZ",
8355 AnalyzeFormat::JSON => "JSON",
8356 AnalyzeFormat::TRADITIONAL => "TRADITIONAL",
8357 AnalyzeFormat::TREE => "TREE",
8358 })
8359 }
8360}
8361
8362#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8364#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8365#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8366pub enum FileFormat {
8367 TEXTFILE,
8369 SEQUENCEFILE,
8371 ORC,
8373 PARQUET,
8375 AVRO,
8377 RCFILE,
8379 JSONFILE,
8381}
8382
8383impl fmt::Display for FileFormat {
8384 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8385 use self::FileFormat::*;
8386 f.write_str(match self {
8387 TEXTFILE => "TEXTFILE",
8388 SEQUENCEFILE => "SEQUENCEFILE",
8389 ORC => "ORC",
8390 PARQUET => "PARQUET",
8391 AVRO => "AVRO",
8392 RCFILE => "RCFILE",
8393 JSONFILE => "JSONFILE",
8394 })
8395 }
8396}
8397
8398#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8400#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8401#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8402pub enum ListAggOnOverflow {
8403 Error,
8405
8406 Truncate {
8408 filler: Option<Box<Expr>>,
8410 with_count: bool,
8412 },
8413}
8414
8415impl fmt::Display for ListAggOnOverflow {
8416 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8417 write!(f, "ON OVERFLOW")?;
8418 match self {
8419 ListAggOnOverflow::Error => write!(f, " ERROR"),
8420 ListAggOnOverflow::Truncate { filler, with_count } => {
8421 write!(f, " TRUNCATE")?;
8422 if let Some(filler) = filler {
8423 write!(f, " {filler}")?;
8424 }
8425 if *with_count {
8426 write!(f, " WITH")?;
8427 } else {
8428 write!(f, " WITHOUT")?;
8429 }
8430 write!(f, " COUNT")
8431 }
8432 }
8433 }
8434}
8435
8436#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8438#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8439#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8440pub struct HavingBound(pub HavingBoundKind, pub Expr);
8441
8442impl fmt::Display for HavingBound {
8443 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8444 write!(f, "HAVING {} {}", self.0, self.1)
8445 }
8446}
8447
8448#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8449#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8450#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8451pub enum HavingBoundKind {
8453 Min,
8455 Max,
8457}
8458
8459impl fmt::Display for HavingBoundKind {
8460 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8461 match self {
8462 HavingBoundKind::Min => write!(f, "MIN"),
8463 HavingBoundKind::Max => write!(f, "MAX"),
8464 }
8465 }
8466}
8467
8468#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8469#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8470#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8471pub enum ObjectType {
8473 Collation,
8475 Table,
8477 View,
8479 MaterializedView,
8481 Index,
8483 Schema,
8485 Database,
8487 Role,
8489 Sequence,
8491 Stage,
8493 Type,
8495 User,
8497 Stream,
8499}
8500
8501impl fmt::Display for ObjectType {
8502 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8503 f.write_str(match self {
8504 ObjectType::Collation => "COLLATION",
8505 ObjectType::Table => "TABLE",
8506 ObjectType::View => "VIEW",
8507 ObjectType::MaterializedView => "MATERIALIZED VIEW",
8508 ObjectType::Index => "INDEX",
8509 ObjectType::Schema => "SCHEMA",
8510 ObjectType::Database => "DATABASE",
8511 ObjectType::Role => "ROLE",
8512 ObjectType::Sequence => "SEQUENCE",
8513 ObjectType::Stage => "STAGE",
8514 ObjectType::Type => "TYPE",
8515 ObjectType::User => "USER",
8516 ObjectType::Stream => "STREAM",
8517 })
8518 }
8519}
8520
8521#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8522#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8523#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8524pub enum KillType {
8526 Connection,
8528 Query,
8530 Mutation,
8532}
8533
8534impl fmt::Display for KillType {
8535 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8536 f.write_str(match self {
8537 KillType::Connection => "CONNECTION",
8539 KillType::Query => "QUERY",
8540 KillType::Mutation => "MUTATION",
8542 })
8543 }
8544}
8545
8546#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8547#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8548#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8549pub enum HiveDistributionStyle {
8551 PARTITIONED {
8553 columns: Vec<ColumnDef>,
8555 },
8556 SKEWED {
8558 columns: Vec<ColumnDef>,
8560 on: Vec<ColumnDef>,
8562 stored_as_directories: bool,
8564 },
8565 NONE,
8567}
8568
8569#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8570#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8571#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8572pub enum HiveRowFormat {
8574 SERDE {
8576 class: String,
8578 },
8579 DELIMITED {
8581 delimiters: Vec<HiveRowDelimiter>,
8583 },
8584}
8585
8586#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8587#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8588#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8589pub struct HiveLoadDataFormat {
8591 pub serde: Expr,
8593 pub input_format: Expr,
8595}
8596
8597#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8598#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8599#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8600pub struct HiveRowDelimiter {
8602 pub delimiter: HiveDelimiter,
8604 pub char: Ident,
8606}
8607
8608impl fmt::Display for HiveRowDelimiter {
8609 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8610 write!(f, "{} ", self.delimiter)?;
8611 write!(f, "{}", self.char)
8612 }
8613}
8614
8615#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8616#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8617#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8618pub enum HiveDelimiter {
8620 FieldsTerminatedBy,
8622 FieldsEscapedBy,
8624 CollectionItemsTerminatedBy,
8626 MapKeysTerminatedBy,
8628 LinesTerminatedBy,
8630 NullDefinedAs,
8632}
8633
8634impl fmt::Display for HiveDelimiter {
8635 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8636 use HiveDelimiter::*;
8637 f.write_str(match self {
8638 FieldsTerminatedBy => "FIELDS TERMINATED BY",
8639 FieldsEscapedBy => "ESCAPED BY",
8640 CollectionItemsTerminatedBy => "COLLECTION ITEMS TERMINATED BY",
8641 MapKeysTerminatedBy => "MAP KEYS TERMINATED BY",
8642 LinesTerminatedBy => "LINES TERMINATED BY",
8643 NullDefinedAs => "NULL DEFINED AS",
8644 })
8645 }
8646}
8647
8648#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8649#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8650#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8651pub enum HiveDescribeFormat {
8653 Extended,
8655 Formatted,
8657}
8658
8659impl fmt::Display for HiveDescribeFormat {
8660 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8661 use HiveDescribeFormat::*;
8662 f.write_str(match self {
8663 Extended => "EXTENDED",
8664 Formatted => "FORMATTED",
8665 })
8666 }
8667}
8668
8669#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8670#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8671#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8672pub enum DescribeAlias {
8674 Describe,
8676 Explain,
8678 Desc,
8680}
8681
8682impl fmt::Display for DescribeAlias {
8683 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8684 use DescribeAlias::*;
8685 f.write_str(match self {
8686 Describe => "DESCRIBE",
8687 Explain => "EXPLAIN",
8688 Desc => "DESC",
8689 })
8690 }
8691}
8692
8693#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8694#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8695#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8696#[allow(clippy::large_enum_variant)]
8697pub enum HiveIOFormat {
8699 IOF {
8701 input_format: Expr,
8703 output_format: Expr,
8705 },
8706 FileFormat {
8708 format: FileFormat,
8710 },
8711}
8712
8713#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
8714#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8715#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8716pub struct HiveFormat {
8718 pub row_format: Option<HiveRowFormat>,
8720 pub serde_properties: Option<Vec<SqlOption>>,
8722 pub storage: Option<HiveIOFormat>,
8724 pub location: Option<String>,
8726}
8727
8728#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8729#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8730#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8731pub struct ClusteredIndex {
8733 pub name: Ident,
8735 pub asc: Option<bool>,
8737}
8738
8739impl fmt::Display for ClusteredIndex {
8740 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8741 write!(f, "{}", self.name)?;
8742 match self.asc {
8743 Some(true) => write!(f, " ASC"),
8744 Some(false) => write!(f, " DESC"),
8745 _ => Ok(()),
8746 }
8747 }
8748}
8749
8750#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8751#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8752#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8753pub enum TableOptionsClustered {
8755 ColumnstoreIndex,
8757 ColumnstoreIndexOrder(Vec<Ident>),
8759 Index(Vec<ClusteredIndex>),
8761}
8762
8763impl fmt::Display for TableOptionsClustered {
8764 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8765 match self {
8766 TableOptionsClustered::ColumnstoreIndex => {
8767 write!(f, "CLUSTERED COLUMNSTORE INDEX")
8768 }
8769 TableOptionsClustered::ColumnstoreIndexOrder(values) => {
8770 write!(
8771 f,
8772 "CLUSTERED COLUMNSTORE INDEX ORDER ({})",
8773 display_comma_separated(values)
8774 )
8775 }
8776 TableOptionsClustered::Index(values) => {
8777 write!(f, "CLUSTERED INDEX ({})", display_comma_separated(values))
8778 }
8779 }
8780 }
8781}
8782
8783#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
8785#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8786#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8787pub enum PartitionRangeDirection {
8788 Left,
8790 Right,
8792}
8793
8794#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8795#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8796#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8797pub enum SqlOption {
8799 Clustered(TableOptionsClustered),
8803 Ident(Ident),
8807 KeyValue {
8811 key: Ident,
8813 value: Expr,
8815 },
8816 Partition {
8823 column_name: Ident,
8825 range_direction: Option<PartitionRangeDirection>,
8827 for_values: Vec<Expr>,
8829 },
8830 Comment(CommentDef),
8832 TableSpace(TablespaceOption),
8835 NamedParenthesizedList(NamedParenthesizedList),
8842}
8843
8844impl fmt::Display for SqlOption {
8845 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8846 match self {
8847 SqlOption::Clustered(c) => write!(f, "{c}"),
8848 SqlOption::Ident(ident) => {
8849 write!(f, "{ident}")
8850 }
8851 SqlOption::KeyValue { key: name, value } => {
8852 write!(f, "{name} = {value}")
8853 }
8854 SqlOption::Partition {
8855 column_name,
8856 range_direction,
8857 for_values,
8858 } => {
8859 let direction = match range_direction {
8860 Some(PartitionRangeDirection::Left) => " LEFT",
8861 Some(PartitionRangeDirection::Right) => " RIGHT",
8862 None => "",
8863 };
8864
8865 write!(
8866 f,
8867 "PARTITION ({} RANGE{} FOR VALUES ({}))",
8868 column_name,
8869 direction,
8870 display_comma_separated(for_values)
8871 )
8872 }
8873 SqlOption::TableSpace(tablespace_option) => {
8874 write!(f, "TABLESPACE {}", tablespace_option.name)?;
8875 match tablespace_option.storage {
8876 Some(StorageType::Disk) => write!(f, " STORAGE DISK"),
8877 Some(StorageType::Memory) => write!(f, " STORAGE MEMORY"),
8878 None => Ok(()),
8879 }
8880 }
8881 SqlOption::Comment(comment) => match comment {
8882 CommentDef::WithEq(comment) => {
8883 write!(f, "COMMENT = '{comment}'")
8884 }
8885 CommentDef::WithoutEq(comment) => {
8886 write!(f, "COMMENT '{comment}'")
8887 }
8888 },
8889 SqlOption::NamedParenthesizedList(value) => {
8890 write!(f, "{} = ", value.key)?;
8891 if let Some(key) = &value.name {
8892 write!(f, "{key}")?;
8893 }
8894 if !value.values.is_empty() {
8895 write!(f, "({})", display_comma_separated(&value.values))?
8896 }
8897 Ok(())
8898 }
8899 }
8900 }
8901}
8902
8903#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
8904#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8905#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8906pub enum StorageType {
8908 Disk,
8910 Memory,
8912}
8913
8914#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
8915#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8916#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8917pub struct TablespaceOption {
8920 pub name: String,
8922 pub storage: Option<StorageType>,
8924}
8925
8926#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8927#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8928#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8929pub struct SecretOption {
8931 pub key: Ident,
8933 pub value: Ident,
8935}
8936
8937impl fmt::Display for SecretOption {
8938 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8939 write!(f, "{} {}", self.key, self.value)
8940 }
8941}
8942
8943#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8947#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8948#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8949pub struct CreateServerStatement {
8950 pub name: ObjectName,
8952 pub if_not_exists: bool,
8954 pub server_type: Option<Ident>,
8956 pub version: Option<Ident>,
8958 pub foreign_data_wrapper: ObjectName,
8960 pub options: Option<Vec<CreateServerOption>>,
8962}
8963
8964impl fmt::Display for CreateServerStatement {
8965 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8966 let CreateServerStatement {
8967 name,
8968 if_not_exists,
8969 server_type,
8970 version,
8971 foreign_data_wrapper,
8972 options,
8973 } = self;
8974
8975 write!(
8976 f,
8977 "CREATE SERVER {if_not_exists}{name} ",
8978 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
8979 )?;
8980
8981 if let Some(st) = server_type {
8982 write!(f, "TYPE {st} ")?;
8983 }
8984
8985 if let Some(v) = version {
8986 write!(f, "VERSION {v} ")?;
8987 }
8988
8989 write!(f, "FOREIGN DATA WRAPPER {foreign_data_wrapper}")?;
8990
8991 if let Some(o) = options {
8992 write!(f, " OPTIONS ({o})", o = display_comma_separated(o))?;
8993 }
8994
8995 Ok(())
8996 }
8997}
8998
8999#[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 CreateServerOption {
9004 pub key: Ident,
9006 pub value: Ident,
9008}
9009
9010impl fmt::Display for CreateServerOption {
9011 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9012 write!(f, "{} {}", self.key, self.value)
9013 }
9014}
9015
9016#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9017#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9018#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9019pub enum AttachDuckDBDatabaseOption {
9021 ReadOnly(Option<bool>),
9023 Type(Ident),
9025}
9026
9027impl fmt::Display for AttachDuckDBDatabaseOption {
9028 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9029 match self {
9030 AttachDuckDBDatabaseOption::ReadOnly(Some(true)) => write!(f, "READ_ONLY true"),
9031 AttachDuckDBDatabaseOption::ReadOnly(Some(false)) => write!(f, "READ_ONLY false"),
9032 AttachDuckDBDatabaseOption::ReadOnly(None) => write!(f, "READ_ONLY"),
9033 AttachDuckDBDatabaseOption::Type(t) => write!(f, "TYPE {t}"),
9034 }
9035 }
9036}
9037
9038#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9039#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9040#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9041pub enum TransactionMode {
9043 AccessMode(TransactionAccessMode),
9045 IsolationLevel(TransactionIsolationLevel),
9047}
9048
9049impl fmt::Display for TransactionMode {
9050 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9051 use TransactionMode::*;
9052 match self {
9053 AccessMode(access_mode) => write!(f, "{access_mode}"),
9054 IsolationLevel(iso_level) => write!(f, "ISOLATION LEVEL {iso_level}"),
9055 }
9056 }
9057}
9058
9059#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9060#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9061#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9062pub enum TransactionAccessMode {
9064 ReadOnly,
9066 ReadWrite,
9068}
9069
9070impl fmt::Display for TransactionAccessMode {
9071 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9072 use TransactionAccessMode::*;
9073 f.write_str(match self {
9074 ReadOnly => "READ ONLY",
9075 ReadWrite => "READ WRITE",
9076 })
9077 }
9078}
9079
9080#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9081#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9082#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9083pub enum TransactionIsolationLevel {
9085 ReadUncommitted,
9087 ReadCommitted,
9089 RepeatableRead,
9091 Serializable,
9093 Snapshot,
9095}
9096
9097impl fmt::Display for TransactionIsolationLevel {
9098 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9099 use TransactionIsolationLevel::*;
9100 f.write_str(match self {
9101 ReadUncommitted => "READ UNCOMMITTED",
9102 ReadCommitted => "READ COMMITTED",
9103 RepeatableRead => "REPEATABLE READ",
9104 Serializable => "SERIALIZABLE",
9105 Snapshot => "SNAPSHOT",
9106 })
9107 }
9108}
9109
9110#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9115#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9116#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9117pub enum TransactionModifier {
9118 Deferred,
9120 Immediate,
9122 Exclusive,
9124 Try,
9126 Catch,
9128}
9129
9130impl fmt::Display for TransactionModifier {
9131 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9132 use TransactionModifier::*;
9133 f.write_str(match self {
9134 Deferred => "DEFERRED",
9135 Immediate => "IMMEDIATE",
9136 Exclusive => "EXCLUSIVE",
9137 Try => "TRY",
9138 Catch => "CATCH",
9139 })
9140 }
9141}
9142
9143#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9144#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9145#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9146pub enum ShowStatementFilter {
9148 Like(String),
9150 ILike(String),
9152 Where(Expr),
9154 NoKeyword(String),
9156}
9157
9158impl fmt::Display for ShowStatementFilter {
9159 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9160 use ShowStatementFilter::*;
9161 match self {
9162 Like(pattern) => write!(f, "LIKE '{}'", value::escape_single_quote_string(pattern)),
9163 ILike(pattern) => write!(f, "ILIKE {}", value::escape_single_quote_string(pattern)),
9164 Where(expr) => write!(f, "WHERE {expr}"),
9165 NoKeyword(pattern) => write!(f, "'{}'", value::escape_single_quote_string(pattern)),
9166 }
9167 }
9168}
9169
9170#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9171#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9172#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9173pub enum ShowStatementInClause {
9175 IN,
9177 FROM,
9179}
9180
9181impl fmt::Display for ShowStatementInClause {
9182 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9183 use ShowStatementInClause::*;
9184 match self {
9185 FROM => write!(f, "FROM"),
9186 IN => write!(f, "IN"),
9187 }
9188 }
9189}
9190
9191#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9196#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9197#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9198pub enum SqliteOnConflict {
9199 Rollback,
9201 Abort,
9203 Fail,
9205 Ignore,
9207 Replace,
9209}
9210
9211impl fmt::Display for SqliteOnConflict {
9212 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9213 use SqliteOnConflict::*;
9214 match self {
9215 Rollback => write!(f, "OR ROLLBACK"),
9216 Abort => write!(f, "OR ABORT"),
9217 Fail => write!(f, "OR FAIL"),
9218 Ignore => write!(f, "OR IGNORE"),
9219 Replace => write!(f, "OR REPLACE"),
9220 }
9221 }
9222}
9223
9224#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9230#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9231#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9232pub enum MysqlInsertPriority {
9233 LowPriority,
9235 Delayed,
9237 HighPriority,
9239}
9240
9241impl fmt::Display for crate::ast::MysqlInsertPriority {
9242 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9243 use MysqlInsertPriority::*;
9244 match self {
9245 LowPriority => write!(f, "LOW_PRIORITY"),
9246 Delayed => write!(f, "DELAYED"),
9247 HighPriority => write!(f, "HIGH_PRIORITY"),
9248 }
9249 }
9250}
9251
9252#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9253#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9254#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9255pub enum CopySource {
9257 Table {
9259 table_name: ObjectName,
9261 columns: Vec<Ident>,
9264 },
9265 Query(Box<Query>),
9267}
9268
9269#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9270#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9271#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9272pub enum CopyTarget {
9274 Stdin,
9276 Stdout,
9278 File {
9280 filename: String,
9282 },
9283 Program {
9285 command: String,
9287 },
9288}
9289
9290impl fmt::Display for CopyTarget {
9291 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9292 use CopyTarget::*;
9293 match self {
9294 Stdin => write!(f, "STDIN"),
9295 Stdout => write!(f, "STDOUT"),
9296 File { filename } => write!(f, "'{}'", value::escape_single_quote_string(filename)),
9297 Program { command } => write!(
9298 f,
9299 "PROGRAM '{}'",
9300 value::escape_single_quote_string(command)
9301 ),
9302 }
9303 }
9304}
9305
9306#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9307#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9308#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9309pub enum OnCommit {
9311 DeleteRows,
9313 PreserveRows,
9315 Drop,
9317}
9318
9319#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9323#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9324#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9325pub enum CopyOption {
9326 Format(Ident),
9328 Freeze(bool),
9330 Delimiter(char),
9332 Null(String),
9334 Header(bool),
9336 Quote(char),
9338 Escape(char),
9340 ForceQuote(Vec<Ident>),
9342 ForceNotNull(Vec<Ident>),
9344 ForceNull(Vec<Ident>),
9346 Encoding(String),
9348}
9349
9350impl fmt::Display for CopyOption {
9351 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9352 use CopyOption::*;
9353 match self {
9354 Format(name) => write!(f, "FORMAT {name}"),
9355 Freeze(true) => write!(f, "FREEZE"),
9356 Freeze(false) => write!(f, "FREEZE FALSE"),
9357 Delimiter(char) => write!(f, "DELIMITER '{char}'"),
9358 Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)),
9359 Header(true) => write!(f, "HEADER"),
9360 Header(false) => write!(f, "HEADER FALSE"),
9361 Quote(char) => write!(f, "QUOTE '{char}'"),
9362 Escape(char) => write!(f, "ESCAPE '{char}'"),
9363 ForceQuote(columns) => write!(f, "FORCE_QUOTE ({})", display_comma_separated(columns)),
9364 ForceNotNull(columns) => {
9365 write!(f, "FORCE_NOT_NULL ({})", display_comma_separated(columns))
9366 }
9367 ForceNull(columns) => write!(f, "FORCE_NULL ({})", display_comma_separated(columns)),
9368 Encoding(name) => write!(f, "ENCODING '{}'", value::escape_single_quote_string(name)),
9369 }
9370 }
9371}
9372
9373#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9378#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9379#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9380pub enum CopyLegacyOption {
9381 AcceptAnyDate,
9383 AcceptInvChars(Option<String>),
9385 AddQuotes,
9387 AllowOverwrite,
9389 Binary,
9391 BlankAsNull,
9393 Bzip2,
9395 CleanPath,
9397 CompUpdate {
9399 preset: bool,
9401 enabled: Option<bool>,
9403 },
9404 Csv(Vec<CopyLegacyCsvOption>),
9406 DateFormat(Option<String>),
9408 Delimiter(char),
9410 EmptyAsNull,
9412 Encrypted {
9414 auto: bool,
9416 },
9417 Escape,
9419 Extension(String),
9421 FixedWidth(String),
9423 Gzip,
9425 Header,
9427 IamRole(IamRoleKind),
9429 IgnoreHeader(u64),
9431 Json(Option<String>),
9433 Manifest {
9435 verbose: bool,
9437 },
9438 MaxFileSize(FileSize),
9440 Null(String),
9442 Parallel(Option<bool>),
9444 Parquet,
9446 PartitionBy(UnloadPartitionBy),
9448 Region(String),
9450 RemoveQuotes,
9452 RowGroupSize(FileSize),
9454 StatUpdate(Option<bool>),
9456 TimeFormat(Option<String>),
9458 TruncateColumns,
9460 Zstd,
9462 Credentials(String),
9465}
9466
9467impl fmt::Display for CopyLegacyOption {
9468 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9469 use CopyLegacyOption::*;
9470 match self {
9471 AcceptAnyDate => write!(f, "ACCEPTANYDATE"),
9472 AcceptInvChars(ch) => {
9473 write!(f, "ACCEPTINVCHARS")?;
9474 if let Some(ch) = ch {
9475 write!(f, " '{}'", value::escape_single_quote_string(ch))?;
9476 }
9477 Ok(())
9478 }
9479 AddQuotes => write!(f, "ADDQUOTES"),
9480 AllowOverwrite => write!(f, "ALLOWOVERWRITE"),
9481 Binary => write!(f, "BINARY"),
9482 BlankAsNull => write!(f, "BLANKSASNULL"),
9483 Bzip2 => write!(f, "BZIP2"),
9484 CleanPath => write!(f, "CLEANPATH"),
9485 CompUpdate { preset, enabled } => {
9486 write!(f, "COMPUPDATE")?;
9487 if *preset {
9488 write!(f, " PRESET")?;
9489 } else if let Some(enabled) = enabled {
9490 write!(
9491 f,
9492 "{}",
9493 match enabled {
9494 true => " TRUE",
9495 false => " FALSE",
9496 }
9497 )?;
9498 }
9499 Ok(())
9500 }
9501 Csv(opts) => {
9502 write!(f, "CSV")?;
9503 if !opts.is_empty() {
9504 write!(f, " {}", display_separated(opts, " "))?;
9505 }
9506 Ok(())
9507 }
9508 DateFormat(fmt) => {
9509 write!(f, "DATEFORMAT")?;
9510 if let Some(fmt) = fmt {
9511 write!(f, " '{}'", value::escape_single_quote_string(fmt))?;
9512 }
9513 Ok(())
9514 }
9515 Delimiter(char) => write!(f, "DELIMITER '{char}'"),
9516 EmptyAsNull => write!(f, "EMPTYASNULL"),
9517 Encrypted { auto } => write!(f, "ENCRYPTED{}", if *auto { " AUTO" } else { "" }),
9518 Escape => write!(f, "ESCAPE"),
9519 Extension(ext) => write!(f, "EXTENSION '{}'", value::escape_single_quote_string(ext)),
9520 FixedWidth(spec) => write!(
9521 f,
9522 "FIXEDWIDTH '{}'",
9523 value::escape_single_quote_string(spec)
9524 ),
9525 Gzip => write!(f, "GZIP"),
9526 Header => write!(f, "HEADER"),
9527 IamRole(role) => write!(f, "IAM_ROLE {role}"),
9528 IgnoreHeader(num_rows) => write!(f, "IGNOREHEADER {num_rows}"),
9529 Json(opt) => {
9530 write!(f, "JSON")?;
9531 if let Some(opt) = opt {
9532 write!(f, " AS '{}'", value::escape_single_quote_string(opt))?;
9533 }
9534 Ok(())
9535 }
9536 Manifest { verbose } => write!(f, "MANIFEST{}", if *verbose { " VERBOSE" } else { "" }),
9537 MaxFileSize(file_size) => write!(f, "MAXFILESIZE {file_size}"),
9538 Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)),
9539 Parallel(enabled) => {
9540 write!(
9541 f,
9542 "PARALLEL{}",
9543 match enabled {
9544 Some(true) => " TRUE",
9545 Some(false) => " FALSE",
9546 _ => "",
9547 }
9548 )
9549 }
9550 Parquet => write!(f, "PARQUET"),
9551 PartitionBy(p) => write!(f, "{p}"),
9552 Region(region) => write!(f, "REGION '{}'", value::escape_single_quote_string(region)),
9553 RemoveQuotes => write!(f, "REMOVEQUOTES"),
9554 RowGroupSize(file_size) => write!(f, "ROWGROUPSIZE {file_size}"),
9555 StatUpdate(enabled) => {
9556 write!(
9557 f,
9558 "STATUPDATE{}",
9559 match enabled {
9560 Some(true) => " TRUE",
9561 Some(false) => " FALSE",
9562 _ => "",
9563 }
9564 )
9565 }
9566 TimeFormat(fmt) => {
9567 write!(f, "TIMEFORMAT")?;
9568 if let Some(fmt) = fmt {
9569 write!(f, " '{}'", value::escape_single_quote_string(fmt))?;
9570 }
9571 Ok(())
9572 }
9573 TruncateColumns => write!(f, "TRUNCATECOLUMNS"),
9574 Zstd => write!(f, "ZSTD"),
9575 Credentials(s) => write!(f, "CREDENTIALS '{}'", value::escape_single_quote_string(s)),
9576 }
9577 }
9578}
9579
9580#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9584#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9585#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9586pub struct FileSize {
9587 pub size: ValueWithSpan,
9589 pub unit: Option<FileSizeUnit>,
9591}
9592
9593impl fmt::Display for FileSize {
9594 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9595 write!(f, "{}", self.size)?;
9596 if let Some(unit) = &self.unit {
9597 write!(f, " {unit}")?;
9598 }
9599 Ok(())
9600 }
9601}
9602
9603#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9605#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9606#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9607pub enum FileSizeUnit {
9608 MB,
9610 GB,
9612}
9613
9614impl fmt::Display for FileSizeUnit {
9615 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9616 match self {
9617 FileSizeUnit::MB => write!(f, "MB"),
9618 FileSizeUnit::GB => write!(f, "GB"),
9619 }
9620 }
9621}
9622
9623#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9629#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9630#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9631pub struct UnloadPartitionBy {
9632 pub columns: Vec<Ident>,
9634 pub include: bool,
9636}
9637
9638impl fmt::Display for UnloadPartitionBy {
9639 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9640 write!(
9641 f,
9642 "PARTITION BY ({}){}",
9643 display_comma_separated(&self.columns),
9644 if self.include { " INCLUDE" } else { "" }
9645 )
9646 }
9647}
9648
9649#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9653#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9654#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9655pub enum IamRoleKind {
9656 Default,
9658 Arn(String),
9660}
9661
9662impl fmt::Display for IamRoleKind {
9663 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9664 match self {
9665 IamRoleKind::Default => write!(f, "DEFAULT"),
9666 IamRoleKind::Arn(arn) => write!(f, "'{arn}'"),
9667 }
9668 }
9669}
9670
9671#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9675#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9676#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9677pub enum CopyLegacyCsvOption {
9678 Header,
9680 Quote(char),
9682 Escape(char),
9684 ForceQuote(Vec<Ident>),
9686 ForceNotNull(Vec<Ident>),
9688}
9689
9690impl fmt::Display for CopyLegacyCsvOption {
9691 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9692 use CopyLegacyCsvOption::*;
9693 match self {
9694 Header => write!(f, "HEADER"),
9695 Quote(char) => write!(f, "QUOTE '{char}'"),
9696 Escape(char) => write!(f, "ESCAPE '{char}'"),
9697 ForceQuote(columns) => write!(f, "FORCE QUOTE {}", display_comma_separated(columns)),
9698 ForceNotNull(columns) => {
9699 write!(f, "FORCE NOT NULL {}", display_comma_separated(columns))
9700 }
9701 }
9702 }
9703}
9704
9705#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9707#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9708#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9709pub enum DiscardObject {
9710 ALL,
9712 PLANS,
9714 SEQUENCES,
9716 TEMP,
9718}
9719
9720impl fmt::Display for DiscardObject {
9721 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9722 match self {
9723 DiscardObject::ALL => f.write_str("ALL"),
9724 DiscardObject::PLANS => f.write_str("PLANS"),
9725 DiscardObject::SEQUENCES => f.write_str("SEQUENCES"),
9726 DiscardObject::TEMP => f.write_str("TEMP"),
9727 }
9728 }
9729}
9730
9731#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9733#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9734#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9735pub enum FlushType {
9736 BinaryLogs,
9738 EngineLogs,
9740 ErrorLogs,
9742 GeneralLogs,
9744 Hosts,
9746 Logs,
9748 Privileges,
9750 OptimizerCosts,
9752 RelayLogs,
9754 SlowLogs,
9756 Status,
9758 UserResources,
9760 Tables,
9762}
9763
9764impl fmt::Display for FlushType {
9765 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9766 match self {
9767 FlushType::BinaryLogs => f.write_str("BINARY LOGS"),
9768 FlushType::EngineLogs => f.write_str("ENGINE LOGS"),
9769 FlushType::ErrorLogs => f.write_str("ERROR LOGS"),
9770 FlushType::GeneralLogs => f.write_str("GENERAL LOGS"),
9771 FlushType::Hosts => f.write_str("HOSTS"),
9772 FlushType::Logs => f.write_str("LOGS"),
9773 FlushType::Privileges => f.write_str("PRIVILEGES"),
9774 FlushType::OptimizerCosts => f.write_str("OPTIMIZER_COSTS"),
9775 FlushType::RelayLogs => f.write_str("RELAY LOGS"),
9776 FlushType::SlowLogs => f.write_str("SLOW LOGS"),
9777 FlushType::Status => f.write_str("STATUS"),
9778 FlushType::UserResources => f.write_str("USER_RESOURCES"),
9779 FlushType::Tables => f.write_str("TABLES"),
9780 }
9781 }
9782}
9783
9784#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9786#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9787#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9788pub enum FlushLocation {
9789 NoWriteToBinlog,
9791 Local,
9793}
9794
9795impl fmt::Display for FlushLocation {
9796 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9797 match self {
9798 FlushLocation::NoWriteToBinlog => f.write_str("NO_WRITE_TO_BINLOG"),
9799 FlushLocation::Local => f.write_str("LOCAL"),
9800 }
9801 }
9802}
9803
9804#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9806#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9807#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9808pub enum ContextModifier {
9809 Local,
9811 Session,
9813 Global,
9815}
9816
9817impl fmt::Display for ContextModifier {
9818 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9819 match self {
9820 Self::Local => {
9821 write!(f, "LOCAL ")
9822 }
9823 Self::Session => {
9824 write!(f, "SESSION ")
9825 }
9826 Self::Global => {
9827 write!(f, "GLOBAL ")
9828 }
9829 }
9830 }
9831}
9832
9833#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9835#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9836pub enum DropFunctionOption {
9837 Restrict,
9839 Cascade,
9841}
9842
9843impl fmt::Display for DropFunctionOption {
9844 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9845 match self {
9846 DropFunctionOption::Restrict => write!(f, "RESTRICT "),
9847 DropFunctionOption::Cascade => write!(f, "CASCADE "),
9848 }
9849 }
9850}
9851
9852#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9854#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9855#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9856pub struct FunctionDesc {
9857 pub name: ObjectName,
9859 pub args: Option<Vec<OperateFunctionArg>>,
9861}
9862
9863impl fmt::Display for FunctionDesc {
9864 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9865 write!(f, "{}", self.name)?;
9866 if let Some(args) = &self.args {
9867 write!(f, "({})", display_comma_separated(args))?;
9868 }
9869 Ok(())
9870 }
9871}
9872
9873#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9875#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9876#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9877pub struct OperateFunctionArg {
9878 pub mode: Option<ArgMode>,
9880 pub name: Option<Ident>,
9882 pub data_type: DataType,
9884 pub default_expr: Option<Expr>,
9886}
9887
9888impl OperateFunctionArg {
9889 pub fn unnamed(data_type: DataType) -> Self {
9891 Self {
9892 mode: None,
9893 name: None,
9894 data_type,
9895 default_expr: None,
9896 }
9897 }
9898
9899 pub fn with_name(name: &str, data_type: DataType) -> Self {
9901 Self {
9902 mode: None,
9903 name: Some(name.into()),
9904 data_type,
9905 default_expr: None,
9906 }
9907 }
9908}
9909
9910impl fmt::Display for OperateFunctionArg {
9911 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9912 if let Some(mode) = &self.mode {
9913 write!(f, "{mode} ")?;
9914 }
9915 if let Some(name) = &self.name {
9916 write!(f, "{name} ")?;
9917 }
9918 write!(f, "{}", self.data_type)?;
9919 if let Some(default_expr) = &self.default_expr {
9920 write!(f, " = {default_expr}")?;
9921 }
9922 Ok(())
9923 }
9924}
9925
9926#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9928#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9929#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9930pub enum ArgMode {
9931 In,
9933 Out,
9935 InOut,
9937 Variadic,
9939}
9940
9941impl fmt::Display for ArgMode {
9942 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9943 match self {
9944 ArgMode::In => write!(f, "IN"),
9945 ArgMode::Out => write!(f, "OUT"),
9946 ArgMode::InOut => write!(f, "INOUT"),
9947 ArgMode::Variadic => write!(f, "VARIADIC"),
9948 }
9949 }
9950}
9951
9952#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9954#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9955#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9956pub enum FunctionBehavior {
9957 Immutable,
9959 Stable,
9961 Volatile,
9963}
9964
9965impl fmt::Display for FunctionBehavior {
9966 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9967 match self {
9968 FunctionBehavior::Immutable => write!(f, "IMMUTABLE"),
9969 FunctionBehavior::Stable => write!(f, "STABLE"),
9970 FunctionBehavior::Volatile => write!(f, "VOLATILE"),
9971 }
9972 }
9973}
9974
9975#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9979#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9980#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9981pub enum FunctionSecurity {
9982 Definer,
9984 Invoker,
9986}
9987
9988impl fmt::Display for FunctionSecurity {
9989 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9990 match self {
9991 FunctionSecurity::Definer => write!(f, "SECURITY DEFINER"),
9992 FunctionSecurity::Invoker => write!(f, "SECURITY INVOKER"),
9993 }
9994 }
9995}
9996
9997#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10001#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10002#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10003pub enum FunctionSetValue {
10004 Default,
10006 Values(Vec<Expr>),
10008 FromCurrent,
10010}
10011
10012#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10016#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10017#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10018pub struct FunctionDefinitionSetParam {
10019 pub name: ObjectName,
10021 pub value: FunctionSetValue,
10023}
10024
10025impl fmt::Display for FunctionDefinitionSetParam {
10026 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10027 write!(f, "SET {} ", self.name)?;
10028 match &self.value {
10029 FunctionSetValue::Default => write!(f, "= DEFAULT"),
10030 FunctionSetValue::Values(values) => {
10031 write!(f, "= {}", display_comma_separated(values))
10032 }
10033 FunctionSetValue::FromCurrent => write!(f, "FROM CURRENT"),
10034 }
10035 }
10036}
10037
10038#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10040#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10041#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10042pub enum FunctionCalledOnNull {
10043 CalledOnNullInput,
10045 ReturnsNullOnNullInput,
10047 Strict,
10049}
10050
10051impl fmt::Display for FunctionCalledOnNull {
10052 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10053 match self {
10054 FunctionCalledOnNull::CalledOnNullInput => write!(f, "CALLED ON NULL INPUT"),
10055 FunctionCalledOnNull::ReturnsNullOnNullInput => write!(f, "RETURNS NULL ON NULL INPUT"),
10056 FunctionCalledOnNull::Strict => write!(f, "STRICT"),
10057 }
10058 }
10059}
10060
10061#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10063#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10064#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10065pub enum FunctionParallel {
10066 Unsafe,
10068 Restricted,
10070 Safe,
10072}
10073
10074impl fmt::Display for FunctionParallel {
10075 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10076 match self {
10077 FunctionParallel::Unsafe => write!(f, "PARALLEL UNSAFE"),
10078 FunctionParallel::Restricted => write!(f, "PARALLEL RESTRICTED"),
10079 FunctionParallel::Safe => write!(f, "PARALLEL SAFE"),
10080 }
10081 }
10082}
10083
10084#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10088#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10089#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10090pub enum FunctionDeterminismSpecifier {
10091 Deterministic,
10093 NotDeterministic,
10095}
10096
10097impl fmt::Display for FunctionDeterminismSpecifier {
10098 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10099 match self {
10100 FunctionDeterminismSpecifier::Deterministic => {
10101 write!(f, "DETERMINISTIC")
10102 }
10103 FunctionDeterminismSpecifier::NotDeterministic => {
10104 write!(f, "NOT DETERMINISTIC")
10105 }
10106 }
10107 }
10108}
10109
10110#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10117#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10118#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10119pub enum CreateFunctionBody {
10120 AsBeforeOptions {
10133 body: Expr,
10135 link_symbol: Option<Expr>,
10144 },
10145 AsAfterOptions(Expr),
10157 AsBeginEnd(BeginEndStatements),
10173 Return(Expr),
10184
10185 AsReturnExpr(Expr),
10196
10197 AsReturnSelect(Select),
10208}
10209
10210#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10211#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10212#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10213pub enum CreateFunctionUsing {
10215 Jar(String),
10217 File(String),
10219 Archive(String),
10221}
10222
10223impl fmt::Display for CreateFunctionUsing {
10224 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10225 write!(f, "USING ")?;
10226 match self {
10227 CreateFunctionUsing::Jar(uri) => write!(f, "JAR '{uri}'"),
10228 CreateFunctionUsing::File(uri) => write!(f, "FILE '{uri}'"),
10229 CreateFunctionUsing::Archive(uri) => write!(f, "ARCHIVE '{uri}'"),
10230 }
10231 }
10232}
10233
10234#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10239#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10240#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10241pub struct MacroArg {
10242 pub name: Ident,
10244 pub default_expr: Option<Expr>,
10246}
10247
10248impl MacroArg {
10249 pub fn new(name: &str) -> Self {
10251 Self {
10252 name: name.into(),
10253 default_expr: None,
10254 }
10255 }
10256}
10257
10258impl fmt::Display for MacroArg {
10259 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10260 write!(f, "{}", self.name)?;
10261 if let Some(default_expr) = &self.default_expr {
10262 write!(f, " := {default_expr}")?;
10263 }
10264 Ok(())
10265 }
10266}
10267
10268#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10269#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10270#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10271pub enum MacroDefinition {
10273 Expr(Expr),
10275 Table(Box<Query>),
10277}
10278
10279impl fmt::Display for MacroDefinition {
10280 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10281 match self {
10282 MacroDefinition::Expr(expr) => write!(f, "{expr}")?,
10283 MacroDefinition::Table(query) => write!(f, "{query}")?,
10284 }
10285 Ok(())
10286 }
10287}
10288
10289#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10293#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10294#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10295pub enum SchemaName {
10296 Simple(ObjectName),
10298 UnnamedAuthorization(Ident),
10300 NamedAuthorization(ObjectName, Ident),
10302}
10303
10304impl fmt::Display for SchemaName {
10305 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10306 match self {
10307 SchemaName::Simple(name) => {
10308 write!(f, "{name}")
10309 }
10310 SchemaName::UnnamedAuthorization(authorization) => {
10311 write!(f, "AUTHORIZATION {authorization}")
10312 }
10313 SchemaName::NamedAuthorization(name, authorization) => {
10314 write!(f, "{name} AUTHORIZATION {authorization}")
10315 }
10316 }
10317 }
10318}
10319
10320#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10324#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10325#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10326pub enum SearchModifier {
10327 InNaturalLanguageMode,
10329 InNaturalLanguageModeWithQueryExpansion,
10331 InBooleanMode,
10333 WithQueryExpansion,
10335}
10336
10337impl fmt::Display for SearchModifier {
10338 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10339 match self {
10340 Self::InNaturalLanguageMode => {
10341 write!(f, "IN NATURAL LANGUAGE MODE")?;
10342 }
10343 Self::InNaturalLanguageModeWithQueryExpansion => {
10344 write!(f, "IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION")?;
10345 }
10346 Self::InBooleanMode => {
10347 write!(f, "IN BOOLEAN MODE")?;
10348 }
10349 Self::WithQueryExpansion => {
10350 write!(f, "WITH QUERY EXPANSION")?;
10351 }
10352 }
10353
10354 Ok(())
10355 }
10356}
10357
10358#[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 struct LockTable {
10363 pub table: Ident,
10365 pub alias: Option<Ident>,
10367 pub lock_type: LockTableType,
10369}
10370
10371impl fmt::Display for LockTable {
10372 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10373 let Self {
10374 table: tbl_name,
10375 alias,
10376 lock_type,
10377 } = self;
10378
10379 write!(f, "{tbl_name} ")?;
10380 if let Some(alias) = alias {
10381 write!(f, "AS {alias} ")?;
10382 }
10383 write!(f, "{lock_type}")?;
10384 Ok(())
10385 }
10386}
10387
10388#[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 LockTableType {
10393 Read {
10395 local: bool,
10397 },
10398 Write {
10400 low_priority: bool,
10402 },
10403}
10404
10405impl fmt::Display for LockTableType {
10406 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10407 match self {
10408 Self::Read { local } => {
10409 write!(f, "READ")?;
10410 if *local {
10411 write!(f, " LOCAL")?;
10412 }
10413 }
10414 Self::Write { low_priority } => {
10415 if *low_priority {
10416 write!(f, "LOW_PRIORITY ")?;
10417 }
10418 write!(f, "WRITE")?;
10419 }
10420 }
10421
10422 Ok(())
10423 }
10424}
10425
10426#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10427#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10428#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10429pub struct HiveSetLocation {
10431 pub has_set: bool,
10433 pub location: Ident,
10435}
10436
10437impl fmt::Display for HiveSetLocation {
10438 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10439 if self.has_set {
10440 write!(f, "SET ")?;
10441 }
10442 write!(f, "LOCATION {}", self.location)
10443 }
10444}
10445
10446#[allow(clippy::large_enum_variant)]
10448#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10449#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10450#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10451pub enum MySQLColumnPosition {
10453 First,
10455 After(Ident),
10457}
10458
10459impl Display for MySQLColumnPosition {
10460 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10461 match self {
10462 MySQLColumnPosition::First => write!(f, "FIRST"),
10463 MySQLColumnPosition::After(ident) => {
10464 let column_name = &ident.value;
10465 write!(f, "AFTER {column_name}")
10466 }
10467 }
10468 }
10469}
10470
10471#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10473#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10474#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10475pub enum CreateViewAlgorithm {
10477 Undefined,
10479 Merge,
10481 TempTable,
10483}
10484
10485impl Display for CreateViewAlgorithm {
10486 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10487 match self {
10488 CreateViewAlgorithm::Undefined => write!(f, "UNDEFINED"),
10489 CreateViewAlgorithm::Merge => write!(f, "MERGE"),
10490 CreateViewAlgorithm::TempTable => write!(f, "TEMPTABLE"),
10491 }
10492 }
10493}
10494#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10496#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10497#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10498pub enum CreateViewSecurity {
10500 Definer,
10502 Invoker,
10504}
10505
10506impl Display for CreateViewSecurity {
10507 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10508 match self {
10509 CreateViewSecurity::Definer => write!(f, "DEFINER"),
10510 CreateViewSecurity::Invoker => write!(f, "INVOKER"),
10511 }
10512 }
10513}
10514
10515#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10519#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10520#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10521pub struct CreateViewParams {
10522 pub algorithm: Option<CreateViewAlgorithm>,
10524 pub definer: Option<GranteeName>,
10526 pub security: Option<CreateViewSecurity>,
10528}
10529
10530impl Display for CreateViewParams {
10531 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10532 let CreateViewParams {
10533 algorithm,
10534 definer,
10535 security,
10536 } = self;
10537 if let Some(algorithm) = algorithm {
10538 write!(f, "ALGORITHM = {algorithm} ")?;
10539 }
10540 if let Some(definers) = definer {
10541 write!(f, "DEFINER = {definers} ")?;
10542 }
10543 if let Some(security) = security {
10544 write!(f, "SQL SECURITY {security} ")?;
10545 }
10546 Ok(())
10547 }
10548}
10549
10550#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10551#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10552#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10553pub struct NamedParenthesizedList {
10561 pub key: Ident,
10563 pub name: Option<Ident>,
10565 pub values: Vec<Ident>,
10567}
10568
10569#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10574#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10575#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10576pub struct RowAccessPolicy {
10577 pub policy: ObjectName,
10579 pub on: Vec<Ident>,
10581}
10582
10583impl RowAccessPolicy {
10584 pub fn new(policy: ObjectName, on: Vec<Ident>) -> Self {
10586 Self { policy, on }
10587 }
10588}
10589
10590impl Display for RowAccessPolicy {
10591 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10592 write!(
10593 f,
10594 "WITH ROW ACCESS POLICY {} ON ({})",
10595 self.policy,
10596 display_comma_separated(self.on.as_slice())
10597 )
10598 }
10599}
10600
10601#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10605#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10606#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10607pub struct StorageLifecyclePolicy {
10608 pub policy: ObjectName,
10610 pub on: Vec<Ident>,
10612}
10613
10614impl Display for StorageLifecyclePolicy {
10615 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10616 write!(
10617 f,
10618 "WITH STORAGE LIFECYCLE POLICY {} ON ({})",
10619 self.policy,
10620 display_comma_separated(self.on.as_slice())
10621 )
10622 }
10623}
10624
10625#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10629#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10630#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10631pub struct Tag {
10632 pub key: ObjectName,
10634 pub value: String,
10636}
10637
10638impl Tag {
10639 pub fn new(key: ObjectName, value: String) -> Self {
10641 Self { key, value }
10642 }
10643}
10644
10645impl Display for Tag {
10646 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10647 write!(f, "{}='{}'", self.key, self.value)
10648 }
10649}
10650
10651#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10655#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10656#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10657pub struct ContactEntry {
10658 pub purpose: String,
10660 pub contact: String,
10662}
10663
10664impl Display for ContactEntry {
10665 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10666 write!(f, "{} = {}", self.purpose, self.contact)
10667 }
10668}
10669
10670#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10672#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10673#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10674pub enum CommentDef {
10675 WithEq(String),
10678 WithoutEq(String),
10680}
10681
10682impl Display for CommentDef {
10683 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10684 match self {
10685 CommentDef::WithEq(comment) | CommentDef::WithoutEq(comment) => write!(f, "{comment}"),
10686 }
10687 }
10688}
10689
10690#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10705#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10706#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10707pub enum WrappedCollection<T> {
10708 NoWrapping(T),
10710 Parentheses(T),
10712}
10713
10714impl<T> Display for WrappedCollection<Vec<T>>
10715where
10716 T: Display,
10717{
10718 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10719 match self {
10720 WrappedCollection::NoWrapping(inner) => {
10721 write!(f, "{}", display_comma_separated(inner.as_slice()))
10722 }
10723 WrappedCollection::Parentheses(inner) => {
10724 write!(f, "({})", display_comma_separated(inner.as_slice()))
10725 }
10726 }
10727 }
10728}
10729
10730#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10754#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10755#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10756pub struct UtilityOption {
10757 pub name: Ident,
10759 pub arg: Option<Expr>,
10761}
10762
10763impl Display for UtilityOption {
10764 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10765 if let Some(ref arg) = self.arg {
10766 write!(f, "{} {}", self.name, arg)
10767 } else {
10768 write!(f, "{}", self.name)
10769 }
10770 }
10771}
10772
10773#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10777#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10778#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10779pub struct ShowStatementOptions {
10780 pub show_in: Option<ShowStatementIn>,
10782 pub starts_with: Option<ValueWithSpan>,
10784 pub limit: Option<Expr>,
10786 pub limit_from: Option<ValueWithSpan>,
10788 pub filter_position: Option<ShowStatementFilterPosition>,
10790}
10791
10792impl Display for ShowStatementOptions {
10793 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10794 let (like_in_infix, like_in_suffix) = match &self.filter_position {
10795 Some(ShowStatementFilterPosition::Infix(filter)) => {
10796 (format!(" {filter}"), "".to_string())
10797 }
10798 Some(ShowStatementFilterPosition::Suffix(filter)) => {
10799 ("".to_string(), format!(" {filter}"))
10800 }
10801 None => ("".to_string(), "".to_string()),
10802 };
10803 write!(
10804 f,
10805 "{like_in_infix}{show_in}{starts_with}{limit}{from}{like_in_suffix}",
10806 show_in = match &self.show_in {
10807 Some(i) => format!(" {i}"),
10808 None => String::new(),
10809 },
10810 starts_with = match &self.starts_with {
10811 Some(s) => format!(" STARTS WITH {s}"),
10812 None => String::new(),
10813 },
10814 limit = match &self.limit {
10815 Some(l) => format!(" LIMIT {l}"),
10816 None => String::new(),
10817 },
10818 from = match &self.limit_from {
10819 Some(f) => format!(" FROM {f}"),
10820 None => String::new(),
10821 }
10822 )?;
10823 Ok(())
10824 }
10825}
10826
10827#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10828#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10829#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10830pub enum ShowStatementFilterPosition {
10832 Infix(ShowStatementFilter), Suffix(ShowStatementFilter), }
10837
10838#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10839#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10840#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10841pub enum ShowStatementInParentType {
10843 Account,
10845 Database,
10847 Schema,
10849 Table,
10851 View,
10853}
10854
10855impl fmt::Display for ShowStatementInParentType {
10856 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10857 match self {
10858 ShowStatementInParentType::Account => write!(f, "ACCOUNT"),
10859 ShowStatementInParentType::Database => write!(f, "DATABASE"),
10860 ShowStatementInParentType::Schema => write!(f, "SCHEMA"),
10861 ShowStatementInParentType::Table => write!(f, "TABLE"),
10862 ShowStatementInParentType::View => write!(f, "VIEW"),
10863 }
10864 }
10865}
10866
10867#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10868#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10869#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10870pub struct ShowStatementIn {
10872 pub clause: ShowStatementInClause,
10874 pub parent_type: Option<ShowStatementInParentType>,
10876 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
10878 pub parent_name: Option<ObjectName>,
10879}
10880
10881impl fmt::Display for ShowStatementIn {
10882 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10883 write!(f, "{}", self.clause)?;
10884 if let Some(parent_type) = &self.parent_type {
10885 write!(f, " {parent_type}")?;
10886 }
10887 if let Some(parent_name) = &self.parent_name {
10888 write!(f, " {parent_name}")?;
10889 }
10890 Ok(())
10891 }
10892}
10893
10894#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10896#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10897#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10898pub struct ShowCharset {
10899 pub is_shorthand: bool,
10902 pub filter: Option<ShowStatementFilter>,
10904}
10905
10906impl fmt::Display for ShowCharset {
10907 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10908 write!(f, "SHOW")?;
10909 if self.is_shorthand {
10910 write!(f, " CHARSET")?;
10911 } else {
10912 write!(f, " CHARACTER SET")?;
10913 }
10914 if let Some(filter) = &self.filter {
10915 write!(f, " {filter}")?;
10916 }
10917 Ok(())
10918 }
10919}
10920
10921#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10922#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10923#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10924pub struct ShowObjects {
10926 pub terse: bool,
10928 pub show_options: ShowStatementOptions,
10930}
10931
10932#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10942#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10943#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10944pub enum JsonNullClause {
10945 NullOnNull,
10947 AbsentOnNull,
10949}
10950
10951impl Display for JsonNullClause {
10952 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10953 match self {
10954 JsonNullClause::NullOnNull => write!(f, "NULL ON NULL"),
10955 JsonNullClause::AbsentOnNull => write!(f, "ABSENT ON NULL"),
10956 }
10957 }
10958}
10959
10960#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10967#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10968#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10969pub struct JsonReturningClause {
10970 pub data_type: DataType,
10972}
10973
10974impl Display for JsonReturningClause {
10975 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10976 write!(f, "RETURNING {}", self.data_type)
10977 }
10978}
10979
10980#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10982#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10983#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10984pub struct RenameTable {
10985 pub old_name: ObjectName,
10987 pub new_name: ObjectName,
10989}
10990
10991impl fmt::Display for RenameTable {
10992 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10993 write!(f, "{} TO {}", self.old_name, self.new_name)?;
10994 Ok(())
10995 }
10996}
10997
10998#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11000#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11001#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11002pub enum TableObject {
11003 TableName(#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] ObjectName),
11009
11010 TableFunction(Function),
11017
11018 TableQuery(Box<Query>),
11027}
11028
11029impl fmt::Display for TableObject {
11030 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11031 match self {
11032 Self::TableName(table_name) => write!(f, "{table_name}"),
11033 Self::TableFunction(func) => write!(f, "FUNCTION {func}"),
11034 Self::TableQuery(table_query) => write!(f, "({table_query})"),
11035 }
11036 }
11037}
11038
11039#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11041#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11042#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11043pub struct SetSessionAuthorizationParam {
11044 pub scope: ContextModifier,
11046 pub kind: SetSessionAuthorizationParamKind,
11048}
11049
11050impl fmt::Display for SetSessionAuthorizationParam {
11051 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11052 write!(f, "{}", self.kind)
11053 }
11054}
11055
11056#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11058#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11059#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11060pub enum SetSessionAuthorizationParamKind {
11061 Default,
11063
11064 User(Ident),
11066}
11067
11068impl fmt::Display for SetSessionAuthorizationParamKind {
11069 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11070 match self {
11071 SetSessionAuthorizationParamKind::Default => write!(f, "DEFAULT"),
11072 SetSessionAuthorizationParamKind::User(name) => write!(f, "{}", name),
11073 }
11074 }
11075}
11076
11077#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11078#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11079#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11080pub enum SetSessionParamKind {
11082 Generic(SetSessionParamGeneric),
11084 IdentityInsert(SetSessionParamIdentityInsert),
11086 Offsets(SetSessionParamOffsets),
11088 Statistics(SetSessionParamStatistics),
11090}
11091
11092impl fmt::Display for SetSessionParamKind {
11093 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11094 match self {
11095 SetSessionParamKind::Generic(x) => write!(f, "{x}"),
11096 SetSessionParamKind::IdentityInsert(x) => write!(f, "{x}"),
11097 SetSessionParamKind::Offsets(x) => write!(f, "{x}"),
11098 SetSessionParamKind::Statistics(x) => write!(f, "{x}"),
11099 }
11100 }
11101}
11102
11103#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11104#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11105#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11106pub struct SetSessionParamGeneric {
11108 pub names: Vec<String>,
11110 pub value: String,
11112}
11113
11114impl fmt::Display for SetSessionParamGeneric {
11115 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11116 write!(f, "{} {}", display_comma_separated(&self.names), self.value)
11117 }
11118}
11119
11120#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11121#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11122#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11123pub struct SetSessionParamIdentityInsert {
11125 pub obj: ObjectName,
11127 pub value: SessionParamValue,
11129}
11130
11131impl fmt::Display for SetSessionParamIdentityInsert {
11132 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11133 write!(f, "IDENTITY_INSERT {} {}", self.obj, self.value)
11134 }
11135}
11136
11137#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11138#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11139#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11140pub struct SetSessionParamOffsets {
11142 pub keywords: Vec<String>,
11144 pub value: SessionParamValue,
11146}
11147
11148impl fmt::Display for SetSessionParamOffsets {
11149 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11150 write!(
11151 f,
11152 "OFFSETS {} {}",
11153 display_comma_separated(&self.keywords),
11154 self.value
11155 )
11156 }
11157}
11158
11159#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11160#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11161#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11162pub struct SetSessionParamStatistics {
11164 pub topic: SessionParamStatsTopic,
11166 pub value: SessionParamValue,
11168}
11169
11170impl fmt::Display for SetSessionParamStatistics {
11171 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11172 write!(f, "STATISTICS {} {}", self.topic, self.value)
11173 }
11174}
11175
11176#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11177#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11178#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11179pub enum SessionParamStatsTopic {
11181 IO,
11183 Profile,
11185 Time,
11187 Xml,
11189}
11190
11191impl fmt::Display for SessionParamStatsTopic {
11192 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11193 match self {
11194 SessionParamStatsTopic::IO => write!(f, "IO"),
11195 SessionParamStatsTopic::Profile => write!(f, "PROFILE"),
11196 SessionParamStatsTopic::Time => write!(f, "TIME"),
11197 SessionParamStatsTopic::Xml => write!(f, "XML"),
11198 }
11199 }
11200}
11201
11202#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11203#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11204#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11205pub enum SessionParamValue {
11207 On,
11209 Off,
11211}
11212
11213impl fmt::Display for SessionParamValue {
11214 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11215 match self {
11216 SessionParamValue::On => write!(f, "ON"),
11217 SessionParamValue::Off => write!(f, "OFF"),
11218 }
11219 }
11220}
11221
11222#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11229#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11230#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11231pub enum StorageSerializationPolicy {
11232 Compatible,
11234 Optimized,
11236}
11237
11238impl Display for StorageSerializationPolicy {
11239 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11240 match self {
11241 StorageSerializationPolicy::Compatible => write!(f, "COMPATIBLE"),
11242 StorageSerializationPolicy::Optimized => write!(f, "OPTIMIZED"),
11243 }
11244 }
11245}
11246
11247#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11254#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11255#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11256pub enum CatalogSyncNamespaceMode {
11257 Nest,
11259 Flatten,
11261}
11262
11263impl Display for CatalogSyncNamespaceMode {
11264 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11265 match self {
11266 CatalogSyncNamespaceMode::Nest => write!(f, "NEST"),
11267 CatalogSyncNamespaceMode::Flatten => write!(f, "FLATTEN"),
11268 }
11269 }
11270}
11271
11272#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11274#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11275#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11276pub enum CopyIntoSnowflakeKind {
11277 Table,
11280 Location,
11283}
11284
11285#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11286#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11287#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11288pub struct PrintStatement {
11290 pub message: Box<Expr>,
11292}
11293
11294impl fmt::Display for PrintStatement {
11295 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11296 write!(f, "PRINT {}", self.message)
11297 }
11298}
11299
11300#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11304#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11305#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11306pub enum WaitForType {
11307 Delay,
11309 Time,
11311}
11312
11313impl fmt::Display for WaitForType {
11314 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11315 match self {
11316 WaitForType::Delay => write!(f, "DELAY"),
11317 WaitForType::Time => write!(f, "TIME"),
11318 }
11319 }
11320}
11321
11322#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11326#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11327#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11328pub struct WaitForStatement {
11329 pub wait_type: WaitForType,
11331 pub expr: Expr,
11333}
11334
11335impl fmt::Display for WaitForStatement {
11336 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11337 write!(f, "WAITFOR {} {}", self.wait_type, self.expr)
11338 }
11339}
11340
11341#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11346#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11347#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11348pub struct ReturnStatement {
11349 pub value: Option<ReturnStatementValue>,
11351}
11352
11353impl fmt::Display for ReturnStatement {
11354 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11355 match &self.value {
11356 Some(ReturnStatementValue::Expr(expr)) => write!(f, "RETURN {expr}"),
11357 None => write!(f, "RETURN"),
11358 }
11359 }
11360}
11361
11362#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11364#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11365#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11366pub enum ReturnStatementValue {
11367 Expr(Expr),
11369}
11370
11371#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11373#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11374#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11375pub struct OpenStatement {
11376 pub cursor_name: Ident,
11378}
11379
11380impl fmt::Display for OpenStatement {
11381 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11382 write!(f, "OPEN {}", self.cursor_name)
11383 }
11384}
11385
11386#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11390#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11391#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11392pub enum NullInclusion {
11393 IncludeNulls,
11395 ExcludeNulls,
11397}
11398
11399impl fmt::Display for NullInclusion {
11400 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11401 match self {
11402 NullInclusion::IncludeNulls => write!(f, "INCLUDE NULLS"),
11403 NullInclusion::ExcludeNulls => write!(f, "EXCLUDE NULLS"),
11404 }
11405 }
11406}
11407
11408#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11416#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11417#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11418pub struct MemberOf {
11419 pub value: Box<Expr>,
11421 pub array: Box<Expr>,
11423}
11424
11425impl fmt::Display for MemberOf {
11426 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11427 write!(f, "{} MEMBER OF({})", self.value, self.array)
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 ExportData {
11436 pub options: Vec<SqlOption>,
11438 pub query: Box<Query>,
11440 pub connection: Option<ObjectName>,
11442}
11443
11444impl fmt::Display for ExportData {
11445 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11446 if let Some(connection) = &self.connection {
11447 write!(
11448 f,
11449 "EXPORT DATA WITH CONNECTION {connection} OPTIONS({}) AS {}",
11450 display_comma_separated(&self.options),
11451 self.query
11452 )
11453 } else {
11454 write!(
11455 f,
11456 "EXPORT DATA OPTIONS({}) AS {}",
11457 display_comma_separated(&self.options),
11458 self.query
11459 )
11460 }
11461 }
11462}
11463#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11472#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11473#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11474pub struct CreateUser {
11475 pub or_replace: bool,
11477 pub if_not_exists: bool,
11479 pub name: Ident,
11481 pub options: KeyValueOptions,
11483 pub with_tags: bool,
11485 pub tags: KeyValueOptions,
11487}
11488
11489impl fmt::Display for CreateUser {
11490 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11491 write!(f, "CREATE")?;
11492 if self.or_replace {
11493 write!(f, " OR REPLACE")?;
11494 }
11495 write!(f, " USER")?;
11496 if self.if_not_exists {
11497 write!(f, " IF NOT EXISTS")?;
11498 }
11499 write!(f, " {}", self.name)?;
11500 if !self.options.options.is_empty() {
11501 write!(f, " {}", self.options)?;
11502 }
11503 if !self.tags.options.is_empty() {
11504 if self.with_tags {
11505 write!(f, " WITH")?;
11506 }
11507 write!(f, " TAG ({})", self.tags)?;
11508 }
11509 Ok(())
11510 }
11511}
11512
11513#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11525#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11526#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11527pub struct AlterUser {
11528 pub if_exists: bool,
11530 pub name: Ident,
11532 pub rename_to: Option<Ident>,
11535 pub reset_password: bool,
11537 pub abort_all_queries: bool,
11539 pub add_role_delegation: Option<AlterUserAddRoleDelegation>,
11541 pub remove_role_delegation: Option<AlterUserRemoveRoleDelegation>,
11543 pub enroll_mfa: bool,
11545 pub set_default_mfa_method: Option<MfaMethodKind>,
11547 pub remove_mfa_method: Option<MfaMethodKind>,
11549 pub modify_mfa_method: Option<AlterUserModifyMfaMethod>,
11551 pub add_mfa_method_otp: Option<AlterUserAddMfaMethodOtp>,
11553 pub set_policy: Option<AlterUserSetPolicy>,
11555 pub unset_policy: Option<UserPolicyKind>,
11557 pub set_tag: KeyValueOptions,
11559 pub unset_tag: Vec<String>,
11561 pub set_props: KeyValueOptions,
11563 pub unset_props: Vec<String>,
11565 pub password: Option<AlterUserPassword>,
11567}
11568
11569#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11573#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11574#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11575pub struct AlterUserAddRoleDelegation {
11576 pub role: Ident,
11578 pub integration: Ident,
11580}
11581
11582#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11586#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11587#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11588pub struct AlterUserRemoveRoleDelegation {
11589 pub role: Option<Ident>,
11591 pub integration: Ident,
11593}
11594
11595#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11599#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11600#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11601pub struct AlterUserAddMfaMethodOtp {
11602 pub count: Option<ValueWithSpan>,
11604}
11605
11606#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11610#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11611#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11612pub struct AlterUserModifyMfaMethod {
11613 pub method: MfaMethodKind,
11615 pub comment: String,
11617}
11618
11619#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11621#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11622#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11623pub enum MfaMethodKind {
11624 PassKey,
11626 Totp,
11628 Duo,
11630}
11631
11632impl fmt::Display for MfaMethodKind {
11633 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11634 match self {
11635 MfaMethodKind::PassKey => write!(f, "PASSKEY"),
11636 MfaMethodKind::Totp => write!(f, "TOTP"),
11637 MfaMethodKind::Duo => write!(f, "DUO"),
11638 }
11639 }
11640}
11641
11642#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11646#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11647#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11648pub struct AlterUserSetPolicy {
11649 pub policy_kind: UserPolicyKind,
11651 pub policy: Ident,
11653}
11654
11655#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11657#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11658#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11659pub enum UserPolicyKind {
11660 Authentication,
11662 Password,
11664 Session,
11666}
11667
11668impl fmt::Display for UserPolicyKind {
11669 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11670 match self {
11671 UserPolicyKind::Authentication => write!(f, "AUTHENTICATION"),
11672 UserPolicyKind::Password => write!(f, "PASSWORD"),
11673 UserPolicyKind::Session => write!(f, "SESSION"),
11674 }
11675 }
11676}
11677
11678impl fmt::Display for AlterUser {
11679 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11680 write!(f, "ALTER")?;
11681 write!(f, " USER")?;
11682 if self.if_exists {
11683 write!(f, " IF EXISTS")?;
11684 }
11685 write!(f, " {}", self.name)?;
11686 if let Some(new_name) = &self.rename_to {
11687 write!(f, " RENAME TO {new_name}")?;
11688 }
11689 if self.reset_password {
11690 write!(f, " RESET PASSWORD")?;
11691 }
11692 if self.abort_all_queries {
11693 write!(f, " ABORT ALL QUERIES")?;
11694 }
11695 if let Some(role_delegation) = &self.add_role_delegation {
11696 let role = &role_delegation.role;
11697 let integration = &role_delegation.integration;
11698 write!(
11699 f,
11700 " ADD DELEGATED AUTHORIZATION OF ROLE {role} TO SECURITY INTEGRATION {integration}"
11701 )?;
11702 }
11703 if let Some(role_delegation) = &self.remove_role_delegation {
11704 write!(f, " REMOVE DELEGATED")?;
11705 match &role_delegation.role {
11706 Some(role) => write!(f, " AUTHORIZATION OF ROLE {role}")?,
11707 None => write!(f, " AUTHORIZATIONS")?,
11708 }
11709 let integration = &role_delegation.integration;
11710 write!(f, " FROM SECURITY INTEGRATION {integration}")?;
11711 }
11712 if self.enroll_mfa {
11713 write!(f, " ENROLL MFA")?;
11714 }
11715 if let Some(method) = &self.set_default_mfa_method {
11716 write!(f, " SET DEFAULT_MFA_METHOD {method}")?
11717 }
11718 if let Some(method) = &self.remove_mfa_method {
11719 write!(f, " REMOVE MFA METHOD {method}")?;
11720 }
11721 if let Some(modify) = &self.modify_mfa_method {
11722 let method = &modify.method;
11723 let comment = &modify.comment;
11724 write!(
11725 f,
11726 " MODIFY MFA METHOD {method} SET COMMENT '{}'",
11727 value::escape_single_quote_string(comment)
11728 )?;
11729 }
11730 if let Some(add_mfa_method_otp) = &self.add_mfa_method_otp {
11731 write!(f, " ADD MFA METHOD OTP")?;
11732 if let Some(count) = &add_mfa_method_otp.count {
11733 write!(f, " COUNT = {count}")?;
11734 }
11735 }
11736 if let Some(policy) = &self.set_policy {
11737 let policy_kind = &policy.policy_kind;
11738 let name = &policy.policy;
11739 write!(f, " SET {policy_kind} POLICY {name}")?;
11740 }
11741 if let Some(policy_kind) = &self.unset_policy {
11742 write!(f, " UNSET {policy_kind} POLICY")?;
11743 }
11744 if !self.set_tag.options.is_empty() {
11745 write!(f, " SET TAG {}", self.set_tag)?;
11746 }
11747 if !self.unset_tag.is_empty() {
11748 write!(f, " UNSET TAG {}", display_comma_separated(&self.unset_tag))?;
11749 }
11750 let has_props = !self.set_props.options.is_empty();
11751 if has_props {
11752 write!(f, " SET")?;
11753 write!(f, " {}", &self.set_props)?;
11754 }
11755 if !self.unset_props.is_empty() {
11756 write!(f, " UNSET {}", display_comma_separated(&self.unset_props))?;
11757 }
11758 if let Some(password) = &self.password {
11759 write!(f, " {}", password)?;
11760 }
11761 Ok(())
11762 }
11763}
11764
11765#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11769#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11770#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11771pub struct AlterUserPassword {
11772 pub encrypted: bool,
11774 pub password: Option<String>,
11776}
11777
11778impl Display for AlterUserPassword {
11779 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11780 if self.encrypted {
11781 write!(f, "ENCRYPTED ")?;
11782 }
11783 write!(f, "PASSWORD")?;
11784 match &self.password {
11785 None => write!(f, " NULL")?,
11786 Some(password) => write!(f, " '{}'", value::escape_single_quote_string(password))?,
11787 }
11788 Ok(())
11789 }
11790}
11791
11792#[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 enum CreateTableLikeKind {
11800 Parenthesized(CreateTableLike),
11805 Plain(CreateTableLike),
11811}
11812
11813#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11814#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11815#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11816pub enum CreateTableLikeDefaults {
11818 Including,
11820 Excluding,
11822}
11823
11824impl fmt::Display for CreateTableLikeDefaults {
11825 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11826 match self {
11827 CreateTableLikeDefaults::Including => write!(f, "INCLUDING DEFAULTS"),
11828 CreateTableLikeDefaults::Excluding => write!(f, "EXCLUDING DEFAULTS"),
11829 }
11830 }
11831}
11832
11833#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11834#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11835#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11836pub struct CreateTableLike {
11838 pub name: ObjectName,
11840 pub defaults: Option<CreateTableLikeDefaults>,
11842}
11843
11844impl fmt::Display for CreateTableLike {
11845 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11846 write!(f, "LIKE {}", self.name)?;
11847 if let Some(defaults) = &self.defaults {
11848 write!(f, " {defaults}")?;
11849 }
11850 Ok(())
11851 }
11852}
11853
11854#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11858#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11859#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11860pub enum RefreshModeKind {
11861 Auto,
11863 Full,
11865 Incremental,
11867}
11868
11869impl fmt::Display for RefreshModeKind {
11870 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11871 match self {
11872 RefreshModeKind::Auto => write!(f, "AUTO"),
11873 RefreshModeKind::Full => write!(f, "FULL"),
11874 RefreshModeKind::Incremental => write!(f, "INCREMENTAL"),
11875 }
11876 }
11877}
11878
11879#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11883#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11884#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11885pub enum InitializeKind {
11886 OnCreate,
11888 OnSchedule,
11890}
11891
11892impl fmt::Display for InitializeKind {
11893 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11894 match self {
11895 InitializeKind::OnCreate => write!(f, "ON_CREATE"),
11896 InitializeKind::OnSchedule => write!(f, "ON_SCHEDULE"),
11897 }
11898 }
11899}
11900
11901#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11908#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11909#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11910pub struct VacuumStatement {
11911 pub full: bool,
11913 pub sort_only: bool,
11915 pub delete_only: bool,
11917 pub reindex: bool,
11919 pub recluster: bool,
11921 pub table_name: Option<ObjectName>,
11923 pub threshold: Option<ValueWithSpan>,
11925 pub boost: bool,
11927}
11928
11929impl fmt::Display for VacuumStatement {
11930 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11931 write!(
11932 f,
11933 "VACUUM{}{}{}{}{}",
11934 if self.full { " FULL" } else { "" },
11935 if self.sort_only { " SORT ONLY" } else { "" },
11936 if self.delete_only { " DELETE ONLY" } else { "" },
11937 if self.reindex { " REINDEX" } else { "" },
11938 if self.recluster { " RECLUSTER" } else { "" },
11939 )?;
11940 if let Some(table_name) = &self.table_name {
11941 write!(f, " {table_name}")?;
11942 }
11943 if let Some(threshold) = &self.threshold {
11944 write!(f, " TO {threshold} PERCENT")?;
11945 }
11946 if self.boost {
11947 write!(f, " BOOST")?;
11948 }
11949 Ok(())
11950 }
11951}
11952
11953#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11955#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11956#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11957pub enum Reset {
11958 ALL,
11960
11961 ConfigurationParameter(ObjectName),
11963}
11964
11965#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11970#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11971#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11972pub struct ResetStatement {
11973 pub reset: Reset,
11975}
11976
11977#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11983#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11984#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11985pub struct OptimizerHint {
11986 pub prefix: String,
11993 pub text: String,
11995 pub style: OptimizerHintStyle,
12000}
12001
12002#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
12004#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
12005#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
12006pub enum OptimizerHintStyle {
12007 SingleLine {
12010 prefix: String,
12012 },
12013 MultiLine,
12016}
12017
12018impl fmt::Display for OptimizerHint {
12019 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12020 match &self.style {
12021 OptimizerHintStyle::SingleLine { prefix } => {
12022 f.write_str(prefix)?;
12023 f.write_str(&self.prefix)?;
12024 f.write_str("+")?;
12025 f.write_str(&self.text)
12026 }
12027 OptimizerHintStyle::MultiLine => {
12028 f.write_str("/*")?;
12029 f.write_str(&self.prefix)?;
12030 f.write_str("+")?;
12031 f.write_str(&self.text)?;
12032 f.write_str("*/")
12033 }
12034 }
12035 }
12036}
12037
12038impl fmt::Display for ResetStatement {
12039 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12040 match &self.reset {
12041 Reset::ALL => write!(f, "RESET ALL"),
12042 Reset::ConfigurationParameter(param) => write!(f, "RESET {}", param),
12043 }
12044 }
12045}
12046
12047impl From<Set> for Statement {
12048 fn from(s: Set) -> Self {
12049 Self::Set(s)
12050 }
12051}
12052
12053impl From<Query> for Statement {
12054 fn from(q: Query) -> Self {
12055 Box::new(q).into()
12056 }
12057}
12058
12059impl From<Box<Query>> for Statement {
12060 fn from(q: Box<Query>) -> Self {
12061 Self::Query(q)
12062 }
12063}
12064
12065impl From<Insert> for Statement {
12066 fn from(i: Insert) -> Self {
12067 Self::Insert(i)
12068 }
12069}
12070
12071impl From<Update> for Statement {
12072 fn from(u: Update) -> Self {
12073 Self::Update(u)
12074 }
12075}
12076
12077impl From<CreateView> for Statement {
12078 fn from(cv: CreateView) -> Self {
12079 Self::CreateView(cv)
12080 }
12081}
12082
12083impl From<CreateRole> for Statement {
12084 fn from(cr: CreateRole) -> Self {
12085 Self::CreateRole(cr)
12086 }
12087}
12088
12089impl From<AlterTable> for Statement {
12090 fn from(at: AlterTable) -> Self {
12091 Self::AlterTable(at)
12092 }
12093}
12094
12095impl From<DropFunction> for Statement {
12096 fn from(df: DropFunction) -> Self {
12097 Self::DropFunction(df)
12098 }
12099}
12100
12101impl From<CreateExtension> for Statement {
12102 fn from(ce: CreateExtension) -> Self {
12103 Self::CreateExtension(ce)
12104 }
12105}
12106
12107impl From<CreateCollation> for Statement {
12108 fn from(c: CreateCollation) -> Self {
12109 Self::CreateCollation(c)
12110 }
12111}
12112
12113impl From<DropExtension> for Statement {
12114 fn from(de: DropExtension) -> Self {
12115 Self::DropExtension(de)
12116 }
12117}
12118
12119impl From<CaseStatement> for Statement {
12120 fn from(c: CaseStatement) -> Self {
12121 Self::Case(c)
12122 }
12123}
12124
12125impl From<IfStatement> for Statement {
12126 fn from(i: IfStatement) -> Self {
12127 Self::If(i)
12128 }
12129}
12130
12131impl From<WhileStatement> for Statement {
12132 fn from(w: WhileStatement) -> Self {
12133 Self::While(w)
12134 }
12135}
12136
12137impl From<RaiseStatement> for Statement {
12138 fn from(r: RaiseStatement) -> Self {
12139 Self::Raise(r)
12140 }
12141}
12142
12143impl From<ThrowStatement> for Statement {
12144 fn from(t: ThrowStatement) -> Self {
12145 Self::Throw(t)
12146 }
12147}
12148
12149impl From<Function> for Statement {
12150 fn from(f: Function) -> Self {
12151 Self::Call(f)
12152 }
12153}
12154
12155impl From<OpenStatement> for Statement {
12156 fn from(o: OpenStatement) -> Self {
12157 Self::Open(o)
12158 }
12159}
12160
12161impl From<Delete> for Statement {
12162 fn from(d: Delete) -> Self {
12163 Self::Delete(d)
12164 }
12165}
12166
12167impl From<CreateTable> for Statement {
12168 fn from(c: CreateTable) -> Self {
12169 Self::CreateTable(c)
12170 }
12171}
12172
12173impl From<CreateIndex> for Statement {
12174 fn from(c: CreateIndex) -> Self {
12175 Self::CreateIndex(c)
12176 }
12177}
12178
12179impl From<CreateServerStatement> for Statement {
12180 fn from(c: CreateServerStatement) -> Self {
12181 Self::CreateServer(c)
12182 }
12183}
12184
12185impl From<CreateConnector> for Statement {
12186 fn from(c: CreateConnector) -> Self {
12187 Self::CreateConnector(c)
12188 }
12189}
12190
12191impl From<CreateOperator> for Statement {
12192 fn from(c: CreateOperator) -> Self {
12193 Self::CreateOperator(c)
12194 }
12195}
12196
12197impl From<CreateOperatorFamily> for Statement {
12198 fn from(c: CreateOperatorFamily) -> Self {
12199 Self::CreateOperatorFamily(c)
12200 }
12201}
12202
12203impl From<CreateOperatorClass> for Statement {
12204 fn from(c: CreateOperatorClass) -> Self {
12205 Self::CreateOperatorClass(c)
12206 }
12207}
12208
12209impl From<AlterSchema> for Statement {
12210 fn from(a: AlterSchema) -> Self {
12211 Self::AlterSchema(a)
12212 }
12213}
12214
12215impl From<AlterFunction> for Statement {
12216 fn from(a: AlterFunction) -> Self {
12217 Self::AlterFunction(a)
12218 }
12219}
12220
12221impl From<AlterType> for Statement {
12222 fn from(a: AlterType) -> Self {
12223 Self::AlterType(a)
12224 }
12225}
12226
12227impl From<AlterCollation> for Statement {
12228 fn from(a: AlterCollation) -> Self {
12229 Self::AlterCollation(a)
12230 }
12231}
12232
12233impl From<AlterOperator> for Statement {
12234 fn from(a: AlterOperator) -> Self {
12235 Self::AlterOperator(a)
12236 }
12237}
12238
12239impl From<AlterOperatorFamily> for Statement {
12240 fn from(a: AlterOperatorFamily) -> Self {
12241 Self::AlterOperatorFamily(a)
12242 }
12243}
12244
12245impl From<AlterOperatorClass> for Statement {
12246 fn from(a: AlterOperatorClass) -> Self {
12247 Self::AlterOperatorClass(a)
12248 }
12249}
12250
12251impl From<Merge> for Statement {
12252 fn from(m: Merge) -> Self {
12253 Self::Merge(m)
12254 }
12255}
12256
12257impl From<AlterUser> for Statement {
12258 fn from(a: AlterUser) -> Self {
12259 Self::AlterUser(a)
12260 }
12261}
12262
12263impl From<DropDomain> for Statement {
12264 fn from(d: DropDomain) -> Self {
12265 Self::DropDomain(d)
12266 }
12267}
12268
12269impl From<ShowCharset> for Statement {
12270 fn from(s: ShowCharset) -> Self {
12271 Self::ShowCharset(s)
12272 }
12273}
12274
12275impl From<ShowObjects> for Statement {
12276 fn from(s: ShowObjects) -> Self {
12277 Self::ShowObjects(s)
12278 }
12279}
12280
12281impl From<Use> for Statement {
12282 fn from(u: Use) -> Self {
12283 Self::Use(u)
12284 }
12285}
12286
12287impl From<CreateFunction> for Statement {
12288 fn from(c: CreateFunction) -> Self {
12289 Self::CreateFunction(c)
12290 }
12291}
12292
12293impl From<CreateTrigger> for Statement {
12294 fn from(c: CreateTrigger) -> Self {
12295 Self::CreateTrigger(c)
12296 }
12297}
12298
12299impl From<DropTrigger> for Statement {
12300 fn from(d: DropTrigger) -> Self {
12301 Self::DropTrigger(d)
12302 }
12303}
12304
12305impl From<DropOperator> for Statement {
12306 fn from(d: DropOperator) -> Self {
12307 Self::DropOperator(d)
12308 }
12309}
12310
12311impl From<DropOperatorFamily> for Statement {
12312 fn from(d: DropOperatorFamily) -> Self {
12313 Self::DropOperatorFamily(d)
12314 }
12315}
12316
12317impl From<DropOperatorClass> for Statement {
12318 fn from(d: DropOperatorClass) -> Self {
12319 Self::DropOperatorClass(d)
12320 }
12321}
12322
12323impl From<DenyStatement> for Statement {
12324 fn from(d: DenyStatement) -> Self {
12325 Self::Deny(d)
12326 }
12327}
12328
12329impl From<CreateDomain> for Statement {
12330 fn from(c: CreateDomain) -> Self {
12331 Self::CreateDomain(c)
12332 }
12333}
12334
12335impl From<RenameTable> for Statement {
12336 fn from(r: RenameTable) -> Self {
12337 vec![r].into()
12338 }
12339}
12340
12341impl From<Vec<RenameTable>> for Statement {
12342 fn from(r: Vec<RenameTable>) -> Self {
12343 Self::RenameTable(r)
12344 }
12345}
12346
12347impl From<PrintStatement> for Statement {
12348 fn from(p: PrintStatement) -> Self {
12349 Self::Print(p)
12350 }
12351}
12352
12353impl From<ReturnStatement> for Statement {
12354 fn from(r: ReturnStatement) -> Self {
12355 Self::Return(r)
12356 }
12357}
12358
12359impl From<ExportData> for Statement {
12360 fn from(e: ExportData) -> Self {
12361 Self::ExportData(e)
12362 }
12363}
12364
12365impl From<CreateUser> for Statement {
12366 fn from(c: CreateUser) -> Self {
12367 Self::CreateUser(c)
12368 }
12369}
12370
12371impl From<VacuumStatement> for Statement {
12372 fn from(v: VacuumStatement) -> Self {
12373 Self::Vacuum(v)
12374 }
12375}
12376
12377impl From<ResetStatement> for Statement {
12378 fn from(r: ResetStatement) -> Self {
12379 Self::Reset(r)
12380 }
12381}
12382
12383#[cfg(test)]
12384mod tests {
12385 use crate::tokenizer::Location;
12386
12387 use super::*;
12388
12389 #[test]
12390 fn test_window_frame_default() {
12391 let window_frame = WindowFrame::default();
12392 assert_eq!(WindowFrameBound::Preceding(None), window_frame.start_bound);
12393 }
12394
12395 #[test]
12396 fn test_grouping_sets_display() {
12397 let grouping_sets = Expr::GroupingSets(vec![
12399 vec![Expr::Identifier(Ident::new("a"))],
12400 vec![Expr::Identifier(Ident::new("b"))],
12401 ]);
12402 assert_eq!("GROUPING SETS ((a), (b))", format!("{grouping_sets}"));
12403
12404 let grouping_sets = Expr::GroupingSets(vec![vec![
12406 Expr::Identifier(Ident::new("a")),
12407 Expr::Identifier(Ident::new("b")),
12408 ]]);
12409 assert_eq!("GROUPING SETS ((a, b))", format!("{grouping_sets}"));
12410
12411 let grouping_sets = Expr::GroupingSets(vec![
12413 vec![
12414 Expr::Identifier(Ident::new("a")),
12415 Expr::Identifier(Ident::new("b")),
12416 ],
12417 vec![
12418 Expr::Identifier(Ident::new("c")),
12419 Expr::Identifier(Ident::new("d")),
12420 ],
12421 ]);
12422 assert_eq!("GROUPING SETS ((a, b), (c, d))", format!("{grouping_sets}"));
12423 }
12424
12425 #[test]
12426 fn test_rollup_display() {
12427 let rollup = Expr::Rollup(vec![vec![Expr::Identifier(Ident::new("a"))]]);
12428 assert_eq!("ROLLUP (a)", format!("{rollup}"));
12429
12430 let rollup = Expr::Rollup(vec![vec![
12431 Expr::Identifier(Ident::new("a")),
12432 Expr::Identifier(Ident::new("b")),
12433 ]]);
12434 assert_eq!("ROLLUP ((a, b))", format!("{rollup}"));
12435
12436 let rollup = Expr::Rollup(vec![
12437 vec![Expr::Identifier(Ident::new("a"))],
12438 vec![Expr::Identifier(Ident::new("b"))],
12439 ]);
12440 assert_eq!("ROLLUP (a, b)", format!("{rollup}"));
12441
12442 let rollup = Expr::Rollup(vec![
12443 vec![Expr::Identifier(Ident::new("a"))],
12444 vec![
12445 Expr::Identifier(Ident::new("b")),
12446 Expr::Identifier(Ident::new("c")),
12447 ],
12448 vec![Expr::Identifier(Ident::new("d"))],
12449 ]);
12450 assert_eq!("ROLLUP (a, (b, c), d)", format!("{rollup}"));
12451 }
12452
12453 #[test]
12454 fn test_cube_display() {
12455 let cube = Expr::Cube(vec![vec![Expr::Identifier(Ident::new("a"))]]);
12456 assert_eq!("CUBE (a)", format!("{cube}"));
12457
12458 let cube = Expr::Cube(vec![vec![
12459 Expr::Identifier(Ident::new("a")),
12460 Expr::Identifier(Ident::new("b")),
12461 ]]);
12462 assert_eq!("CUBE ((a, b))", format!("{cube}"));
12463
12464 let cube = Expr::Cube(vec![
12465 vec![Expr::Identifier(Ident::new("a"))],
12466 vec![Expr::Identifier(Ident::new("b"))],
12467 ]);
12468 assert_eq!("CUBE (a, b)", format!("{cube}"));
12469
12470 let cube = Expr::Cube(vec![
12471 vec![Expr::Identifier(Ident::new("a"))],
12472 vec![
12473 Expr::Identifier(Ident::new("b")),
12474 Expr::Identifier(Ident::new("c")),
12475 ],
12476 vec![Expr::Identifier(Ident::new("d"))],
12477 ]);
12478 assert_eq!("CUBE (a, (b, c), d)", format!("{cube}"));
12479 }
12480
12481 #[test]
12482 fn test_interval_display() {
12483 let interval = Expr::Interval(Interval {
12484 value: Box::new(Expr::Value(
12485 Value::SingleQuotedString(String::from("123:45.67")).with_empty_span(),
12486 )),
12487 leading_field: Some(DateTimeField::Minute),
12488 leading_precision: Some(10),
12489 last_field: Some(DateTimeField::Second),
12490 fractional_seconds_precision: Some(9),
12491 });
12492 assert_eq!(
12493 "INTERVAL '123:45.67' MINUTE (10) TO SECOND (9)",
12494 format!("{interval}"),
12495 );
12496
12497 let interval = Expr::Interval(Interval {
12498 value: Box::new(Expr::Value(
12499 Value::SingleQuotedString(String::from("5")).with_empty_span(),
12500 )),
12501 leading_field: Some(DateTimeField::Second),
12502 leading_precision: Some(1),
12503 last_field: None,
12504 fractional_seconds_precision: Some(3),
12505 });
12506 assert_eq!("INTERVAL '5' SECOND (1, 3)", format!("{interval}"));
12507 }
12508
12509 #[test]
12510 fn test_one_or_many_with_parens_deref() {
12511 use core::ops::Index;
12512
12513 let one = OneOrManyWithParens::One("a");
12514
12515 assert_eq!(one.deref(), &["a"]);
12516 assert_eq!(<OneOrManyWithParens<_> as Deref>::deref(&one), &["a"]);
12517
12518 assert_eq!(one[0], "a");
12519 assert_eq!(one.index(0), &"a");
12520 assert_eq!(
12521 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&one, 0),
12522 &"a"
12523 );
12524
12525 assert_eq!(one.len(), 1);
12526 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&one), 1);
12527
12528 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12529
12530 assert_eq!(many1.deref(), &["b"]);
12531 assert_eq!(<OneOrManyWithParens<_> as Deref>::deref(&many1), &["b"]);
12532
12533 assert_eq!(many1[0], "b");
12534 assert_eq!(many1.index(0), &"b");
12535 assert_eq!(
12536 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many1, 0),
12537 &"b"
12538 );
12539
12540 assert_eq!(many1.len(), 1);
12541 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&many1), 1);
12542
12543 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12544
12545 assert_eq!(many2.deref(), &["c", "d"]);
12546 assert_eq!(
12547 <OneOrManyWithParens<_> as Deref>::deref(&many2),
12548 &["c", "d"]
12549 );
12550
12551 assert_eq!(many2[0], "c");
12552 assert_eq!(many2.index(0), &"c");
12553 assert_eq!(
12554 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many2, 0),
12555 &"c"
12556 );
12557
12558 assert_eq!(many2[1], "d");
12559 assert_eq!(many2.index(1), &"d");
12560 assert_eq!(
12561 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many2, 1),
12562 &"d"
12563 );
12564
12565 assert_eq!(many2.len(), 2);
12566 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&many2), 2);
12567 }
12568
12569 #[test]
12570 fn test_one_or_many_with_parens_as_ref() {
12571 let one = OneOrManyWithParens::One("a");
12572
12573 assert_eq!(one.as_ref(), &["a"]);
12574 assert_eq!(<OneOrManyWithParens<_> as AsRef<_>>::as_ref(&one), &["a"]);
12575
12576 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12577
12578 assert_eq!(many1.as_ref(), &["b"]);
12579 assert_eq!(<OneOrManyWithParens<_> as AsRef<_>>::as_ref(&many1), &["b"]);
12580
12581 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12582
12583 assert_eq!(many2.as_ref(), &["c", "d"]);
12584 assert_eq!(
12585 <OneOrManyWithParens<_> as AsRef<_>>::as_ref(&many2),
12586 &["c", "d"]
12587 );
12588 }
12589
12590 #[test]
12591 fn test_one_or_many_with_parens_ref_into_iter() {
12592 let one = OneOrManyWithParens::One("a");
12593
12594 assert_eq!(Vec::from_iter(&one), vec![&"a"]);
12595
12596 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12597
12598 assert_eq!(Vec::from_iter(&many1), vec![&"b"]);
12599
12600 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12601
12602 assert_eq!(Vec::from_iter(&many2), vec![&"c", &"d"]);
12603 }
12604
12605 #[test]
12606 fn test_one_or_many_with_parens_value_into_iter() {
12607 use core::iter::once;
12608
12609 fn test_steps<I>(ours: OneOrManyWithParens<usize>, inner: I, n: usize)
12611 where
12612 I: IntoIterator<Item = usize, IntoIter: DoubleEndedIterator + Clone> + Clone,
12613 {
12614 fn checks<I>(ours: OneOrManyWithParensIntoIter<usize>, inner: I)
12615 where
12616 I: Iterator<Item = usize> + Clone + DoubleEndedIterator,
12617 {
12618 assert_eq!(ours.size_hint(), inner.size_hint());
12619 assert_eq!(ours.clone().count(), inner.clone().count());
12620
12621 assert_eq!(
12622 ours.clone().fold(1, |a, v| a + v),
12623 inner.clone().fold(1, |a, v| a + v)
12624 );
12625
12626 assert_eq!(Vec::from_iter(ours.clone()), Vec::from_iter(inner.clone()));
12627 assert_eq!(
12628 Vec::from_iter(ours.clone().rev()),
12629 Vec::from_iter(inner.clone().rev())
12630 );
12631 }
12632
12633 let mut ours_next = ours.clone().into_iter();
12634 let mut inner_next = inner.clone().into_iter();
12635
12636 for _ in 0..n {
12637 checks(ours_next.clone(), inner_next.clone());
12638
12639 assert_eq!(ours_next.next(), inner_next.next());
12640 }
12641
12642 let mut ours_next_back = ours.clone().into_iter();
12643 let mut inner_next_back = inner.clone().into_iter();
12644
12645 for _ in 0..n {
12646 checks(ours_next_back.clone(), inner_next_back.clone());
12647
12648 assert_eq!(ours_next_back.next_back(), inner_next_back.next_back());
12649 }
12650
12651 let mut ours_mixed = ours.clone().into_iter();
12652 let mut inner_mixed = inner.clone().into_iter();
12653
12654 for i in 0..n {
12655 checks(ours_mixed.clone(), inner_mixed.clone());
12656
12657 if i % 2 == 0 {
12658 assert_eq!(ours_mixed.next_back(), inner_mixed.next_back());
12659 } else {
12660 assert_eq!(ours_mixed.next(), inner_mixed.next());
12661 }
12662 }
12663
12664 let mut ours_mixed2 = ours.into_iter();
12665 let mut inner_mixed2 = inner.into_iter();
12666
12667 for i in 0..n {
12668 checks(ours_mixed2.clone(), inner_mixed2.clone());
12669
12670 if i % 2 == 0 {
12671 assert_eq!(ours_mixed2.next(), inner_mixed2.next());
12672 } else {
12673 assert_eq!(ours_mixed2.next_back(), inner_mixed2.next_back());
12674 }
12675 }
12676 }
12677
12678 test_steps(OneOrManyWithParens::One(1), once(1), 3);
12679 test_steps(OneOrManyWithParens::Many(vec![2]), vec![2], 3);
12680 test_steps(OneOrManyWithParens::Many(vec![3, 4]), vec![3, 4], 4);
12681 }
12682
12683 #[test]
12686 fn test_ident_ord() {
12687 let mut a = Ident::with_span(Span::new(Location::new(1, 1), Location::new(1, 1)), "a");
12688 let mut b = Ident::with_span(Span::new(Location::new(2, 2), Location::new(2, 2)), "b");
12689
12690 assert!(a < b);
12691 std::mem::swap(&mut a.span, &mut b.span);
12692 assert!(a < b);
12693 }
12694}