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 ClusteredBy, ColumnDef, ColumnOption, ColumnOptionDef, ColumnOptions, ColumnPolicy,
71 ColumnPolicyProperty, ConstraintCharacteristics, CreateCollation, CreateCollationDefinition,
72 CreateConnector, CreateDomain, CreateExtension, CreateFunction, CreateIndex, CreateOperator,
73 CreateOperatorClass, CreateOperatorFamily, CreatePolicy, CreatePolicyCommand, CreatePolicyType,
74 CreateTable, CreateTrigger, CreateView, Deduplicate, DeferrableInitial, DistStyle,
75 DropBehavior, DropExtension, DropFunction, DropOperator, DropOperatorClass, DropOperatorFamily,
76 DropOperatorSignature, DropPolicy, DropTrigger, ForValues, FunctionReturnType, GeneratedAs,
77 GeneratedExpressionMode, IdentityParameters, IdentityProperty, IdentityPropertyFormatKind,
78 IdentityPropertyKind, IdentityPropertyOrder, IndexColumn, IndexOption, IndexType,
79 KeyOrIndexDisplay, Msck, NullsDistinctOption, OperatorArgTypes, OperatorClassItem,
80 OperatorFamilyDropItem, OperatorFamilyItem, OperatorOption, OperatorPurpose, Owner, Partition,
81 PartitionBoundValue, ProcedureParam, ReferentialAction, RenameTableNameKind, ReplicaIdentity,
82 TagsColumnOption, TriggerObjectKind, Truncate, UserDefinedTypeCompositeAttributeDef,
83 UserDefinedTypeInternalLength, UserDefinedTypeRangeOption, UserDefinedTypeRepresentation,
84 UserDefinedTypeSqlDefinitionOption, UserDefinedTypeStorage, ViewColumnDef,
85};
86pub use self::dml::{
87 Delete, Insert, Merge, MergeAction, MergeClause, MergeClauseKind, MergeInsertExpr,
88 MergeInsertKind, MergeUpdateExpr, MultiTableInsertIntoClause, MultiTableInsertType,
89 MultiTableInsertValue, MultiTableInsertValues, MultiTableInsertWhenClause, OutputClause,
90 Update,
91};
92pub use self::operator::{BinaryOperator, UnaryOperator};
93pub use self::query::{
94 AfterMatchSkip, ConnectByKind, Cte, CteAsMaterialized, Distinct, EmptyMatchesMode,
95 ExceptSelectItem, ExcludeSelectItem, ExprWithAlias, ExprWithAliasAndOrderBy, Fetch, ForClause,
96 ForJson, ForXml, FormatClause, GroupByExpr, GroupByWithModifier, IdentWithAlias,
97 IlikeSelectItem, InputFormatClause, Interpolate, InterpolateExpr, Join, JoinConstraint,
98 JoinOperator, JsonTableColumn, JsonTableColumnErrorHandling, JsonTableNamedColumn,
99 JsonTableNestedColumn, LateralView, LimitClause, LockClause, LockType, MatchRecognizePattern,
100 MatchRecognizeSymbol, Measure, NamedWindowDefinition, NamedWindowExpr, NonBlock, Offset,
101 OffsetRows, OpenJsonTableColumn, OrderBy, OrderByExpr, OrderByKind, OrderByOptions,
102 PipeOperator, PivotValueSource, ProjectionSelect, Query, RenameSelectItem,
103 RepetitionQuantifier, ReplaceSelectElement, ReplaceSelectItem, RowsPerMatch, Select,
104 SelectFlavor, SelectInto, SelectItem, SelectItemQualifiedWildcardKind, SelectModifiers,
105 SetExpr, SetOperator, SetQuantifier, Setting, SymbolDefinition, Table, TableAlias,
106 TableAliasColumnDef, TableFactor, TableFunctionArgs, TableIndexHintForClause,
107 TableIndexHintType, TableIndexHints, TableIndexType, TableSample, TableSampleBucket,
108 TableSampleKind, TableSampleMethod, TableSampleModifier, TableSampleQuantity, TableSampleSeed,
109 TableSampleSeedModifier, TableSampleUnit, TableVersion, TableWithJoins, Top, TopQuantity,
110 UpdateTableFromKind, ValueTableMode, Values, WildcardAdditionalOptions, With, WithFill,
111 XmlNamespaceDefinition, XmlPassingArgument, XmlPassingClause, XmlTableColumn,
112 XmlTableColumnOption,
113};
114
115pub use self::trigger::{
116 TriggerEvent, TriggerExecBody, TriggerExecBodyType, TriggerObject, TriggerPeriod,
117 TriggerReferencing, TriggerReferencingType,
118};
119
120pub use self::value::{
121 escape_double_quote_string, escape_quoted_string, DateTimeField, DollarQuotedString,
122 NormalizationForm, QuoteDelimitedString, TrimWhereField, Value, ValueWithSpan,
123};
124
125use crate::ast::helpers::key_value_options::KeyValueOptions;
126use crate::ast::helpers::stmt_data_loading::StageParamsObject;
127
128#[cfg(feature = "visitor")]
129pub use visitor::*;
130
131pub use self::data_type::GeometricTypeKind;
132
133mod data_type;
134mod dcl;
135mod ddl;
136mod dml;
137pub mod helpers;
139pub mod table_constraints;
140pub use table_constraints::{
141 CheckConstraint, ConstraintUsingIndex, ExclusionConstraint, ExclusionElement,
142 ForeignKeyConstraint, FullTextOrSpatialConstraint, IndexConstraint, PrimaryKeyConstraint,
143 TableConstraint, UniqueConstraint,
144};
145mod operator;
146mod query;
147mod spans;
148pub use spans::Spanned;
149
150pub mod comments;
151mod trigger;
152mod value;
153
154#[cfg(feature = "visitor")]
155mod visitor;
156
157pub struct DisplaySeparated<'a, T>
159where
160 T: fmt::Display,
161{
162 slice: &'a [T],
163 sep: &'static str,
164}
165
166impl<T> fmt::Display for DisplaySeparated<'_, T>
167where
168 T: fmt::Display,
169{
170 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
171 let mut delim = "";
172 for t in self.slice {
173 f.write_str(delim)?;
174 delim = self.sep;
175 t.fmt(f)?;
176 }
177 Ok(())
178 }
179}
180
181pub(crate) fn display_separated<'a, T>(slice: &'a [T], sep: &'static str) -> DisplaySeparated<'a, T>
182where
183 T: fmt::Display,
184{
185 DisplaySeparated { slice, sep }
186}
187
188pub(crate) fn display_comma_separated<T>(slice: &[T]) -> DisplaySeparated<'_, T>
189where
190 T: fmt::Display,
191{
192 DisplaySeparated { slice, sep: ", " }
193}
194
195fn format_statement_list(f: &mut fmt::Formatter, statements: &[Statement]) -> fmt::Result {
198 write!(f, "{}", display_separated(statements, "; "))?;
199 write!(f, ";")
202}
203
204#[derive(Debug, Clone)]
206#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
207#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
208pub struct Ident {
209 pub value: String,
211 pub quote_style: Option<char>,
214 pub span: Span,
216}
217
218impl PartialEq for Ident {
219 fn eq(&self, other: &Self) -> bool {
220 let Ident {
221 value,
222 quote_style,
223 span: _,
225 } = self;
226
227 value == &other.value && quote_style == &other.quote_style
228 }
229}
230
231impl core::hash::Hash for Ident {
232 fn hash<H: hash::Hasher>(&self, state: &mut H) {
233 let Ident {
234 value,
235 quote_style,
236 span: _,
238 } = self;
239
240 value.hash(state);
241 quote_style.hash(state);
242 }
243}
244
245impl Eq for Ident {}
246
247impl PartialOrd for Ident {
248 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
249 Some(self.cmp(other))
250 }
251}
252
253impl Ord for Ident {
254 fn cmp(&self, other: &Self) -> Ordering {
255 let Ident {
256 value,
257 quote_style,
258 span: _,
260 } = self;
261
262 let Ident {
263 value: other_value,
264 quote_style: other_quote_style,
265 span: _,
267 } = other;
268
269 value
271 .cmp(other_value)
272 .then_with(|| quote_style.cmp(other_quote_style))
273 }
274}
275
276impl Ident {
277 pub fn new<S>(value: S) -> Self
279 where
280 S: Into<String>,
281 {
282 Ident {
283 value: value.into(),
284 quote_style: None,
285 span: Span::empty(),
286 }
287 }
288
289 pub fn with_quote<S>(quote: char, value: S) -> Self
292 where
293 S: Into<String>,
294 {
295 assert!(quote == '\'' || quote == '"' || quote == '`' || quote == '[');
296 Ident {
297 value: value.into(),
298 quote_style: Some(quote),
299 span: Span::empty(),
300 }
301 }
302
303 pub fn with_span<S>(span: Span, value: S) -> Self
305 where
306 S: Into<String>,
307 {
308 Ident {
309 value: value.into(),
310 quote_style: None,
311 span,
312 }
313 }
314
315 pub fn with_quote_and_span<S>(quote: char, span: Span, value: S) -> Self
317 where
318 S: Into<String>,
319 {
320 assert!(quote == '\'' || quote == '"' || quote == '`' || quote == '[');
321 Ident {
322 value: value.into(),
323 quote_style: Some(quote),
324 span,
325 }
326 }
327}
328
329impl From<&str> for Ident {
330 fn from(value: &str) -> Self {
331 Ident {
332 value: value.to_string(),
333 quote_style: None,
334 span: Span::empty(),
335 }
336 }
337}
338
339impl fmt::Display for Ident {
340 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
341 match self.quote_style {
342 Some(q) if q == '"' || q == '\'' || q == '`' => {
343 let escaped = value::escape_quoted_string(&self.value, q);
344 write!(f, "{q}{escaped}{q}")
345 }
346 Some('[') => write!(f, "[{}]", self.value),
347 None => f.write_str(&self.value),
348 _ => panic!("unexpected quote style"),
349 }
350 }
351}
352
353#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
355#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
356#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
357pub struct ObjectName(pub Vec<ObjectNamePart>);
358
359impl From<Vec<Ident>> for ObjectName {
360 fn from(idents: Vec<Ident>) -> Self {
361 ObjectName(idents.into_iter().map(ObjectNamePart::Identifier).collect())
362 }
363}
364
365impl From<Ident> for ObjectName {
366 fn from(ident: Ident) -> Self {
367 ObjectName(vec![ObjectNamePart::Identifier(ident)])
368 }
369}
370
371impl fmt::Display for ObjectName {
372 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
373 write!(f, "{}", display_separated(&self.0, "."))
374 }
375}
376
377#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
379#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
380#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
381pub enum ObjectNamePart {
382 Identifier(Ident),
384 Function(ObjectNamePartFunction),
386}
387
388impl ObjectNamePart {
389 pub fn as_ident(&self) -> Option<&Ident> {
391 match self {
392 ObjectNamePart::Identifier(ident) => Some(ident),
393 ObjectNamePart::Function(_) => None,
394 }
395 }
396}
397
398impl fmt::Display for ObjectNamePart {
399 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
400 match self {
401 ObjectNamePart::Identifier(ident) => write!(f, "{ident}"),
402 ObjectNamePart::Function(func) => write!(f, "{func}"),
403 }
404 }
405}
406
407#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
412#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
413#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
414pub struct ObjectNamePartFunction {
415 pub name: Ident,
417 pub args: Vec<FunctionArg>,
419}
420
421impl fmt::Display for ObjectNamePartFunction {
422 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
423 write!(f, "{}(", self.name)?;
424 write!(f, "{})", display_comma_separated(&self.args))
425 }
426}
427
428#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
431#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
432#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
433pub struct Array {
434 pub elem: Vec<Expr>,
436
437 pub named: bool,
439}
440
441impl fmt::Display for Array {
442 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
443 write!(
444 f,
445 "{}[{}]",
446 if self.named { "ARRAY" } else { "" },
447 display_comma_separated(&self.elem)
448 )
449 }
450}
451
452#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
461#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
462#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
463pub struct Interval {
464 pub value: Box<Expr>,
466 pub leading_field: Option<DateTimeField>,
468 pub leading_precision: Option<u64>,
470 pub last_field: Option<DateTimeField>,
472 pub fractional_seconds_precision: Option<u64>,
476}
477
478impl fmt::Display for Interval {
479 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
480 let value = self.value.as_ref();
481 match (
482 &self.leading_field,
483 self.leading_precision,
484 self.fractional_seconds_precision,
485 ) {
486 (
487 Some(DateTimeField::Second),
488 Some(leading_precision),
489 Some(fractional_seconds_precision),
490 ) => {
491 assert!(self.last_field.is_none());
494 write!(
495 f,
496 "INTERVAL {value} SECOND ({leading_precision}, {fractional_seconds_precision})"
497 )
498 }
499 _ => {
500 write!(f, "INTERVAL {value}")?;
501 if let Some(leading_field) = &self.leading_field {
502 write!(f, " {leading_field}")?;
503 }
504 if let Some(leading_precision) = self.leading_precision {
505 write!(f, " ({leading_precision})")?;
506 }
507 if let Some(last_field) = &self.last_field {
508 write!(f, " TO {last_field}")?;
509 }
510 if let Some(fractional_seconds_precision) = self.fractional_seconds_precision {
511 write!(f, " ({fractional_seconds_precision})")?;
512 }
513 Ok(())
514 }
515 }
516 }
517}
518
519#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
523#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
524#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
525pub struct StructField {
526 pub field_name: Option<Ident>,
528 pub field_type: DataType,
530 pub options: Option<Vec<SqlOption>>,
533}
534
535impl fmt::Display for StructField {
536 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
537 if let Some(name) = &self.field_name {
538 write!(f, "{name} {}", self.field_type)?;
539 } else {
540 write!(f, "{}", self.field_type)?;
541 }
542 if let Some(options) = &self.options {
543 write!(f, " OPTIONS({})", display_separated(options, ", "))
544 } else {
545 Ok(())
546 }
547 }
548}
549
550#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
554#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
555#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
556pub struct UnionField {
557 pub field_name: Ident,
559 pub field_type: DataType,
561}
562
563impl fmt::Display for UnionField {
564 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
565 write!(f, "{} {}", self.field_name, self.field_type)
566 }
567}
568
569#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
573#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
574#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
575pub struct DictionaryField {
576 pub key: Ident,
578 pub value: Box<Expr>,
580}
581
582impl fmt::Display for DictionaryField {
583 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
584 write!(f, "{}: {}", self.key, self.value)
585 }
586}
587
588#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
590#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
591#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
592pub struct Map {
593 pub entries: Vec<MapEntry>,
595}
596
597impl Display for Map {
598 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
599 write!(f, "MAP {{{}}}", display_comma_separated(&self.entries))
600 }
601}
602
603#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
607#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
608#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
609pub struct MapEntry {
610 pub key: Box<Expr>,
612 pub value: Box<Expr>,
614}
615
616impl fmt::Display for MapEntry {
617 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
618 write!(f, "{}: {}", self.key, self.value)
619 }
620}
621
622#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
625#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
626#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
627pub enum CastFormat {
628 Value(ValueWithSpan),
630 ValueAtTimeZone(ValueWithSpan, ValueWithSpan),
632}
633
634#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
636#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
637#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
638pub enum JsonPathElem {
639 Dot {
643 key: String,
645 quoted: bool,
647 },
648 Bracket {
653 key: Expr,
655 },
656 ColonBracket {
661 key: Expr,
663 },
664}
665
666#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
671#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
672#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
673pub struct JsonPath {
674 pub path: Vec<JsonPathElem>,
676}
677
678impl fmt::Display for JsonPath {
679 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
680 for (i, elem) in self.path.iter().enumerate() {
681 match elem {
682 JsonPathElem::Dot { key, quoted } => {
683 if i == 0 {
684 write!(f, ":")?;
685 } else {
686 write!(f, ".")?;
687 }
688
689 if *quoted {
690 write!(f, "\"{}\"", escape_double_quote_string(key))?;
691 } else {
692 write!(f, "{key}")?;
693 }
694 }
695 JsonPathElem::Bracket { key } => {
696 write!(f, "[{key}]")?;
697 }
698 JsonPathElem::ColonBracket { key } => {
699 write!(f, ":[{key}]")?;
700 }
701 }
702 }
703 Ok(())
704 }
705}
706
707#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
709#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
710#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
711pub enum CastKind {
712 Cast,
714 TryCast,
719 SafeCast,
723 DoubleColon,
725}
726
727#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
731#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
732#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
733pub enum ConstraintReferenceMatchKind {
734 Full,
736 Partial,
738 Simple,
740}
741
742impl fmt::Display for ConstraintReferenceMatchKind {
743 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
744 match self {
745 Self::Full => write!(f, "MATCH FULL"),
746 Self::Partial => write!(f, "MATCH PARTIAL"),
747 Self::Simple => write!(f, "MATCH SIMPLE"),
748 }
749 }
750}
751
752#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
759#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
760#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
761pub enum ExtractSyntax {
762 From,
764 Comma,
766}
767
768#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
777#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
778#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
779pub enum CeilFloorKind {
780 DateTimeField(DateTimeField),
782 Scale(ValueWithSpan),
784}
785
786#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
789#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
790#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
791pub struct CaseWhen {
792 pub condition: Expr,
794 pub result: Expr,
796}
797
798impl fmt::Display for CaseWhen {
799 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
800 f.write_str("WHEN ")?;
801 self.condition.fmt(f)?;
802 f.write_str(" THEN")?;
803 SpaceOrNewline.fmt(f)?;
804 Indent(&self.result).fmt(f)?;
805 Ok(())
806 }
807}
808
809#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
827#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
828#[cfg_attr(
829 feature = "visitor",
830 derive(Visit, VisitMut),
831 visit(with = "visit_expr")
832)]
833pub enum Expr {
834 Identifier(Ident),
836 CompoundIdentifier(Vec<Ident>),
838 CompoundFieldAccess {
857 root: Box<Expr>,
859 access_chain: Vec<AccessExpr>,
861 },
862 JsonAccess {
868 value: Box<Expr>,
870 path: JsonPath,
872 },
873 IsFalse(Box<Expr>),
875 IsNotFalse(Box<Expr>),
877 IsTrue(Box<Expr>),
879 IsNotTrue(Box<Expr>),
881 IsNull(Box<Expr>),
883 IsNotNull(Box<Expr>),
885 IsUnknown(Box<Expr>),
887 IsNotUnknown(Box<Expr>),
889 IsDistinctFrom(Box<Expr>, Box<Expr>),
891 IsNotDistinctFrom(Box<Expr>, Box<Expr>),
893 IsNormalized {
895 expr: Box<Expr>,
897 form: Option<NormalizationForm>,
899 negated: bool,
901 },
902 InList {
904 expr: Box<Expr>,
906 list: Vec<Expr>,
908 negated: bool,
910 },
911 InSubquery {
913 expr: Box<Expr>,
915 subquery: Box<Query>,
917 negated: bool,
919 },
920 InUnnest {
922 expr: Box<Expr>,
924 array_expr: Box<Expr>,
926 negated: bool,
928 },
929 Between {
931 expr: Box<Expr>,
933 negated: bool,
935 low: Box<Expr>,
937 high: Box<Expr>,
939 },
940 BinaryOp {
942 left: Box<Expr>,
944 op: BinaryOperator,
946 right: Box<Expr>,
948 },
949 Like {
951 negated: bool,
953 any: bool,
956 expr: Box<Expr>,
958 pattern: Box<Expr>,
960 escape_char: Option<ValueWithSpan>,
962 },
963 ILike {
965 negated: bool,
967 any: bool,
970 expr: Box<Expr>,
972 pattern: Box<Expr>,
974 escape_char: Option<ValueWithSpan>,
976 },
977 SimilarTo {
979 negated: bool,
981 expr: Box<Expr>,
983 pattern: Box<Expr>,
985 escape_char: Option<ValueWithSpan>,
987 },
988 RLike {
990 negated: bool,
992 expr: Box<Expr>,
994 pattern: Box<Expr>,
996 regexp: bool,
998 },
999 AnyOp {
1002 left: Box<Expr>,
1004 compare_op: BinaryOperator,
1006 right: Box<Expr>,
1008 is_some: bool,
1010 },
1011 AllOp {
1014 left: Box<Expr>,
1016 compare_op: BinaryOperator,
1018 right: Box<Expr>,
1020 },
1021
1022 UnaryOp {
1024 op: UnaryOperator,
1026 expr: Box<Expr>,
1028 },
1029 Convert {
1031 is_try: bool,
1034 expr: Box<Expr>,
1036 data_type: Option<DataType>,
1038 charset: Option<ObjectName>,
1040 target_before_value: bool,
1042 styles: Vec<Expr>,
1046 },
1047 Cast {
1049 kind: CastKind,
1051 expr: Box<Expr>,
1053 data_type: DataType,
1055 array: bool,
1061 format: Option<CastFormat>,
1065 },
1066 AtTimeZone {
1068 timestamp: Box<Expr>,
1070 time_zone: Box<Expr>,
1072 },
1073 Extract {
1081 field: DateTimeField,
1083 syntax: ExtractSyntax,
1085 expr: Box<Expr>,
1087 },
1088 Ceil {
1095 expr: Box<Expr>,
1097 field: CeilFloorKind,
1099 },
1100 Floor {
1107 expr: Box<Expr>,
1109 field: CeilFloorKind,
1111 },
1112 Position {
1116 expr: Box<Expr>,
1118 r#in: Box<Expr>,
1120 },
1121 Substring {
1129 expr: Box<Expr>,
1131 substring_from: Option<Box<Expr>>,
1133 substring_for: Option<Box<Expr>>,
1135
1136 special: bool,
1140
1141 shorthand: bool,
1144 },
1145 Trim {
1151 trim_where: Option<TrimWhereField>,
1153 trim_what: Option<Box<Expr>>,
1155 expr: Box<Expr>,
1157 trim_characters: Option<Vec<Expr>>,
1159 },
1160 Overlay {
1164 expr: Box<Expr>,
1166 overlay_what: Box<Expr>,
1168 overlay_from: Box<Expr>,
1170 overlay_for: Option<Box<Expr>>,
1172 },
1173 Collate {
1175 expr: Box<Expr>,
1177 collation: ObjectName,
1179 },
1180 Nested(Box<Expr>),
1182 Value(ValueWithSpan),
1184 Prefixed {
1188 prefix: Ident,
1190 value: Box<Expr>,
1193 },
1194 TypedString(TypedString),
1198 Function(Function),
1200 Case {
1206 case_token: AttachedToken,
1208 end_token: AttachedToken,
1210 operand: Option<Box<Expr>>,
1212 conditions: Vec<CaseWhen>,
1214 else_result: Option<Box<Expr>>,
1216 },
1217 Exists {
1220 subquery: Box<Query>,
1222 negated: bool,
1224 },
1225 Subquery(Box<Query>),
1228 GroupingSets(Vec<Vec<Expr>>),
1230 Cube(Vec<Vec<Expr>>),
1232 Rollup(Vec<Vec<Expr>>),
1234 Tuple(Vec<Expr>),
1236 Struct {
1245 values: Vec<Expr>,
1247 fields: Vec<StructField>,
1249 },
1250 Named {
1258 expr: Box<Expr>,
1260 name: Ident,
1262 },
1263 Dictionary(Vec<DictionaryField>),
1271 Map(Map),
1279 Array(Array),
1281 Interval(Interval),
1283 MatchAgainst {
1294 columns: Vec<ObjectName>,
1296 match_value: ValueWithSpan,
1298 opt_search_modifier: Option<SearchModifier>,
1300 },
1301 Wildcard(AttachedToken),
1303 QualifiedWildcard(ObjectName, AttachedToken),
1306 OuterJoin(Box<Expr>),
1321 Prior(Box<Expr>),
1323 Lambda(LambdaFunction),
1334 MemberOf(MemberOf),
1336}
1337
1338impl Expr {
1339 pub fn value(value: impl Into<ValueWithSpan>) -> Self {
1341 Expr::Value(value.into())
1342 }
1343}
1344
1345#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1347#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1348#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1349pub enum Subscript {
1350 Index {
1352 index: Expr,
1354 },
1355
1356 Slice {
1378 lower_bound: Option<Expr>,
1380 upper_bound: Option<Expr>,
1382 stride: Option<Expr>,
1384 },
1385}
1386
1387impl fmt::Display for Subscript {
1388 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1389 match self {
1390 Subscript::Index { index } => write!(f, "{index}"),
1391 Subscript::Slice {
1392 lower_bound,
1393 upper_bound,
1394 stride,
1395 } => {
1396 if let Some(lower) = lower_bound {
1397 write!(f, "{lower}")?;
1398 }
1399 write!(f, ":")?;
1400 if let Some(upper) = upper_bound {
1401 write!(f, "{upper}")?;
1402 }
1403 if let Some(stride) = stride {
1404 write!(f, ":")?;
1405 write!(f, "{stride}")?;
1406 }
1407 Ok(())
1408 }
1409 }
1410 }
1411}
1412
1413#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1416#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1417#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1418pub enum AccessExpr {
1419 Dot(Expr),
1421 Subscript(Subscript),
1423}
1424
1425impl fmt::Display for AccessExpr {
1426 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1427 match self {
1428 AccessExpr::Dot(expr) => write!(f, ".{expr}"),
1429 AccessExpr::Subscript(subscript) => write!(f, "[{subscript}]"),
1430 }
1431 }
1432}
1433
1434#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1436#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1437#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1438pub struct LambdaFunction {
1439 pub params: OneOrManyWithParens<LambdaFunctionParameter>,
1441 pub body: Box<Expr>,
1443 pub syntax: LambdaSyntax,
1445}
1446
1447impl fmt::Display for LambdaFunction {
1448 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1449 match self.syntax {
1450 LambdaSyntax::Arrow => write!(f, "{} -> {}", self.params, self.body),
1451 LambdaSyntax::LambdaKeyword => {
1452 write!(f, "lambda ")?;
1455 match &self.params {
1456 OneOrManyWithParens::One(p) => write!(f, "{p}")?,
1457 OneOrManyWithParens::Many(ps) => write!(f, "{}", display_comma_separated(ps))?,
1458 };
1459 write!(f, " : {}", self.body)
1460 }
1461 }
1462 }
1463}
1464
1465#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1467#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1468#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1469pub struct LambdaFunctionParameter {
1470 pub name: Ident,
1472 pub data_type: Option<DataType>,
1475}
1476
1477impl fmt::Display for LambdaFunctionParameter {
1478 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1479 match &self.data_type {
1480 Some(dt) => write!(f, "{} {}", self.name, dt),
1481 None => write!(f, "{}", self.name),
1482 }
1483 }
1484}
1485
1486#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy)]
1488#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1489#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1490pub enum LambdaSyntax {
1491 Arrow,
1498 LambdaKeyword,
1503}
1504
1505#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1528#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1529#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1530pub enum OneOrManyWithParens<T> {
1531 One(T),
1533 Many(Vec<T>),
1535}
1536
1537impl<T> Deref for OneOrManyWithParens<T> {
1538 type Target = [T];
1539
1540 fn deref(&self) -> &[T] {
1541 match self {
1542 OneOrManyWithParens::One(one) => core::slice::from_ref(one),
1543 OneOrManyWithParens::Many(many) => many,
1544 }
1545 }
1546}
1547
1548impl<T> AsRef<[T]> for OneOrManyWithParens<T> {
1549 fn as_ref(&self) -> &[T] {
1550 self
1551 }
1552}
1553
1554impl<'a, T> IntoIterator for &'a OneOrManyWithParens<T> {
1555 type Item = &'a T;
1556 type IntoIter = core::slice::Iter<'a, T>;
1557
1558 fn into_iter(self) -> Self::IntoIter {
1559 self.iter()
1560 }
1561}
1562
1563#[derive(Debug, Clone)]
1565pub struct OneOrManyWithParensIntoIter<T> {
1566 inner: OneOrManyWithParensIntoIterInner<T>,
1567}
1568
1569#[derive(Debug, Clone)]
1570enum OneOrManyWithParensIntoIterInner<T> {
1571 One(core::iter::Once<T>),
1572 Many(<Vec<T> as IntoIterator>::IntoIter),
1573}
1574
1575impl<T> core::iter::FusedIterator for OneOrManyWithParensIntoIter<T>
1576where
1577 core::iter::Once<T>: core::iter::FusedIterator,
1578 <Vec<T> as IntoIterator>::IntoIter: core::iter::FusedIterator,
1579{
1580}
1581
1582impl<T> core::iter::ExactSizeIterator for OneOrManyWithParensIntoIter<T>
1583where
1584 core::iter::Once<T>: core::iter::ExactSizeIterator,
1585 <Vec<T> as IntoIterator>::IntoIter: core::iter::ExactSizeIterator,
1586{
1587}
1588
1589impl<T> core::iter::Iterator for OneOrManyWithParensIntoIter<T> {
1590 type Item = T;
1591
1592 fn next(&mut self) -> Option<Self::Item> {
1593 match &mut self.inner {
1594 OneOrManyWithParensIntoIterInner::One(one) => one.next(),
1595 OneOrManyWithParensIntoIterInner::Many(many) => many.next(),
1596 }
1597 }
1598
1599 fn size_hint(&self) -> (usize, Option<usize>) {
1600 match &self.inner {
1601 OneOrManyWithParensIntoIterInner::One(one) => one.size_hint(),
1602 OneOrManyWithParensIntoIterInner::Many(many) => many.size_hint(),
1603 }
1604 }
1605
1606 fn count(self) -> usize
1607 where
1608 Self: Sized,
1609 {
1610 match self.inner {
1611 OneOrManyWithParensIntoIterInner::One(one) => one.count(),
1612 OneOrManyWithParensIntoIterInner::Many(many) => many.count(),
1613 }
1614 }
1615
1616 fn fold<B, F>(mut self, init: B, f: F) -> B
1617 where
1618 Self: Sized,
1619 F: FnMut(B, Self::Item) -> B,
1620 {
1621 match &mut self.inner {
1622 OneOrManyWithParensIntoIterInner::One(one) => one.fold(init, f),
1623 OneOrManyWithParensIntoIterInner::Many(many) => many.fold(init, f),
1624 }
1625 }
1626}
1627
1628impl<T> core::iter::DoubleEndedIterator for OneOrManyWithParensIntoIter<T> {
1629 fn next_back(&mut self) -> Option<Self::Item> {
1630 match &mut self.inner {
1631 OneOrManyWithParensIntoIterInner::One(one) => one.next_back(),
1632 OneOrManyWithParensIntoIterInner::Many(many) => many.next_back(),
1633 }
1634 }
1635}
1636
1637impl<T> IntoIterator for OneOrManyWithParens<T> {
1638 type Item = T;
1639
1640 type IntoIter = OneOrManyWithParensIntoIter<T>;
1641
1642 fn into_iter(self) -> Self::IntoIter {
1643 let inner = match self {
1644 OneOrManyWithParens::One(one) => {
1645 OneOrManyWithParensIntoIterInner::One(core::iter::once(one))
1646 }
1647 OneOrManyWithParens::Many(many) => {
1648 OneOrManyWithParensIntoIterInner::Many(many.into_iter())
1649 }
1650 };
1651
1652 OneOrManyWithParensIntoIter { inner }
1653 }
1654}
1655
1656impl<T> fmt::Display for OneOrManyWithParens<T>
1657where
1658 T: fmt::Display,
1659{
1660 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1661 match self {
1662 OneOrManyWithParens::One(value) => write!(f, "{value}"),
1663 OneOrManyWithParens::Many(values) => {
1664 write!(f, "({})", display_comma_separated(values))
1665 }
1666 }
1667 }
1668}
1669
1670impl fmt::Display for CastFormat {
1671 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1672 match self {
1673 CastFormat::Value(v) => write!(f, "{v}"),
1674 CastFormat::ValueAtTimeZone(v, tz) => write!(f, "{v} AT TIME ZONE {tz}"),
1675 }
1676 }
1677}
1678
1679impl fmt::Display for Expr {
1680 #[cfg_attr(feature = "recursive-protection", recursive::recursive)]
1681 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1682 match self {
1683 Expr::Identifier(s) => write!(f, "{s}"),
1684 Expr::Wildcard(_) => f.write_str("*"),
1685 Expr::QualifiedWildcard(prefix, _) => write!(f, "{prefix}.*"),
1686 Expr::CompoundIdentifier(s) => write!(f, "{}", display_separated(s, ".")),
1687 Expr::CompoundFieldAccess { root, access_chain } => {
1688 write!(f, "{root}")?;
1689 for field in access_chain {
1690 write!(f, "{field}")?;
1691 }
1692 Ok(())
1693 }
1694 Expr::IsTrue(ast) => write!(f, "{ast} IS TRUE"),
1695 Expr::IsNotTrue(ast) => write!(f, "{ast} IS NOT TRUE"),
1696 Expr::IsFalse(ast) => write!(f, "{ast} IS FALSE"),
1697 Expr::IsNotFalse(ast) => write!(f, "{ast} IS NOT FALSE"),
1698 Expr::IsNull(ast) => write!(f, "{ast} IS NULL"),
1699 Expr::IsNotNull(ast) => write!(f, "{ast} IS NOT NULL"),
1700 Expr::IsUnknown(ast) => write!(f, "{ast} IS UNKNOWN"),
1701 Expr::IsNotUnknown(ast) => write!(f, "{ast} IS NOT UNKNOWN"),
1702 Expr::InList {
1703 expr,
1704 list,
1705 negated,
1706 } => write!(
1707 f,
1708 "{} {}IN ({})",
1709 expr,
1710 if *negated { "NOT " } else { "" },
1711 display_comma_separated(list)
1712 ),
1713 Expr::InSubquery {
1714 expr,
1715 subquery,
1716 negated,
1717 } => write!(
1718 f,
1719 "{} {}IN ({})",
1720 expr,
1721 if *negated { "NOT " } else { "" },
1722 subquery
1723 ),
1724 Expr::InUnnest {
1725 expr,
1726 array_expr,
1727 negated,
1728 } => write!(
1729 f,
1730 "{} {}IN UNNEST({})",
1731 expr,
1732 if *negated { "NOT " } else { "" },
1733 array_expr
1734 ),
1735 Expr::Between {
1736 expr,
1737 negated,
1738 low,
1739 high,
1740 } => write!(
1741 f,
1742 "{} {}BETWEEN {} AND {}",
1743 expr,
1744 if *negated { "NOT " } else { "" },
1745 low,
1746 high
1747 ),
1748 Expr::BinaryOp { left, op, right } => write!(f, "{left} {op} {right}"),
1749 Expr::Like {
1750 negated,
1751 expr,
1752 pattern,
1753 escape_char,
1754 any,
1755 } => match escape_char {
1756 Some(ch) => write!(
1757 f,
1758 "{} {}LIKE {}{} ESCAPE {}",
1759 expr,
1760 if *negated { "NOT " } else { "" },
1761 if *any { "ANY " } else { "" },
1762 pattern,
1763 ch
1764 ),
1765 _ => write!(
1766 f,
1767 "{} {}LIKE {}{}",
1768 expr,
1769 if *negated { "NOT " } else { "" },
1770 if *any { "ANY " } else { "" },
1771 pattern
1772 ),
1773 },
1774 Expr::ILike {
1775 negated,
1776 expr,
1777 pattern,
1778 escape_char,
1779 any,
1780 } => match escape_char {
1781 Some(ch) => write!(
1782 f,
1783 "{} {}ILIKE {}{} ESCAPE {}",
1784 expr,
1785 if *negated { "NOT " } else { "" },
1786 if *any { "ANY" } else { "" },
1787 pattern,
1788 ch
1789 ),
1790 _ => write!(
1791 f,
1792 "{} {}ILIKE {}{}",
1793 expr,
1794 if *negated { "NOT " } else { "" },
1795 if *any { "ANY " } else { "" },
1796 pattern
1797 ),
1798 },
1799 Expr::RLike {
1800 negated,
1801 expr,
1802 pattern,
1803 regexp,
1804 } => write!(
1805 f,
1806 "{} {}{} {}",
1807 expr,
1808 if *negated { "NOT " } else { "" },
1809 if *regexp { "REGEXP" } else { "RLIKE" },
1810 pattern
1811 ),
1812 Expr::IsNormalized {
1813 expr,
1814 form,
1815 negated,
1816 } => {
1817 let not_ = if *negated { "NOT " } else { "" };
1818 if form.is_none() {
1819 write!(f, "{expr} IS {not_}NORMALIZED")
1820 } else {
1821 write!(
1822 f,
1823 "{} IS {}{} NORMALIZED",
1824 expr,
1825 not_,
1826 form.as_ref().unwrap()
1827 )
1828 }
1829 }
1830 Expr::SimilarTo {
1831 negated,
1832 expr,
1833 pattern,
1834 escape_char,
1835 } => match escape_char {
1836 Some(ch) => write!(
1837 f,
1838 "{} {}SIMILAR TO {} ESCAPE {}",
1839 expr,
1840 if *negated { "NOT " } else { "" },
1841 pattern,
1842 ch
1843 ),
1844 _ => write!(
1845 f,
1846 "{} {}SIMILAR TO {}",
1847 expr,
1848 if *negated { "NOT " } else { "" },
1849 pattern
1850 ),
1851 },
1852 Expr::AnyOp {
1853 left,
1854 compare_op,
1855 right,
1856 is_some,
1857 } => {
1858 let add_parens = !matches!(right.as_ref(), Expr::Subquery(_));
1859 write!(
1860 f,
1861 "{left} {compare_op} {}{}{right}{}",
1862 if *is_some { "SOME" } else { "ANY" },
1863 if add_parens { "(" } else { "" },
1864 if add_parens { ")" } else { "" },
1865 )
1866 }
1867 Expr::AllOp {
1868 left,
1869 compare_op,
1870 right,
1871 } => {
1872 let add_parens = !matches!(right.as_ref(), Expr::Subquery(_));
1873 write!(
1874 f,
1875 "{left} {compare_op} ALL{}{right}{}",
1876 if add_parens { "(" } else { "" },
1877 if add_parens { ")" } else { "" },
1878 )
1879 }
1880 Expr::UnaryOp { op, expr } => {
1881 if op == &UnaryOperator::PGPostfixFactorial {
1882 write!(f, "{expr}{op}")
1883 } else if matches!(
1884 op,
1885 UnaryOperator::Not
1886 | UnaryOperator::Hash
1887 | UnaryOperator::AtDashAt
1888 | UnaryOperator::DoubleAt
1889 | UnaryOperator::QuestionDash
1890 | UnaryOperator::QuestionPipe
1891 ) {
1892 write!(f, "{op} {expr}")
1893 } else {
1894 write!(f, "{op}{expr}")
1895 }
1896 }
1897 Expr::Convert {
1898 is_try,
1899 expr,
1900 target_before_value,
1901 data_type,
1902 charset,
1903 styles,
1904 } => {
1905 write!(f, "{}CONVERT(", if *is_try { "TRY_" } else { "" })?;
1906 if let Some(data_type) = data_type {
1907 if let Some(charset) = charset {
1908 write!(f, "{expr}, {data_type} CHARACTER SET {charset}")
1909 } else if *target_before_value {
1910 write!(f, "{data_type}, {expr}")
1911 } else {
1912 write!(f, "{expr}, {data_type}")
1913 }
1914 } else if let Some(charset) = charset {
1915 write!(f, "{expr} USING {charset}")
1916 } else {
1917 write!(f, "{expr}") }?;
1919 if !styles.is_empty() {
1920 write!(f, ", {}", display_comma_separated(styles))?;
1921 }
1922 write!(f, ")")
1923 }
1924 Expr::Cast {
1925 kind,
1926 expr,
1927 data_type,
1928 array,
1929 format,
1930 } => match kind {
1931 CastKind::Cast => {
1932 write!(f, "CAST({expr} AS {data_type}")?;
1933 if *array {
1934 write!(f, " ARRAY")?;
1935 }
1936 if let Some(format) = format {
1937 write!(f, " FORMAT {format}")?;
1938 }
1939 write!(f, ")")
1940 }
1941 CastKind::TryCast => {
1942 if let Some(format) = format {
1943 write!(f, "TRY_CAST({expr} AS {data_type} FORMAT {format})")
1944 } else {
1945 write!(f, "TRY_CAST({expr} AS {data_type})")
1946 }
1947 }
1948 CastKind::SafeCast => {
1949 if let Some(format) = format {
1950 write!(f, "SAFE_CAST({expr} AS {data_type} FORMAT {format})")
1951 } else {
1952 write!(f, "SAFE_CAST({expr} AS {data_type})")
1953 }
1954 }
1955 CastKind::DoubleColon => {
1956 write!(f, "{expr}::{data_type}")
1957 }
1958 },
1959 Expr::Extract {
1960 field,
1961 syntax,
1962 expr,
1963 } => match syntax {
1964 ExtractSyntax::From => write!(f, "EXTRACT({field} FROM {expr})"),
1965 ExtractSyntax::Comma => write!(f, "EXTRACT({field}, {expr})"),
1966 },
1967 Expr::Ceil { expr, field } => match field {
1968 CeilFloorKind::DateTimeField(DateTimeField::NoDateTime) => {
1969 write!(f, "CEIL({expr})")
1970 }
1971 CeilFloorKind::DateTimeField(dt_field) => write!(f, "CEIL({expr} TO {dt_field})"),
1972 CeilFloorKind::Scale(s) => write!(f, "CEIL({expr}, {s})"),
1973 },
1974 Expr::Floor { expr, field } => match field {
1975 CeilFloorKind::DateTimeField(DateTimeField::NoDateTime) => {
1976 write!(f, "FLOOR({expr})")
1977 }
1978 CeilFloorKind::DateTimeField(dt_field) => write!(f, "FLOOR({expr} TO {dt_field})"),
1979 CeilFloorKind::Scale(s) => write!(f, "FLOOR({expr}, {s})"),
1980 },
1981 Expr::Position { expr, r#in } => write!(f, "POSITION({expr} IN {in})"),
1982 Expr::Collate { expr, collation } => write!(f, "{expr} COLLATE {collation}"),
1983 Expr::Nested(ast) => write!(f, "({ast})"),
1984 Expr::Value(v) => write!(f, "{v}"),
1985 Expr::Prefixed { prefix, value } => write!(f, "{prefix} {value}"),
1986 Expr::TypedString(ts) => ts.fmt(f),
1987 Expr::Function(fun) => fun.fmt(f),
1988 Expr::Case {
1989 case_token: _,
1990 end_token: _,
1991 operand,
1992 conditions,
1993 else_result,
1994 } => {
1995 f.write_str("CASE")?;
1996 if let Some(operand) = operand {
1997 f.write_str(" ")?;
1998 operand.fmt(f)?;
1999 }
2000 for when in conditions {
2001 SpaceOrNewline.fmt(f)?;
2002 Indent(when).fmt(f)?;
2003 }
2004 if let Some(else_result) = else_result {
2005 SpaceOrNewline.fmt(f)?;
2006 Indent("ELSE").fmt(f)?;
2007 SpaceOrNewline.fmt(f)?;
2008 Indent(Indent(else_result)).fmt(f)?;
2009 }
2010 SpaceOrNewline.fmt(f)?;
2011 f.write_str("END")
2012 }
2013 Expr::Exists { subquery, negated } => write!(
2014 f,
2015 "{}EXISTS ({})",
2016 if *negated { "NOT " } else { "" },
2017 subquery
2018 ),
2019 Expr::Subquery(s) => write!(f, "({s})"),
2020 Expr::GroupingSets(sets) => {
2021 write!(f, "GROUPING SETS (")?;
2022 let mut sep = "";
2023 for set in sets {
2024 write!(f, "{sep}")?;
2025 sep = ", ";
2026 write!(f, "({})", display_comma_separated(set))?;
2027 }
2028 write!(f, ")")
2029 }
2030 Expr::Cube(sets) => {
2031 write!(f, "CUBE (")?;
2032 let mut sep = "";
2033 for set in sets {
2034 write!(f, "{sep}")?;
2035 sep = ", ";
2036 if set.len() == 1 {
2037 write!(f, "{}", set[0])?;
2038 } else {
2039 write!(f, "({})", display_comma_separated(set))?;
2040 }
2041 }
2042 write!(f, ")")
2043 }
2044 Expr::Rollup(sets) => {
2045 write!(f, "ROLLUP (")?;
2046 let mut sep = "";
2047 for set in sets {
2048 write!(f, "{sep}")?;
2049 sep = ", ";
2050 if set.len() == 1 {
2051 write!(f, "{}", set[0])?;
2052 } else {
2053 write!(f, "({})", display_comma_separated(set))?;
2054 }
2055 }
2056 write!(f, ")")
2057 }
2058 Expr::Substring {
2059 expr,
2060 substring_from,
2061 substring_for,
2062 special,
2063 shorthand,
2064 } => {
2065 f.write_str("SUBSTR")?;
2066 if !*shorthand {
2067 f.write_str("ING")?;
2068 }
2069 write!(f, "({expr}")?;
2070 if let Some(from_part) = substring_from {
2071 if *special {
2072 write!(f, ", {from_part}")?;
2073 } else {
2074 write!(f, " FROM {from_part}")?;
2075 }
2076 }
2077 if let Some(for_part) = substring_for {
2078 if *special {
2079 write!(f, ", {for_part}")?;
2080 } else {
2081 write!(f, " FOR {for_part}")?;
2082 }
2083 }
2084
2085 write!(f, ")")
2086 }
2087 Expr::Overlay {
2088 expr,
2089 overlay_what,
2090 overlay_from,
2091 overlay_for,
2092 } => {
2093 write!(
2094 f,
2095 "OVERLAY({expr} PLACING {overlay_what} FROM {overlay_from}"
2096 )?;
2097 if let Some(for_part) = overlay_for {
2098 write!(f, " FOR {for_part}")?;
2099 }
2100
2101 write!(f, ")")
2102 }
2103 Expr::IsDistinctFrom(a, b) => write!(f, "{a} IS DISTINCT FROM {b}"),
2104 Expr::IsNotDistinctFrom(a, b) => write!(f, "{a} IS NOT DISTINCT FROM {b}"),
2105 Expr::Trim {
2106 expr,
2107 trim_where,
2108 trim_what,
2109 trim_characters,
2110 } => {
2111 write!(f, "TRIM(")?;
2112 if let Some(ident) = trim_where {
2113 write!(f, "{ident} ")?;
2114 }
2115 if let Some(trim_char) = trim_what {
2116 write!(f, "{trim_char} FROM {expr}")?;
2117 } else {
2118 write!(f, "{expr}")?;
2119 }
2120 if let Some(characters) = trim_characters {
2121 write!(f, ", {}", display_comma_separated(characters))?;
2122 }
2123
2124 write!(f, ")")
2125 }
2126 Expr::Tuple(exprs) => {
2127 write!(f, "({})", display_comma_separated(exprs))
2128 }
2129 Expr::Struct { values, fields } => {
2130 if !fields.is_empty() {
2131 write!(
2132 f,
2133 "STRUCT<{}>({})",
2134 display_comma_separated(fields),
2135 display_comma_separated(values)
2136 )
2137 } else {
2138 write!(f, "STRUCT({})", display_comma_separated(values))
2139 }
2140 }
2141 Expr::Named { expr, name } => {
2142 write!(f, "{expr} AS {name}")
2143 }
2144 Expr::Dictionary(fields) => {
2145 write!(f, "{{{}}}", display_comma_separated(fields))
2146 }
2147 Expr::Map(map) => {
2148 write!(f, "{map}")
2149 }
2150 Expr::Array(set) => {
2151 write!(f, "{set}")
2152 }
2153 Expr::JsonAccess { value, path } => {
2154 write!(f, "{value}{path}")
2155 }
2156 Expr::AtTimeZone {
2157 timestamp,
2158 time_zone,
2159 } => {
2160 write!(f, "{timestamp} AT TIME ZONE {time_zone}")
2161 }
2162 Expr::Interval(interval) => {
2163 write!(f, "{interval}")
2164 }
2165 Expr::MatchAgainst {
2166 columns,
2167 match_value: match_expr,
2168 opt_search_modifier,
2169 } => {
2170 write!(f, "MATCH ({}) AGAINST ", display_comma_separated(columns),)?;
2171
2172 if let Some(search_modifier) = opt_search_modifier {
2173 write!(f, "({match_expr} {search_modifier})")?;
2174 } else {
2175 write!(f, "({match_expr})")?;
2176 }
2177
2178 Ok(())
2179 }
2180 Expr::OuterJoin(expr) => {
2181 write!(f, "{expr} (+)")
2182 }
2183 Expr::Prior(expr) => write!(f, "PRIOR {expr}"),
2184 Expr::Lambda(lambda) => write!(f, "{lambda}"),
2185 Expr::MemberOf(member_of) => write!(f, "{member_of}"),
2186 }
2187 }
2188}
2189
2190#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2199#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2200#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2201pub enum WindowType {
2202 WindowSpec(WindowSpec),
2204 NamedWindow(Ident),
2206}
2207
2208impl Display for WindowType {
2209 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2210 match self {
2211 WindowType::WindowSpec(spec) => {
2212 f.write_str("(")?;
2213 NewLine.fmt(f)?;
2214 Indent(spec).fmt(f)?;
2215 NewLine.fmt(f)?;
2216 f.write_str(")")
2217 }
2218 WindowType::NamedWindow(name) => name.fmt(f),
2219 }
2220 }
2221}
2222
2223#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2225#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2226#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2227pub struct WindowSpec {
2228 pub window_name: Option<Ident>,
2236 pub partition_by: Vec<Expr>,
2238 pub order_by: Vec<OrderByExpr>,
2240 pub window_frame: Option<WindowFrame>,
2242}
2243
2244impl fmt::Display for WindowSpec {
2245 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2246 let mut is_first = true;
2247 if let Some(window_name) = &self.window_name {
2248 if !is_first {
2249 SpaceOrNewline.fmt(f)?;
2250 }
2251 is_first = false;
2252 write!(f, "{window_name}")?;
2253 }
2254 if !self.partition_by.is_empty() {
2255 if !is_first {
2256 SpaceOrNewline.fmt(f)?;
2257 }
2258 is_first = false;
2259 write!(
2260 f,
2261 "PARTITION BY {}",
2262 display_comma_separated(&self.partition_by)
2263 )?;
2264 }
2265 if !self.order_by.is_empty() {
2266 if !is_first {
2267 SpaceOrNewline.fmt(f)?;
2268 }
2269 is_first = false;
2270 write!(f, "ORDER BY {}", display_comma_separated(&self.order_by))?;
2271 }
2272 if let Some(window_frame) = &self.window_frame {
2273 if !is_first {
2274 SpaceOrNewline.fmt(f)?;
2275 }
2276 if let Some(end_bound) = &window_frame.end_bound {
2277 write!(
2278 f,
2279 "{} BETWEEN {} AND {}",
2280 window_frame.units, window_frame.start_bound, end_bound
2281 )?;
2282 } else {
2283 write!(f, "{} {}", window_frame.units, window_frame.start_bound)?;
2284 }
2285 }
2286 Ok(())
2287 }
2288}
2289
2290#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2296#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2297#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2298pub struct WindowFrame {
2299 pub units: WindowFrameUnits,
2301 pub start_bound: WindowFrameBound,
2303 pub end_bound: Option<WindowFrameBound>,
2307 }
2309
2310impl Default for WindowFrame {
2311 fn default() -> Self {
2315 Self {
2316 units: WindowFrameUnits::Range,
2317 start_bound: WindowFrameBound::Preceding(None),
2318 end_bound: None,
2319 }
2320 }
2321}
2322
2323#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2324#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2325#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2326pub enum WindowFrameUnits {
2328 Rows,
2330 Range,
2332 Groups,
2334}
2335
2336impl fmt::Display for WindowFrameUnits {
2337 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2338 f.write_str(match self {
2339 WindowFrameUnits::Rows => "ROWS",
2340 WindowFrameUnits::Range => "RANGE",
2341 WindowFrameUnits::Groups => "GROUPS",
2342 })
2343 }
2344}
2345
2346#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2350#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2351#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2352pub enum NullTreatment {
2354 IgnoreNulls,
2356 RespectNulls,
2358}
2359
2360impl fmt::Display for NullTreatment {
2361 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2362 f.write_str(match self {
2363 NullTreatment::IgnoreNulls => "IGNORE NULLS",
2364 NullTreatment::RespectNulls => "RESPECT NULLS",
2365 })
2366 }
2367}
2368
2369#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2371#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2372#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2373pub enum WindowFrameBound {
2374 CurrentRow,
2376 Preceding(Option<Box<Expr>>),
2378 Following(Option<Box<Expr>>),
2380}
2381
2382impl fmt::Display for WindowFrameBound {
2383 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2384 match self {
2385 WindowFrameBound::CurrentRow => f.write_str("CURRENT ROW"),
2386 WindowFrameBound::Preceding(None) => f.write_str("UNBOUNDED PRECEDING"),
2387 WindowFrameBound::Following(None) => f.write_str("UNBOUNDED FOLLOWING"),
2388 WindowFrameBound::Preceding(Some(n)) => write!(f, "{n} PRECEDING"),
2389 WindowFrameBound::Following(Some(n)) => write!(f, "{n} FOLLOWING"),
2390 }
2391 }
2392}
2393
2394#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2395#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2396#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2397pub enum AddDropSync {
2399 ADD,
2401 DROP,
2403 SYNC,
2405}
2406
2407impl fmt::Display for AddDropSync {
2408 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2409 match self {
2410 AddDropSync::SYNC => f.write_str("SYNC PARTITIONS"),
2411 AddDropSync::DROP => f.write_str("DROP PARTITIONS"),
2412 AddDropSync::ADD => f.write_str("ADD PARTITIONS"),
2413 }
2414 }
2415}
2416
2417#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2418#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2419#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2420pub enum ShowCreateObject {
2422 Event,
2424 Function,
2426 Procedure,
2428 Table,
2430 Trigger,
2432 View,
2434}
2435
2436impl fmt::Display for ShowCreateObject {
2437 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2438 match self {
2439 ShowCreateObject::Event => f.write_str("EVENT"),
2440 ShowCreateObject::Function => f.write_str("FUNCTION"),
2441 ShowCreateObject::Procedure => f.write_str("PROCEDURE"),
2442 ShowCreateObject::Table => f.write_str("TABLE"),
2443 ShowCreateObject::Trigger => f.write_str("TRIGGER"),
2444 ShowCreateObject::View => f.write_str("VIEW"),
2445 }
2446 }
2447}
2448
2449#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2450#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2451#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2452pub enum CommentObject {
2454 Collation,
2456 Column,
2458 Database,
2460 Domain,
2462 Extension,
2464 Function,
2466 Index,
2468 MaterializedView,
2470 Procedure,
2472 Role,
2474 Schema,
2476 Sequence,
2478 Table,
2480 Type,
2482 User,
2484 View,
2486}
2487
2488impl fmt::Display for CommentObject {
2489 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2490 match self {
2491 CommentObject::Collation => f.write_str("COLLATION"),
2492 CommentObject::Column => f.write_str("COLUMN"),
2493 CommentObject::Database => f.write_str("DATABASE"),
2494 CommentObject::Domain => f.write_str("DOMAIN"),
2495 CommentObject::Extension => f.write_str("EXTENSION"),
2496 CommentObject::Function => f.write_str("FUNCTION"),
2497 CommentObject::Index => f.write_str("INDEX"),
2498 CommentObject::MaterializedView => f.write_str("MATERIALIZED VIEW"),
2499 CommentObject::Procedure => f.write_str("PROCEDURE"),
2500 CommentObject::Role => f.write_str("ROLE"),
2501 CommentObject::Schema => f.write_str("SCHEMA"),
2502 CommentObject::Sequence => f.write_str("SEQUENCE"),
2503 CommentObject::Table => f.write_str("TABLE"),
2504 CommentObject::Type => f.write_str("TYPE"),
2505 CommentObject::User => f.write_str("USER"),
2506 CommentObject::View => f.write_str("VIEW"),
2507 }
2508 }
2509}
2510
2511#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2512#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2513#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2514pub enum Password {
2516 Password(Expr),
2518 NullPassword,
2520}
2521
2522#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2539#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2540#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2541pub struct CaseStatement {
2542 pub case_token: AttachedToken,
2544 pub match_expr: Option<Expr>,
2546 pub when_blocks: Vec<ConditionalStatementBlock>,
2548 pub else_block: Option<ConditionalStatementBlock>,
2550 pub end_case_token: AttachedToken,
2552}
2553
2554impl fmt::Display for CaseStatement {
2555 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2556 let CaseStatement {
2557 case_token: _,
2558 match_expr,
2559 when_blocks,
2560 else_block,
2561 end_case_token: AttachedToken(end),
2562 } = self;
2563
2564 write!(f, "CASE")?;
2565
2566 if let Some(expr) = match_expr {
2567 write!(f, " {expr}")?;
2568 }
2569
2570 if !when_blocks.is_empty() {
2571 write!(f, " {}", display_separated(when_blocks, " "))?;
2572 }
2573
2574 if let Some(else_block) = else_block {
2575 write!(f, " {else_block}")?;
2576 }
2577
2578 write!(f, " END")?;
2579
2580 if let Token::Word(w) = &end.token {
2581 if w.keyword == Keyword::CASE {
2582 write!(f, " CASE")?;
2583 }
2584 }
2585
2586 Ok(())
2587 }
2588}
2589
2590#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2612#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2613#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2614pub struct IfStatement {
2615 pub if_block: ConditionalStatementBlock,
2617 pub elseif_blocks: Vec<ConditionalStatementBlock>,
2619 pub else_block: Option<ConditionalStatementBlock>,
2621 pub end_token: Option<AttachedToken>,
2623}
2624
2625impl fmt::Display for IfStatement {
2626 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2627 let IfStatement {
2628 if_block,
2629 elseif_blocks,
2630 else_block,
2631 end_token,
2632 } = self;
2633
2634 write!(f, "{if_block}")?;
2635
2636 for elseif_block in elseif_blocks {
2637 write!(f, " {elseif_block}")?;
2638 }
2639
2640 if let Some(else_block) = else_block {
2641 write!(f, " {else_block}")?;
2642 }
2643
2644 if let Some(AttachedToken(end_token)) = end_token {
2645 write!(f, " END {end_token}")?;
2646 }
2647
2648 Ok(())
2649 }
2650}
2651
2652#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2664#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2665#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2666pub struct WhileStatement {
2667 pub while_block: ConditionalStatementBlock,
2669}
2670
2671impl fmt::Display for WhileStatement {
2672 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2673 let WhileStatement { while_block } = self;
2674 write!(f, "{while_block}")?;
2675 Ok(())
2676 }
2677}
2678
2679#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2704#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2705#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2706pub struct ConditionalStatementBlock {
2707 pub start_token: AttachedToken,
2709 pub condition: Option<Expr>,
2711 pub then_token: Option<AttachedToken>,
2713 pub conditional_statements: ConditionalStatements,
2715}
2716
2717impl ConditionalStatementBlock {
2718 pub fn statements(&self) -> &Vec<Statement> {
2720 self.conditional_statements.statements()
2721 }
2722}
2723
2724impl fmt::Display for ConditionalStatementBlock {
2725 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2726 let ConditionalStatementBlock {
2727 start_token: AttachedToken(start_token),
2728 condition,
2729 then_token,
2730 conditional_statements,
2731 } = self;
2732
2733 write!(f, "{start_token}")?;
2734
2735 if let Some(condition) = condition {
2736 write!(f, " {condition}")?;
2737 }
2738
2739 if then_token.is_some() {
2740 write!(f, " THEN")?;
2741 }
2742
2743 if !conditional_statements.statements().is_empty() {
2744 write!(f, " {conditional_statements}")?;
2745 }
2746
2747 Ok(())
2748 }
2749}
2750
2751#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2753#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2754#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2755pub enum ConditionalStatements {
2757 Sequence {
2759 statements: Vec<Statement>,
2761 },
2762 BeginEnd(BeginEndStatements),
2764}
2765
2766impl ConditionalStatements {
2767 pub fn statements(&self) -> &Vec<Statement> {
2769 match self {
2770 ConditionalStatements::Sequence { statements } => statements,
2771 ConditionalStatements::BeginEnd(bes) => &bes.statements,
2772 }
2773 }
2774}
2775
2776impl fmt::Display for ConditionalStatements {
2777 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2778 match self {
2779 ConditionalStatements::Sequence { statements } => {
2780 if !statements.is_empty() {
2781 format_statement_list(f, statements)?;
2782 }
2783 Ok(())
2784 }
2785 ConditionalStatements::BeginEnd(bes) => write!(f, "{bes}"),
2786 }
2787 }
2788}
2789
2790#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2799#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2800#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2801pub struct BeginEndStatements {
2802 pub begin_token: AttachedToken,
2804 pub statements: Vec<Statement>,
2806 pub end_token: AttachedToken,
2808}
2809
2810impl fmt::Display for BeginEndStatements {
2811 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2812 let BeginEndStatements {
2813 begin_token: AttachedToken(begin_token),
2814 statements,
2815 end_token: AttachedToken(end_token),
2816 } = self;
2817
2818 if begin_token.token != Token::EOF {
2819 write!(f, "{begin_token} ")?;
2820 }
2821 if !statements.is_empty() {
2822 format_statement_list(f, statements)?;
2823 }
2824 if end_token.token != Token::EOF {
2825 write!(f, " {end_token}")?;
2826 }
2827 Ok(())
2828 }
2829}
2830
2831#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2843#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2844#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2845pub struct RaiseStatement {
2846 pub value: Option<RaiseStatementValue>,
2848}
2849
2850impl fmt::Display for RaiseStatement {
2851 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2852 let RaiseStatement { value } = self;
2853
2854 write!(f, "RAISE")?;
2855 if let Some(value) = value {
2856 write!(f, " {value}")?;
2857 }
2858
2859 Ok(())
2860 }
2861}
2862
2863#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2865#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2866#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2867pub enum RaiseStatementValue {
2868 UsingMessage(Expr),
2870 Expr(Expr),
2872}
2873
2874impl fmt::Display for RaiseStatementValue {
2875 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2876 match self {
2877 RaiseStatementValue::Expr(expr) => write!(f, "{expr}"),
2878 RaiseStatementValue::UsingMessage(expr) => write!(f, "USING MESSAGE = {expr}"),
2879 }
2880 }
2881}
2882
2883#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2891#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2892#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2893pub struct ThrowStatement {
2894 pub error_number: Option<Box<Expr>>,
2896 pub message: Option<Box<Expr>>,
2898 pub state: Option<Box<Expr>>,
2900}
2901
2902impl fmt::Display for ThrowStatement {
2903 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2904 let ThrowStatement {
2905 error_number,
2906 message,
2907 state,
2908 } = self;
2909
2910 write!(f, "THROW")?;
2911 if let (Some(error_number), Some(message), Some(state)) = (error_number, message, state) {
2912 write!(f, " {error_number}, {message}, {state}")?;
2913 }
2914 Ok(())
2915 }
2916}
2917
2918#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2926#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2927#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2928pub enum DeclareAssignment {
2929 Expr(Box<Expr>),
2931
2932 Default(Box<Expr>),
2934
2935 DuckAssignment(Box<Expr>),
2942
2943 For(Box<Expr>),
2950
2951 MsSqlAssignment(Box<Expr>),
2958}
2959
2960impl fmt::Display for DeclareAssignment {
2961 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2962 match self {
2963 DeclareAssignment::Expr(expr) => {
2964 write!(f, "{expr}")
2965 }
2966 DeclareAssignment::Default(expr) => {
2967 write!(f, "DEFAULT {expr}")
2968 }
2969 DeclareAssignment::DuckAssignment(expr) => {
2970 write!(f, ":= {expr}")
2971 }
2972 DeclareAssignment::MsSqlAssignment(expr) => {
2973 write!(f, "= {expr}")
2974 }
2975 DeclareAssignment::For(expr) => {
2976 write!(f, "FOR {expr}")
2977 }
2978 }
2979 }
2980}
2981
2982#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2984#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2985#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2986pub enum DeclareType {
2987 Cursor,
2993
2994 ResultSet,
3002
3003 Exception,
3011}
3012
3013impl fmt::Display for DeclareType {
3014 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3015 match self {
3016 DeclareType::Cursor => {
3017 write!(f, "CURSOR")
3018 }
3019 DeclareType::ResultSet => {
3020 write!(f, "RESULTSET")
3021 }
3022 DeclareType::Exception => {
3023 write!(f, "EXCEPTION")
3024 }
3025 }
3026 }
3027}
3028
3029#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3042#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3043#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3044pub struct Declare {
3045 pub names: Vec<Ident>,
3048 pub data_type: Option<DataType>,
3051 pub assignment: Option<DeclareAssignment>,
3053 pub declare_type: Option<DeclareType>,
3055 pub binary: Option<bool>,
3057 pub sensitive: Option<bool>,
3061 pub scroll: Option<bool>,
3065 pub hold: Option<bool>,
3069 pub for_query: Option<Box<Query>>,
3071}
3072
3073impl fmt::Display for Declare {
3074 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3075 let Declare {
3076 names,
3077 data_type,
3078 assignment,
3079 declare_type,
3080 binary,
3081 sensitive,
3082 scroll,
3083 hold,
3084 for_query,
3085 } = self;
3086 write!(f, "{}", display_comma_separated(names))?;
3087
3088 if let Some(true) = binary {
3089 write!(f, " BINARY")?;
3090 }
3091
3092 if let Some(sensitive) = sensitive {
3093 if *sensitive {
3094 write!(f, " INSENSITIVE")?;
3095 } else {
3096 write!(f, " ASENSITIVE")?;
3097 }
3098 }
3099
3100 if let Some(scroll) = scroll {
3101 if *scroll {
3102 write!(f, " SCROLL")?;
3103 } else {
3104 write!(f, " NO SCROLL")?;
3105 }
3106 }
3107
3108 if let Some(declare_type) = declare_type {
3109 write!(f, " {declare_type}")?;
3110 }
3111
3112 if let Some(hold) = hold {
3113 if *hold {
3114 write!(f, " WITH HOLD")?;
3115 } else {
3116 write!(f, " WITHOUT HOLD")?;
3117 }
3118 }
3119
3120 if let Some(query) = for_query {
3121 write!(f, " FOR {query}")?;
3122 }
3123
3124 if let Some(data_type) = data_type {
3125 write!(f, " {data_type}")?;
3126 }
3127
3128 if let Some(expr) = assignment {
3129 write!(f, " {expr}")?;
3130 }
3131 Ok(())
3132 }
3133}
3134
3135#[derive(Debug, Default, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3137#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3138#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3139pub enum CreateTableOptions {
3141 #[default]
3143 None,
3144 With(Vec<SqlOption>),
3146 Options(Vec<SqlOption>),
3148 Plain(Vec<SqlOption>),
3150 TableProperties(Vec<SqlOption>),
3152}
3153
3154impl fmt::Display for CreateTableOptions {
3155 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3156 match self {
3157 CreateTableOptions::With(with_options) => {
3158 write!(f, "WITH ({})", display_comma_separated(with_options))
3159 }
3160 CreateTableOptions::Options(options) => {
3161 write!(f, "OPTIONS({})", display_comma_separated(options))
3162 }
3163 CreateTableOptions::TableProperties(options) => {
3164 write!(f, "TBLPROPERTIES ({})", display_comma_separated(options))
3165 }
3166 CreateTableOptions::Plain(options) => {
3167 write!(f, "{}", display_separated(options, " "))
3168 }
3169 CreateTableOptions::None => Ok(()),
3170 }
3171 }
3172}
3173
3174#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3181#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3182#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3183pub enum FromTable {
3184 WithFromKeyword(Vec<TableWithJoins>),
3186 WithoutKeyword(Vec<TableWithJoins>),
3189}
3190impl Display for FromTable {
3191 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3192 match self {
3193 FromTable::WithFromKeyword(tables) => {
3194 write!(f, "FROM {}", display_comma_separated(tables))
3195 }
3196 FromTable::WithoutKeyword(tables) => {
3197 write!(f, "{}", display_comma_separated(tables))
3198 }
3199 }
3200 }
3201}
3202
3203#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3204#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3205#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3206pub enum Set {
3208 SingleAssignment {
3212 scope: Option<ContextModifier>,
3214 hivevar: bool,
3216 variable: ObjectName,
3218 values: Vec<Expr>,
3220 },
3221 ParenthesizedAssignments {
3225 variables: Vec<ObjectName>,
3227 values: Vec<Expr>,
3229 },
3230 MultipleAssignments {
3234 assignments: Vec<SetAssignment>,
3236 },
3237 SetSessionAuthorization(SetSessionAuthorizationParam),
3246 SetSessionParam(SetSessionParamKind),
3250 SetRole {
3261 context_modifier: Option<ContextModifier>,
3263 role_name: Option<Ident>,
3265 },
3266 SetTimeZone {
3276 local: bool,
3278 value: Expr,
3280 },
3281 SetNames {
3285 charset_name: Ident,
3287 collation_name: Option<String>,
3289 },
3290 SetNamesDefault {},
3296 SetTransaction {
3300 modes: Vec<TransactionMode>,
3302 snapshot: Option<ValueWithSpan>,
3304 session: bool,
3306 },
3307}
3308
3309impl Display for Set {
3310 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3311 match self {
3312 Self::ParenthesizedAssignments { variables, values } => write!(
3313 f,
3314 "SET ({}) = ({})",
3315 display_comma_separated(variables),
3316 display_comma_separated(values)
3317 ),
3318 Self::MultipleAssignments { assignments } => {
3319 write!(f, "SET {}", display_comma_separated(assignments))
3320 }
3321 Self::SetRole {
3322 context_modifier,
3323 role_name,
3324 } => {
3325 let role_name = role_name.clone().unwrap_or_else(|| Ident::new("NONE"));
3326 write!(
3327 f,
3328 "SET {modifier}ROLE {role_name}",
3329 modifier = context_modifier.map(|m| format!("{m}")).unwrap_or_default()
3330 )
3331 }
3332 Self::SetSessionAuthorization(kind) => write!(f, "SET SESSION AUTHORIZATION {kind}"),
3333 Self::SetSessionParam(kind) => write!(f, "SET {kind}"),
3334 Self::SetTransaction {
3335 modes,
3336 snapshot,
3337 session,
3338 } => {
3339 if *session {
3340 write!(f, "SET SESSION CHARACTERISTICS AS TRANSACTION")?;
3341 } else {
3342 write!(f, "SET TRANSACTION")?;
3343 }
3344 if !modes.is_empty() {
3345 write!(f, " {}", display_comma_separated(modes))?;
3346 }
3347 if let Some(snapshot_id) = snapshot {
3348 write!(f, " SNAPSHOT {snapshot_id}")?;
3349 }
3350 Ok(())
3351 }
3352 Self::SetTimeZone { local, value } => {
3353 f.write_str("SET ")?;
3354 if *local {
3355 f.write_str("LOCAL ")?;
3356 }
3357 write!(f, "TIME ZONE {value}")
3358 }
3359 Self::SetNames {
3360 charset_name,
3361 collation_name,
3362 } => {
3363 write!(f, "SET NAMES {charset_name}")?;
3364
3365 if let Some(collation) = collation_name {
3366 f.write_str(" COLLATE ")?;
3367 f.write_str(collation)?;
3368 };
3369
3370 Ok(())
3371 }
3372 Self::SetNamesDefault {} => {
3373 f.write_str("SET NAMES DEFAULT")?;
3374
3375 Ok(())
3376 }
3377 Set::SingleAssignment {
3378 scope,
3379 hivevar,
3380 variable,
3381 values,
3382 } => {
3383 write!(
3384 f,
3385 "SET {}{}{} = {}",
3386 scope.map(|s| format!("{s}")).unwrap_or_default(),
3387 if *hivevar { "HIVEVAR:" } else { "" },
3388 variable,
3389 display_comma_separated(values)
3390 )
3391 }
3392 }
3393 }
3394}
3395
3396#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3402#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3403#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3404pub struct ExceptionWhen {
3405 pub idents: Vec<Ident>,
3407 pub statements: Vec<Statement>,
3409}
3410
3411impl Display for ExceptionWhen {
3412 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3413 write!(
3414 f,
3415 "WHEN {idents} THEN",
3416 idents = display_separated(&self.idents, " OR ")
3417 )?;
3418
3419 if !self.statements.is_empty() {
3420 write!(f, " ")?;
3421 format_statement_list(f, &self.statements)?;
3422 }
3423
3424 Ok(())
3425 }
3426}
3427
3428#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3435#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3436#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3437pub struct Analyze {
3438 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3439 pub table_name: Option<ObjectName>,
3441 pub partitions: Option<Vec<Expr>>,
3443 pub for_columns: bool,
3445 pub columns: Vec<Ident>,
3447 pub cache_metadata: bool,
3449 pub noscan: bool,
3451 pub compute_statistics: bool,
3453 pub has_table_keyword: bool,
3455}
3456
3457impl fmt::Display for Analyze {
3458 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3459 write!(f, "ANALYZE")?;
3460 if let Some(ref table_name) = self.table_name {
3461 if self.has_table_keyword {
3462 write!(f, " TABLE")?;
3463 }
3464 write!(f, " {table_name}")?;
3465 }
3466 if !self.for_columns && !self.columns.is_empty() {
3467 write!(f, " ({})", display_comma_separated(&self.columns))?;
3468 }
3469 if let Some(ref parts) = self.partitions {
3470 if !parts.is_empty() {
3471 write!(f, " PARTITION ({})", display_comma_separated(parts))?;
3472 }
3473 }
3474 if self.compute_statistics {
3475 write!(f, " COMPUTE STATISTICS")?;
3476 }
3477 if self.noscan {
3478 write!(f, " NOSCAN")?;
3479 }
3480 if self.cache_metadata {
3481 write!(f, " CACHE METADATA")?;
3482 }
3483 if self.for_columns {
3484 write!(f, " FOR COLUMNS")?;
3485 if !self.columns.is_empty() {
3486 write!(f, " {}", display_comma_separated(&self.columns))?;
3487 }
3488 }
3489 Ok(())
3490 }
3491}
3492
3493#[allow(clippy::large_enum_variant)]
3495#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3496#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3497#[cfg_attr(
3498 feature = "visitor",
3499 derive(Visit, VisitMut),
3500 visit(with = "visit_statement")
3501)]
3502pub enum Statement {
3503 Analyze(Analyze),
3508 Set(Set),
3510 Truncate(Truncate),
3515 Msck(Msck),
3520 Query(Box<Query>),
3524 Insert(Insert),
3528 Install {
3532 extension_name: Ident,
3534 },
3535 Load {
3539 extension_name: Ident,
3541 },
3542 Directory {
3545 overwrite: bool,
3547 local: bool,
3549 path: String,
3551 file_format: Option<FileFormat>,
3553 source: Box<Query>,
3555 },
3556 Case(CaseStatement),
3558 If(IfStatement),
3560 While(WhileStatement),
3562 Raise(RaiseStatement),
3564 Call(Function),
3568 Copy {
3572 source: CopySource,
3574 to: bool,
3576 target: CopyTarget,
3578 options: Vec<CopyOption>,
3580 legacy_options: Vec<CopyLegacyOption>,
3582 values: Vec<Option<String>>,
3584 },
3585 CopyIntoSnowflake {
3597 kind: CopyIntoSnowflakeKind,
3599 into: ObjectName,
3601 into_columns: Option<Vec<Ident>>,
3603 from_obj: Option<ObjectName>,
3605 from_obj_alias: Option<Ident>,
3607 stage_params: StageParamsObject,
3609 from_transformations: Option<Vec<StageLoadSelectItemKind>>,
3611 from_query: Option<Box<Query>>,
3613 files: Option<Vec<String>>,
3615 pattern: Option<String>,
3617 file_format: KeyValueOptions,
3619 copy_options: KeyValueOptions,
3621 validation_mode: Option<String>,
3623 partition: Option<Box<Expr>>,
3625 },
3626 Open(OpenStatement),
3631 Close {
3636 cursor: CloseCursor,
3638 },
3639 Update(Update),
3643 Delete(Delete),
3647 CreateView(CreateView),
3651 CreateTable(CreateTable),
3655 CreateVirtualTable {
3660 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3661 name: ObjectName,
3663 if_not_exists: bool,
3665 module_name: Ident,
3667 module_args: Vec<Ident>,
3669 },
3670 CreateIndex(CreateIndex),
3674 CreateRole(CreateRole),
3679 CreateSecret {
3684 or_replace: bool,
3686 temporary: Option<bool>,
3688 if_not_exists: bool,
3690 name: Option<Ident>,
3692 storage_specifier: Option<Ident>,
3694 secret_type: Ident,
3696 options: Vec<SecretOption>,
3698 },
3699 CreateServer(CreateServerStatement),
3701 CreatePolicy(CreatePolicy),
3706 CreateConnector(CreateConnector),
3711 CreateOperator(CreateOperator),
3716 CreateOperatorFamily(CreateOperatorFamily),
3721 CreateOperatorClass(CreateOperatorClass),
3726 AlterTable(AlterTable),
3730 AlterSchema(AlterSchema),
3735 AlterIndex {
3739 name: ObjectName,
3741 operation: AlterIndexOperation,
3743 },
3744 AlterView {
3748 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3750 name: ObjectName,
3751 columns: Vec<Ident>,
3753 query: Box<Query>,
3755 with_options: Vec<SqlOption>,
3757 },
3758 AlterFunction(AlterFunction),
3765 AlterType(AlterType),
3770 AlterCollation(AlterCollation),
3775 AlterOperator(AlterOperator),
3780 AlterOperatorFamily(AlterOperatorFamily),
3785 AlterOperatorClass(AlterOperatorClass),
3790 AlterRole {
3794 name: Ident,
3796 operation: AlterRoleOperation,
3798 },
3799 AlterPolicy(AlterPolicy),
3804 AlterConnector {
3813 name: Ident,
3815 properties: Option<Vec<SqlOption>>,
3817 url: Option<String>,
3819 owner: Option<ddl::AlterConnectorOwner>,
3821 },
3822 AlterSession {
3828 set: bool,
3830 session_params: KeyValueOptions,
3832 },
3833 AttachDatabase {
3838 schema_name: Ident,
3840 database_file_name: Expr,
3842 database: bool,
3844 },
3845 AttachDuckDBDatabase {
3851 if_not_exists: bool,
3853 database: bool,
3855 database_path: Ident,
3857 database_alias: Option<Ident>,
3859 attach_options: Vec<AttachDuckDBDatabaseOption>,
3861 },
3862 DetachDuckDBDatabase {
3868 if_exists: bool,
3870 database: bool,
3872 database_alias: Ident,
3874 },
3875 Drop {
3879 object_type: ObjectType,
3881 if_exists: bool,
3883 names: Vec<ObjectName>,
3885 cascade: bool,
3888 restrict: bool,
3891 purge: bool,
3894 temporary: bool,
3896 table: Option<ObjectName>,
3899 },
3900 DropFunction(DropFunction),
3904 DropDomain(DropDomain),
3912 DropProcedure {
3916 if_exists: bool,
3918 proc_desc: Vec<FunctionDesc>,
3920 drop_behavior: Option<DropBehavior>,
3922 },
3923 DropSecret {
3927 if_exists: bool,
3929 temporary: Option<bool>,
3931 name: Ident,
3933 storage_specifier: Option<Ident>,
3935 },
3936 DropPolicy(DropPolicy),
3941 DropConnector {
3946 if_exists: bool,
3948 name: Ident,
3950 },
3951 Declare {
3959 stmts: Vec<Declare>,
3961 },
3962 CreateExtension(CreateExtension),
3971 CreateCollation(CreateCollation),
3977 DropExtension(DropExtension),
3983 DropOperator(DropOperator),
3989 DropOperatorFamily(DropOperatorFamily),
3995 DropOperatorClass(DropOperatorClass),
4001 Fetch {
4009 name: Ident,
4011 direction: FetchDirection,
4013 position: FetchPosition,
4015 into: Option<ObjectName>,
4017 },
4018 Flush {
4025 object_type: FlushType,
4027 location: Option<FlushLocation>,
4029 channel: Option<String>,
4031 read_lock: bool,
4033 export: bool,
4035 tables: Vec<ObjectName>,
4037 },
4038 Discard {
4045 object_type: DiscardObject,
4047 },
4048 ShowFunctions {
4052 filter: Option<ShowStatementFilter>,
4054 },
4055 ShowVariable {
4061 variable: Vec<Ident>,
4063 },
4064 ShowStatus {
4070 filter: Option<ShowStatementFilter>,
4072 global: bool,
4074 session: bool,
4076 },
4077 ShowVariables {
4083 filter: Option<ShowStatementFilter>,
4085 global: bool,
4087 session: bool,
4089 },
4090 ShowCreate {
4096 obj_type: ShowCreateObject,
4098 obj_name: ObjectName,
4100 },
4101 ShowColumns {
4105 extended: bool,
4107 full: bool,
4109 show_options: ShowStatementOptions,
4111 },
4112 ShowCatalogs {
4116 terse: bool,
4118 history: bool,
4120 show_options: ShowStatementOptions,
4122 },
4123 ShowDatabases {
4127 terse: bool,
4129 history: bool,
4131 show_options: ShowStatementOptions,
4133 },
4134 ShowProcessList {
4140 full: bool,
4142 },
4143 ShowSchemas {
4147 terse: bool,
4149 history: bool,
4151 show_options: ShowStatementOptions,
4153 },
4154 ShowCharset(ShowCharset),
4161 ShowObjects(ShowObjects),
4167 ShowTables {
4171 terse: bool,
4173 history: bool,
4175 extended: bool,
4177 full: bool,
4179 external: bool,
4181 show_options: ShowStatementOptions,
4183 },
4184 ShowViews {
4188 terse: bool,
4190 materialized: bool,
4192 show_options: ShowStatementOptions,
4194 },
4195 ShowCollation {
4201 filter: Option<ShowStatementFilter>,
4203 },
4204 Use(Use),
4208 StartTransaction {
4218 modes: Vec<TransactionMode>,
4220 begin: bool,
4222 transaction: Option<BeginTransactionKind>,
4224 modifier: Option<TransactionModifier>,
4226 statements: Vec<Statement>,
4235 exception: Option<Vec<ExceptionWhen>>,
4249 has_end_keyword: bool,
4251 },
4252 Comment {
4258 object_type: CommentObject,
4260 object_name: ObjectName,
4262 comment: Option<String>,
4264 if_exists: bool,
4267 },
4268 Commit {
4278 chain: bool,
4280 end: bool,
4282 modifier: Option<TransactionModifier>,
4284 },
4285 Rollback {
4289 chain: bool,
4291 savepoint: Option<Ident>,
4293 },
4294 CreateSchema {
4298 schema_name: SchemaName,
4300 if_not_exists: bool,
4302 with: Option<Vec<SqlOption>>,
4310 options: Option<Vec<SqlOption>>,
4318 default_collate_spec: Option<Expr>,
4326 clone: Option<ObjectName>,
4334 },
4335 CreateDatabase {
4341 db_name: ObjectName,
4343 if_not_exists: bool,
4345 location: Option<String>,
4347 managed_location: Option<String>,
4349 or_replace: bool,
4351 transient: bool,
4353 clone: Option<ObjectName>,
4355 data_retention_time_in_days: Option<u64>,
4357 max_data_extension_time_in_days: Option<u64>,
4359 external_volume: Option<String>,
4361 catalog: Option<String>,
4363 replace_invalid_characters: Option<bool>,
4365 default_ddl_collation: Option<String>,
4367 storage_serialization_policy: Option<StorageSerializationPolicy>,
4369 comment: Option<String>,
4371 default_charset: Option<String>,
4373 default_collation: Option<String>,
4375 catalog_sync: Option<String>,
4377 catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
4379 catalog_sync_namespace_flatten_delimiter: Option<String>,
4381 with_tags: Option<Vec<Tag>>,
4383 with_contacts: Option<Vec<ContactEntry>>,
4385 },
4386 CreateFunction(CreateFunction),
4396 CreateTrigger(CreateTrigger),
4398 DropTrigger(DropTrigger),
4400 CreateProcedure {
4404 or_alter: bool,
4406 name: ObjectName,
4408 params: Option<Vec<ProcedureParam>>,
4410 language: Option<Ident>,
4412 body: ConditionalStatements,
4414 },
4415 CreateMacro {
4422 or_replace: bool,
4424 temporary: bool,
4426 name: ObjectName,
4428 args: Option<Vec<MacroArg>>,
4430 definition: MacroDefinition,
4432 },
4433 CreateStage {
4438 or_replace: bool,
4440 temporary: bool,
4442 if_not_exists: bool,
4444 name: ObjectName,
4446 stage_params: StageParamsObject,
4448 directory_table_params: KeyValueOptions,
4450 file_format: KeyValueOptions,
4452 copy_options: KeyValueOptions,
4454 comment: Option<String>,
4456 },
4457 Assert {
4461 condition: Expr,
4463 message: Option<Expr>,
4465 },
4466 Grant(Grant),
4470 Deny(DenyStatement),
4474 Revoke(Revoke),
4478 Deallocate {
4484 name: Ident,
4486 prepare: bool,
4488 },
4489 Execute {
4498 name: Option<ObjectName>,
4500 parameters: Vec<Expr>,
4502 has_parentheses: bool,
4504 immediate: bool,
4506 into: Vec<Ident>,
4508 using: Vec<ExprWithAlias>,
4510 output: bool,
4513 default: bool,
4516 },
4517 Prepare {
4523 name: Ident,
4525 data_types: Vec<DataType>,
4527 statement: Box<Statement>,
4529 },
4530 Kill {
4537 modifier: Option<KillType>,
4539 id: u64,
4542 },
4543 ExplainTable {
4548 describe_alias: DescribeAlias,
4550 hive_format: Option<HiveDescribeFormat>,
4552 has_table_keyword: bool,
4557 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4559 table_name: ObjectName,
4560 },
4561 Explain {
4565 describe_alias: DescribeAlias,
4567 analyze: bool,
4569 verbose: bool,
4571 query_plan: bool,
4576 estimate: bool,
4579 statement: Box<Statement>,
4581 format: Option<AnalyzeFormatKind>,
4583 options: Option<Vec<UtilityOption>>,
4585 },
4586 Savepoint {
4591 name: Ident,
4593 },
4594 ReleaseSavepoint {
4598 name: Ident,
4600 },
4601 Merge(Merge),
4610 Cache {
4618 table_flag: Option<ObjectName>,
4620 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4622 table_name: ObjectName,
4623 has_as: bool,
4625 options: Vec<SqlOption>,
4627 query: Option<Box<Query>>,
4629 },
4630 UNCache {
4634 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4636 table_name: ObjectName,
4637 if_exists: bool,
4639 },
4640 CreateSequence {
4645 temporary: bool,
4647 if_not_exists: bool,
4649 name: ObjectName,
4651 data_type: Option<DataType>,
4653 sequence_options: Vec<SequenceOptions>,
4655 owned_by: Option<ObjectName>,
4657 },
4658 CreateDomain(CreateDomain),
4660 CreateType {
4664 name: ObjectName,
4666 representation: Option<UserDefinedTypeRepresentation>,
4668 },
4669 Pragma {
4673 name: ObjectName,
4675 value: Option<ValueWithSpan>,
4677 is_eq: bool,
4679 },
4680 Lock(Lock),
4686 LockTables {
4691 tables: Vec<LockTable>,
4693 },
4694 UnlockTables,
4699 Unload {
4711 query: Option<Box<Query>>,
4713 query_text: Option<String>,
4715 to: Ident,
4717 auth: Option<IamRoleKind>,
4719 with: Vec<SqlOption>,
4721 options: Vec<CopyLegacyOption>,
4723 },
4724 OptimizeTable {
4736 name: ObjectName,
4738 has_table_keyword: bool,
4740 on_cluster: Option<Ident>,
4743 partition: Option<Partition>,
4746 include_final: bool,
4749 deduplicate: Option<Deduplicate>,
4752 predicate: Option<Expr>,
4755 zorder: Option<Vec<Expr>>,
4758 },
4759 LISTEN {
4766 channel: Ident,
4768 },
4769 UNLISTEN {
4776 channel: Ident,
4778 },
4779 NOTIFY {
4786 channel: Ident,
4788 payload: Option<String>,
4790 },
4791 LoadData {
4800 local: bool,
4802 inpath: String,
4804 overwrite: bool,
4806 table_name: ObjectName,
4808 partitioned: Option<Vec<Expr>>,
4810 table_format: Option<HiveLoadDataFormat>,
4812 },
4813 RenameTable(Vec<RenameTable>),
4820 List(FileStagingCommand),
4823 Remove(FileStagingCommand),
4826 RaisError {
4833 message: Box<Expr>,
4835 severity: Box<Expr>,
4837 state: Box<Expr>,
4839 arguments: Vec<Expr>,
4841 options: Vec<RaisErrorOption>,
4843 },
4844 Throw(ThrowStatement),
4846 Print(PrintStatement),
4852 WaitFor(WaitForStatement),
4856 Return(ReturnStatement),
4862 ExportData(ExportData),
4871 CreateUser(CreateUser),
4876 AlterUser(AlterUser),
4881 Vacuum(VacuumStatement),
4888 Reset(ResetStatement),
4896}
4897
4898impl From<Analyze> for Statement {
4899 fn from(analyze: Analyze) -> Self {
4900 Statement::Analyze(analyze)
4901 }
4902}
4903
4904impl From<ddl::Truncate> for Statement {
4905 fn from(truncate: ddl::Truncate) -> Self {
4906 Statement::Truncate(truncate)
4907 }
4908}
4909
4910impl From<Lock> for Statement {
4911 fn from(lock: Lock) -> Self {
4912 Statement::Lock(lock)
4913 }
4914}
4915
4916impl From<ddl::Msck> for Statement {
4917 fn from(msck: ddl::Msck) -> Self {
4918 Statement::Msck(msck)
4919 }
4920}
4921
4922#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4928#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4929#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4930pub enum CurrentGrantsKind {
4931 CopyCurrentGrants,
4933 RevokeCurrentGrants,
4935}
4936
4937impl fmt::Display for CurrentGrantsKind {
4938 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4939 match self {
4940 CurrentGrantsKind::CopyCurrentGrants => write!(f, "COPY CURRENT GRANTS"),
4941 CurrentGrantsKind::RevokeCurrentGrants => write!(f, "REVOKE CURRENT GRANTS"),
4942 }
4943 }
4944}
4945
4946#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4947#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4948#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4949pub enum RaisErrorOption {
4952 Log,
4954 NoWait,
4956 SetError,
4958}
4959
4960impl fmt::Display for RaisErrorOption {
4961 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4962 match self {
4963 RaisErrorOption::Log => write!(f, "LOG"),
4964 RaisErrorOption::NoWait => write!(f, "NOWAIT"),
4965 RaisErrorOption::SetError => write!(f, "SETERROR"),
4966 }
4967 }
4968}
4969
4970impl fmt::Display for Statement {
4971 #[allow(clippy::cognitive_complexity)]
4996 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4997 match self {
4998 Statement::Flush {
4999 object_type,
5000 location,
5001 channel,
5002 read_lock,
5003 export,
5004 tables,
5005 } => {
5006 write!(f, "FLUSH")?;
5007 if let Some(location) = location {
5008 f.write_str(" ")?;
5009 location.fmt(f)?;
5010 }
5011 write!(f, " {object_type}")?;
5012
5013 if let Some(channel) = channel {
5014 write!(f, " FOR CHANNEL {channel}")?;
5015 }
5016
5017 write!(
5018 f,
5019 "{tables}{read}{export}",
5020 tables = if !tables.is_empty() {
5021 format!(" {}", display_comma_separated(tables))
5022 } else {
5023 String::new()
5024 },
5025 export = if *export { " FOR EXPORT" } else { "" },
5026 read = if *read_lock { " WITH READ LOCK" } else { "" }
5027 )
5028 }
5029 Statement::Kill { modifier, id } => {
5030 write!(f, "KILL ")?;
5031
5032 if let Some(m) = modifier {
5033 write!(f, "{m} ")?;
5034 }
5035
5036 write!(f, "{id}")
5037 }
5038 Statement::ExplainTable {
5039 describe_alias,
5040 hive_format,
5041 has_table_keyword,
5042 table_name,
5043 } => {
5044 write!(f, "{describe_alias} ")?;
5045
5046 if let Some(format) = hive_format {
5047 write!(f, "{format} ")?;
5048 }
5049 if *has_table_keyword {
5050 write!(f, "TABLE ")?;
5051 }
5052
5053 write!(f, "{table_name}")
5054 }
5055 Statement::Explain {
5056 describe_alias,
5057 verbose,
5058 analyze,
5059 query_plan,
5060 estimate,
5061 statement,
5062 format,
5063 options,
5064 } => {
5065 write!(f, "{describe_alias} ")?;
5066
5067 if *query_plan {
5068 write!(f, "QUERY PLAN ")?;
5069 }
5070 if *analyze {
5071 write!(f, "ANALYZE ")?;
5072 }
5073 if *estimate {
5074 write!(f, "ESTIMATE ")?;
5075 }
5076
5077 if *verbose {
5078 write!(f, "VERBOSE ")?;
5079 }
5080
5081 if let Some(format) = format {
5082 write!(f, "{format} ")?;
5083 }
5084
5085 if let Some(options) = options {
5086 write!(f, "({}) ", display_comma_separated(options))?;
5087 }
5088
5089 write!(f, "{statement}")
5090 }
5091 Statement::Query(s) => s.fmt(f),
5092 Statement::Declare { stmts } => {
5093 write!(f, "DECLARE ")?;
5094 write!(f, "{}", display_separated(stmts, "; "))
5095 }
5096 Statement::Fetch {
5097 name,
5098 direction,
5099 position,
5100 into,
5101 } => {
5102 write!(f, "FETCH {direction} {position} {name}")?;
5103
5104 if let Some(into) = into {
5105 write!(f, " INTO {into}")?;
5106 }
5107
5108 Ok(())
5109 }
5110 Statement::Directory {
5111 overwrite,
5112 local,
5113 path,
5114 file_format,
5115 source,
5116 } => {
5117 write!(
5118 f,
5119 "INSERT{overwrite}{local} DIRECTORY '{path}'",
5120 overwrite = if *overwrite { " OVERWRITE" } else { "" },
5121 local = if *local { " LOCAL" } else { "" },
5122 path = path
5123 )?;
5124 if let Some(ref ff) = file_format {
5125 write!(f, " STORED AS {ff}")?
5126 }
5127 write!(f, " {source}")
5128 }
5129 Statement::Msck(msck) => msck.fmt(f),
5130 Statement::Truncate(truncate) => truncate.fmt(f),
5131 Statement::Case(stmt) => {
5132 write!(f, "{stmt}")
5133 }
5134 Statement::If(stmt) => {
5135 write!(f, "{stmt}")
5136 }
5137 Statement::While(stmt) => {
5138 write!(f, "{stmt}")
5139 }
5140 Statement::Raise(stmt) => {
5141 write!(f, "{stmt}")
5142 }
5143 Statement::AttachDatabase {
5144 schema_name,
5145 database_file_name,
5146 database,
5147 } => {
5148 let keyword = if *database { "DATABASE " } else { "" };
5149 write!(f, "ATTACH {keyword}{database_file_name} AS {schema_name}")
5150 }
5151 Statement::AttachDuckDBDatabase {
5152 if_not_exists,
5153 database,
5154 database_path,
5155 database_alias,
5156 attach_options,
5157 } => {
5158 write!(
5159 f,
5160 "ATTACH{database}{if_not_exists} {database_path}",
5161 database = if *database { " DATABASE" } else { "" },
5162 if_not_exists = if *if_not_exists { " IF NOT EXISTS" } else { "" },
5163 )?;
5164 if let Some(alias) = database_alias {
5165 write!(f, " AS {alias}")?;
5166 }
5167 if !attach_options.is_empty() {
5168 write!(f, " ({})", display_comma_separated(attach_options))?;
5169 }
5170 Ok(())
5171 }
5172 Statement::DetachDuckDBDatabase {
5173 if_exists,
5174 database,
5175 database_alias,
5176 } => {
5177 write!(
5178 f,
5179 "DETACH{database}{if_exists} {database_alias}",
5180 database = if *database { " DATABASE" } else { "" },
5181 if_exists = if *if_exists { " IF EXISTS" } else { "" },
5182 )?;
5183 Ok(())
5184 }
5185 Statement::Analyze(analyze) => analyze.fmt(f),
5186 Statement::Insert(insert) => insert.fmt(f),
5187 Statement::Install {
5188 extension_name: name,
5189 } => write!(f, "INSTALL {name}"),
5190
5191 Statement::Load {
5192 extension_name: name,
5193 } => write!(f, "LOAD {name}"),
5194
5195 Statement::Call(function) => write!(f, "CALL {function}"),
5196
5197 Statement::Copy {
5198 source,
5199 to,
5200 target,
5201 options,
5202 legacy_options,
5203 values,
5204 } => {
5205 write!(f, "COPY")?;
5206 match source {
5207 CopySource::Query(query) => write!(f, " ({query})")?,
5208 CopySource::Table {
5209 table_name,
5210 columns,
5211 } => {
5212 write!(f, " {table_name}")?;
5213 if !columns.is_empty() {
5214 write!(f, " ({})", display_comma_separated(columns))?;
5215 }
5216 }
5217 }
5218 write!(f, " {} {}", if *to { "TO" } else { "FROM" }, target)?;
5219 if !options.is_empty() {
5220 write!(f, " ({})", display_comma_separated(options))?;
5221 }
5222 if !legacy_options.is_empty() {
5223 write!(f, " {}", display_separated(legacy_options, " "))?;
5224 }
5225 if !values.is_empty() {
5226 writeln!(f, ";")?;
5227 let mut delim = "";
5228 for v in values {
5229 write!(f, "{delim}")?;
5230 delim = "\t";
5231 if let Some(v) = v {
5232 write!(f, "{v}")?;
5233 } else {
5234 write!(f, "\\N")?;
5235 }
5236 }
5237 write!(f, "\n\\.")?;
5238 }
5239 Ok(())
5240 }
5241 Statement::Update(update) => update.fmt(f),
5242 Statement::Delete(delete) => delete.fmt(f),
5243 Statement::Open(open) => open.fmt(f),
5244 Statement::Close { cursor } => {
5245 write!(f, "CLOSE {cursor}")?;
5246
5247 Ok(())
5248 }
5249 Statement::CreateDatabase {
5250 db_name,
5251 if_not_exists,
5252 location,
5253 managed_location,
5254 or_replace,
5255 transient,
5256 clone,
5257 data_retention_time_in_days,
5258 max_data_extension_time_in_days,
5259 external_volume,
5260 catalog,
5261 replace_invalid_characters,
5262 default_ddl_collation,
5263 storage_serialization_policy,
5264 comment,
5265 default_charset,
5266 default_collation,
5267 catalog_sync,
5268 catalog_sync_namespace_mode,
5269 catalog_sync_namespace_flatten_delimiter,
5270 with_tags,
5271 with_contacts,
5272 } => {
5273 write!(
5274 f,
5275 "CREATE {or_replace}{transient}DATABASE {if_not_exists}{name}",
5276 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5277 transient = if *transient { "TRANSIENT " } else { "" },
5278 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5279 name = db_name,
5280 )?;
5281
5282 if let Some(l) = location {
5283 write!(f, " LOCATION '{l}'")?;
5284 }
5285 if let Some(ml) = managed_location {
5286 write!(f, " MANAGEDLOCATION '{ml}'")?;
5287 }
5288 if let Some(clone) = clone {
5289 write!(f, " CLONE {clone}")?;
5290 }
5291
5292 if let Some(value) = data_retention_time_in_days {
5293 write!(f, " DATA_RETENTION_TIME_IN_DAYS = {value}")?;
5294 }
5295
5296 if let Some(value) = max_data_extension_time_in_days {
5297 write!(f, " MAX_DATA_EXTENSION_TIME_IN_DAYS = {value}")?;
5298 }
5299
5300 if let Some(vol) = external_volume {
5301 write!(f, " EXTERNAL_VOLUME = '{vol}'")?;
5302 }
5303
5304 if let Some(cat) = catalog {
5305 write!(f, " CATALOG = '{cat}'")?;
5306 }
5307
5308 if let Some(true) = replace_invalid_characters {
5309 write!(f, " REPLACE_INVALID_CHARACTERS = TRUE")?;
5310 } else if let Some(false) = replace_invalid_characters {
5311 write!(f, " REPLACE_INVALID_CHARACTERS = FALSE")?;
5312 }
5313
5314 if let Some(collation) = default_ddl_collation {
5315 write!(f, " DEFAULT_DDL_COLLATION = '{collation}'")?;
5316 }
5317
5318 if let Some(policy) = storage_serialization_policy {
5319 write!(f, " STORAGE_SERIALIZATION_POLICY = {policy}")?;
5320 }
5321
5322 if let Some(comment) = comment {
5323 write!(f, " COMMENT = '{comment}'")?;
5324 }
5325
5326 if let Some(charset) = default_charset {
5327 write!(f, " DEFAULT CHARACTER SET {charset}")?;
5328 }
5329
5330 if let Some(collation) = default_collation {
5331 write!(f, " DEFAULT COLLATE {collation}")?;
5332 }
5333
5334 if let Some(sync) = catalog_sync {
5335 write!(f, " CATALOG_SYNC = '{sync}'")?;
5336 }
5337
5338 if let Some(mode) = catalog_sync_namespace_mode {
5339 write!(f, " CATALOG_SYNC_NAMESPACE_MODE = {mode}")?;
5340 }
5341
5342 if let Some(delim) = catalog_sync_namespace_flatten_delimiter {
5343 write!(f, " CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '{delim}'")?;
5344 }
5345
5346 if let Some(tags) = with_tags {
5347 write!(f, " WITH TAG ({})", display_comma_separated(tags))?;
5348 }
5349
5350 if let Some(contacts) = with_contacts {
5351 write!(f, " WITH CONTACT ({})", display_comma_separated(contacts))?;
5352 }
5353 Ok(())
5354 }
5355 Statement::CreateFunction(create_function) => create_function.fmt(f),
5356 Statement::CreateDomain(create_domain) => create_domain.fmt(f),
5357 Statement::CreateTrigger(create_trigger) => create_trigger.fmt(f),
5358 Statement::DropTrigger(drop_trigger) => drop_trigger.fmt(f),
5359 Statement::CreateProcedure {
5360 name,
5361 or_alter,
5362 params,
5363 language,
5364 body,
5365 } => {
5366 write!(
5367 f,
5368 "CREATE {or_alter}PROCEDURE {name}",
5369 or_alter = if *or_alter { "OR ALTER " } else { "" },
5370 name = name
5371 )?;
5372
5373 if let Some(p) = params {
5374 if !p.is_empty() {
5375 write!(f, " ({})", display_comma_separated(p))?;
5376 }
5377 }
5378
5379 if let Some(language) = language {
5380 write!(f, " LANGUAGE {language}")?;
5381 }
5382
5383 write!(f, " AS {body}")
5384 }
5385 Statement::CreateMacro {
5386 or_replace,
5387 temporary,
5388 name,
5389 args,
5390 definition,
5391 } => {
5392 write!(
5393 f,
5394 "CREATE {or_replace}{temp}MACRO {name}",
5395 temp = if *temporary { "TEMPORARY " } else { "" },
5396 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5397 )?;
5398 if let Some(args) = args {
5399 write!(f, "({})", display_comma_separated(args))?;
5400 }
5401 match definition {
5402 MacroDefinition::Expr(expr) => write!(f, " AS {expr}")?,
5403 MacroDefinition::Table(query) => write!(f, " AS TABLE {query}")?,
5404 }
5405 Ok(())
5406 }
5407 Statement::CreateView(create_view) => create_view.fmt(f),
5408 Statement::CreateTable(create_table) => create_table.fmt(f),
5409 Statement::LoadData {
5410 local,
5411 inpath,
5412 overwrite,
5413 table_name,
5414 partitioned,
5415 table_format,
5416 } => {
5417 write!(
5418 f,
5419 "LOAD DATA {local}INPATH '{inpath}' {overwrite}INTO TABLE {table_name}",
5420 local = if *local { "LOCAL " } else { "" },
5421 inpath = inpath,
5422 overwrite = if *overwrite { "OVERWRITE " } else { "" },
5423 table_name = table_name,
5424 )?;
5425 if let Some(ref parts) = &partitioned {
5426 if !parts.is_empty() {
5427 write!(f, " PARTITION ({})", display_comma_separated(parts))?;
5428 }
5429 }
5430 if let Some(HiveLoadDataFormat {
5431 serde,
5432 input_format,
5433 }) = &table_format
5434 {
5435 write!(f, " INPUTFORMAT {input_format} SERDE {serde}")?;
5436 }
5437 Ok(())
5438 }
5439 Statement::CreateVirtualTable {
5440 name,
5441 if_not_exists,
5442 module_name,
5443 module_args,
5444 } => {
5445 write!(
5446 f,
5447 "CREATE VIRTUAL TABLE {if_not_exists}{name} USING {module_name}",
5448 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5449 name = name,
5450 module_name = module_name
5451 )?;
5452 if !module_args.is_empty() {
5453 write!(f, " ({})", display_comma_separated(module_args))?;
5454 }
5455 Ok(())
5456 }
5457 Statement::CreateIndex(create_index) => create_index.fmt(f),
5458 Statement::CreateExtension(create_extension) => write!(f, "{create_extension}"),
5459 Statement::CreateCollation(create_collation) => write!(f, "{create_collation}"),
5460 Statement::DropExtension(drop_extension) => write!(f, "{drop_extension}"),
5461 Statement::DropOperator(drop_operator) => write!(f, "{drop_operator}"),
5462 Statement::DropOperatorFamily(drop_operator_family) => {
5463 write!(f, "{drop_operator_family}")
5464 }
5465 Statement::DropOperatorClass(drop_operator_class) => {
5466 write!(f, "{drop_operator_class}")
5467 }
5468 Statement::CreateRole(create_role) => write!(f, "{create_role}"),
5469 Statement::CreateSecret {
5470 or_replace,
5471 temporary,
5472 if_not_exists,
5473 name,
5474 storage_specifier,
5475 secret_type,
5476 options,
5477 } => {
5478 write!(
5479 f,
5480 "CREATE {or_replace}",
5481 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5482 )?;
5483 if let Some(t) = temporary {
5484 write!(f, "{}", if *t { "TEMPORARY " } else { "PERSISTENT " })?;
5485 }
5486 write!(
5487 f,
5488 "SECRET {if_not_exists}",
5489 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5490 )?;
5491 if let Some(n) = name {
5492 write!(f, "{n} ")?;
5493 };
5494 if let Some(s) = storage_specifier {
5495 write!(f, "IN {s} ")?;
5496 }
5497 write!(f, "( TYPE {secret_type}",)?;
5498 if !options.is_empty() {
5499 write!(f, ", {o}", o = display_comma_separated(options))?;
5500 }
5501 write!(f, " )")?;
5502 Ok(())
5503 }
5504 Statement::CreateServer(stmt) => {
5505 write!(f, "{stmt}")
5506 }
5507 Statement::CreatePolicy(policy) => write!(f, "{policy}"),
5508 Statement::CreateConnector(create_connector) => create_connector.fmt(f),
5509 Statement::CreateOperator(create_operator) => create_operator.fmt(f),
5510 Statement::CreateOperatorFamily(create_operator_family) => {
5511 create_operator_family.fmt(f)
5512 }
5513 Statement::CreateOperatorClass(create_operator_class) => create_operator_class.fmt(f),
5514 Statement::AlterTable(alter_table) => write!(f, "{alter_table}"),
5515 Statement::AlterIndex { name, operation } => {
5516 write!(f, "ALTER INDEX {name} {operation}")
5517 }
5518 Statement::AlterView {
5519 name,
5520 columns,
5521 query,
5522 with_options,
5523 } => {
5524 write!(f, "ALTER VIEW {name}")?;
5525 if !with_options.is_empty() {
5526 write!(f, " WITH ({})", display_comma_separated(with_options))?;
5527 }
5528 if !columns.is_empty() {
5529 write!(f, " ({})", display_comma_separated(columns))?;
5530 }
5531 write!(f, " AS {query}")
5532 }
5533 Statement::AlterFunction(alter_function) => write!(f, "{alter_function}"),
5534 Statement::AlterType(AlterType { name, operation }) => {
5535 write!(f, "ALTER TYPE {name} {operation}")
5536 }
5537 Statement::AlterCollation(alter_collation) => write!(f, "{alter_collation}"),
5538 Statement::AlterOperator(alter_operator) => write!(f, "{alter_operator}"),
5539 Statement::AlterOperatorFamily(alter_operator_family) => {
5540 write!(f, "{alter_operator_family}")
5541 }
5542 Statement::AlterOperatorClass(alter_operator_class) => {
5543 write!(f, "{alter_operator_class}")
5544 }
5545 Statement::AlterRole { name, operation } => {
5546 write!(f, "ALTER ROLE {name} {operation}")
5547 }
5548 Statement::AlterPolicy(alter_policy) => write!(f, "{alter_policy}"),
5549 Statement::AlterConnector {
5550 name,
5551 properties,
5552 url,
5553 owner,
5554 } => {
5555 write!(f, "ALTER CONNECTOR {name}")?;
5556 if let Some(properties) = properties {
5557 write!(
5558 f,
5559 " SET DCPROPERTIES({})",
5560 display_comma_separated(properties)
5561 )?;
5562 }
5563 if let Some(url) = url {
5564 write!(f, " SET URL '{url}'")?;
5565 }
5566 if let Some(owner) = owner {
5567 write!(f, " SET OWNER {owner}")?;
5568 }
5569 Ok(())
5570 }
5571 Statement::AlterSession {
5572 set,
5573 session_params,
5574 } => {
5575 write!(
5576 f,
5577 "ALTER SESSION {set}",
5578 set = if *set { "SET" } else { "UNSET" }
5579 )?;
5580 if !session_params.options.is_empty() {
5581 if *set {
5582 write!(f, " {session_params}")?;
5583 } else {
5584 let options = session_params
5585 .options
5586 .iter()
5587 .map(|p| p.option_name.clone())
5588 .collect::<Vec<_>>();
5589 write!(f, " {}", display_separated(&options, ", "))?;
5590 }
5591 }
5592 Ok(())
5593 }
5594 Statement::Drop {
5595 object_type,
5596 if_exists,
5597 names,
5598 cascade,
5599 restrict,
5600 purge,
5601 temporary,
5602 table,
5603 } => {
5604 write!(
5605 f,
5606 "DROP {}{}{} {}{}{}{}",
5607 if *temporary { "TEMPORARY " } else { "" },
5608 object_type,
5609 if *if_exists { " IF EXISTS" } else { "" },
5610 display_comma_separated(names),
5611 if *cascade { " CASCADE" } else { "" },
5612 if *restrict { " RESTRICT" } else { "" },
5613 if *purge { " PURGE" } else { "" },
5614 )?;
5615 if let Some(table_name) = table.as_ref() {
5616 write!(f, " ON {table_name}")?;
5617 };
5618 Ok(())
5619 }
5620 Statement::DropFunction(drop_function) => write!(f, "{drop_function}"),
5621 Statement::DropDomain(DropDomain {
5622 if_exists,
5623 name,
5624 drop_behavior,
5625 }) => {
5626 write!(
5627 f,
5628 "DROP DOMAIN{} {name}",
5629 if *if_exists { " IF EXISTS" } else { "" },
5630 )?;
5631 if let Some(op) = drop_behavior {
5632 write!(f, " {op}")?;
5633 }
5634 Ok(())
5635 }
5636 Statement::DropProcedure {
5637 if_exists,
5638 proc_desc,
5639 drop_behavior,
5640 } => {
5641 write!(
5642 f,
5643 "DROP PROCEDURE{} {}",
5644 if *if_exists { " IF EXISTS" } else { "" },
5645 display_comma_separated(proc_desc),
5646 )?;
5647 if let Some(op) = drop_behavior {
5648 write!(f, " {op}")?;
5649 }
5650 Ok(())
5651 }
5652 Statement::DropSecret {
5653 if_exists,
5654 temporary,
5655 name,
5656 storage_specifier,
5657 } => {
5658 write!(f, "DROP ")?;
5659 if let Some(t) = temporary {
5660 write!(f, "{}", if *t { "TEMPORARY " } else { "PERSISTENT " })?;
5661 }
5662 write!(
5663 f,
5664 "SECRET {if_exists}{name}",
5665 if_exists = if *if_exists { "IF EXISTS " } else { "" },
5666 )?;
5667 if let Some(s) = storage_specifier {
5668 write!(f, " FROM {s}")?;
5669 }
5670 Ok(())
5671 }
5672 Statement::DropPolicy(policy) => write!(f, "{policy}"),
5673 Statement::DropConnector { if_exists, name } => {
5674 write!(
5675 f,
5676 "DROP CONNECTOR {if_exists}{name}",
5677 if_exists = if *if_exists { "IF EXISTS " } else { "" }
5678 )?;
5679 Ok(())
5680 }
5681 Statement::Discard { object_type } => {
5682 write!(f, "DISCARD {object_type}")?;
5683 Ok(())
5684 }
5685 Self::Set(set) => write!(f, "{set}"),
5686 Statement::ShowVariable { variable } => {
5687 write!(f, "SHOW")?;
5688 if !variable.is_empty() {
5689 write!(f, " {}", display_separated(variable, " "))?;
5690 }
5691 Ok(())
5692 }
5693 Statement::ShowStatus {
5694 filter,
5695 global,
5696 session,
5697 } => {
5698 write!(f, "SHOW")?;
5699 if *global {
5700 write!(f, " GLOBAL")?;
5701 }
5702 if *session {
5703 write!(f, " SESSION")?;
5704 }
5705 write!(f, " STATUS")?;
5706 if filter.is_some() {
5707 write!(f, " {}", filter.as_ref().unwrap())?;
5708 }
5709 Ok(())
5710 }
5711 Statement::ShowVariables {
5712 filter,
5713 global,
5714 session,
5715 } => {
5716 write!(f, "SHOW")?;
5717 if *global {
5718 write!(f, " GLOBAL")?;
5719 }
5720 if *session {
5721 write!(f, " SESSION")?;
5722 }
5723 write!(f, " VARIABLES")?;
5724 if filter.is_some() {
5725 write!(f, " {}", filter.as_ref().unwrap())?;
5726 }
5727 Ok(())
5728 }
5729 Statement::ShowCreate { obj_type, obj_name } => {
5730 write!(f, "SHOW CREATE {obj_type} {obj_name}",)?;
5731 Ok(())
5732 }
5733 Statement::ShowColumns {
5734 extended,
5735 full,
5736 show_options,
5737 } => {
5738 write!(
5739 f,
5740 "SHOW {extended}{full}COLUMNS{show_options}",
5741 extended = if *extended { "EXTENDED " } else { "" },
5742 full = if *full { "FULL " } else { "" },
5743 )?;
5744 Ok(())
5745 }
5746 Statement::ShowDatabases {
5747 terse,
5748 history,
5749 show_options,
5750 } => {
5751 write!(
5752 f,
5753 "SHOW {terse}DATABASES{history}{show_options}",
5754 terse = if *terse { "TERSE " } else { "" },
5755 history = if *history { " HISTORY" } else { "" },
5756 )?;
5757 Ok(())
5758 }
5759 Statement::ShowCatalogs {
5760 terse,
5761 history,
5762 show_options,
5763 } => {
5764 write!(
5765 f,
5766 "SHOW {terse}CATALOGS{history}{show_options}",
5767 terse = if *terse { "TERSE " } else { "" },
5768 history = if *history { " HISTORY" } else { "" },
5769 )?;
5770 Ok(())
5771 }
5772 Statement::ShowProcessList { full } => {
5773 write!(
5774 f,
5775 "SHOW {full}PROCESSLIST",
5776 full = if *full { "FULL " } else { "" },
5777 )?;
5778 Ok(())
5779 }
5780 Statement::ShowSchemas {
5781 terse,
5782 history,
5783 show_options,
5784 } => {
5785 write!(
5786 f,
5787 "SHOW {terse}SCHEMAS{history}{show_options}",
5788 terse = if *terse { "TERSE " } else { "" },
5789 history = if *history { " HISTORY" } else { "" },
5790 )?;
5791 Ok(())
5792 }
5793 Statement::ShowObjects(ShowObjects {
5794 terse,
5795 show_options,
5796 }) => {
5797 write!(
5798 f,
5799 "SHOW {terse}OBJECTS{show_options}",
5800 terse = if *terse { "TERSE " } else { "" },
5801 )?;
5802 Ok(())
5803 }
5804 Statement::ShowTables {
5805 terse,
5806 history,
5807 extended,
5808 full,
5809 external,
5810 show_options,
5811 } => {
5812 write!(
5813 f,
5814 "SHOW {terse}{extended}{full}{external}TABLES{history}{show_options}",
5815 terse = if *terse { "TERSE " } else { "" },
5816 extended = if *extended { "EXTENDED " } else { "" },
5817 full = if *full { "FULL " } else { "" },
5818 external = if *external { "EXTERNAL " } else { "" },
5819 history = if *history { " HISTORY" } else { "" },
5820 )?;
5821 Ok(())
5822 }
5823 Statement::ShowViews {
5824 terse,
5825 materialized,
5826 show_options,
5827 } => {
5828 write!(
5829 f,
5830 "SHOW {terse}{materialized}VIEWS{show_options}",
5831 terse = if *terse { "TERSE " } else { "" },
5832 materialized = if *materialized { "MATERIALIZED " } else { "" }
5833 )?;
5834 Ok(())
5835 }
5836 Statement::ShowFunctions { filter } => {
5837 write!(f, "SHOW FUNCTIONS")?;
5838 if let Some(filter) = filter {
5839 write!(f, " {filter}")?;
5840 }
5841 Ok(())
5842 }
5843 Statement::Use(use_expr) => use_expr.fmt(f),
5844 Statement::ShowCollation { filter } => {
5845 write!(f, "SHOW COLLATION")?;
5846 if let Some(filter) = filter {
5847 write!(f, " {filter}")?;
5848 }
5849 Ok(())
5850 }
5851 Statement::ShowCharset(show_stm) => show_stm.fmt(f),
5852 Statement::StartTransaction {
5853 modes,
5854 begin: syntax_begin,
5855 transaction,
5856 modifier,
5857 statements,
5858 exception,
5859 has_end_keyword,
5860 } => {
5861 if *syntax_begin {
5862 if let Some(modifier) = *modifier {
5863 write!(f, "BEGIN {modifier}")?;
5864 } else {
5865 write!(f, "BEGIN")?;
5866 }
5867 } else {
5868 write!(f, "START")?;
5869 }
5870 if let Some(transaction) = transaction {
5871 write!(f, " {transaction}")?;
5872 }
5873 if !modes.is_empty() {
5874 write!(f, " {}", display_comma_separated(modes))?;
5875 }
5876 if !statements.is_empty() {
5877 write!(f, " ")?;
5878 format_statement_list(f, statements)?;
5879 }
5880 if let Some(exception_when) = exception {
5881 write!(f, " EXCEPTION")?;
5882 for when in exception_when {
5883 write!(f, " {when}")?;
5884 }
5885 }
5886 if *has_end_keyword {
5887 write!(f, " END")?;
5888 }
5889 Ok(())
5890 }
5891 Statement::Commit {
5892 chain,
5893 end: end_syntax,
5894 modifier,
5895 } => {
5896 if *end_syntax {
5897 write!(f, "END")?;
5898 if let Some(modifier) = *modifier {
5899 write!(f, " {modifier}")?;
5900 }
5901 if *chain {
5902 write!(f, " AND CHAIN")?;
5903 }
5904 } else {
5905 write!(f, "COMMIT{}", if *chain { " AND CHAIN" } else { "" })?;
5906 }
5907 Ok(())
5908 }
5909 Statement::Rollback { chain, savepoint } => {
5910 write!(f, "ROLLBACK")?;
5911
5912 if *chain {
5913 write!(f, " AND CHAIN")?;
5914 }
5915
5916 if let Some(savepoint) = savepoint {
5917 write!(f, " TO SAVEPOINT {savepoint}")?;
5918 }
5919
5920 Ok(())
5921 }
5922 Statement::CreateSchema {
5923 schema_name,
5924 if_not_exists,
5925 with,
5926 options,
5927 default_collate_spec,
5928 clone,
5929 } => {
5930 write!(
5931 f,
5932 "CREATE SCHEMA {if_not_exists}{name}",
5933 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5934 name = schema_name
5935 )?;
5936
5937 if let Some(collate) = default_collate_spec {
5938 write!(f, " DEFAULT COLLATE {collate}")?;
5939 }
5940
5941 if let Some(with) = with {
5942 write!(f, " WITH ({})", display_comma_separated(with))?;
5943 }
5944
5945 if let Some(options) = options {
5946 write!(f, " OPTIONS({})", display_comma_separated(options))?;
5947 }
5948
5949 if let Some(clone) = clone {
5950 write!(f, " CLONE {clone}")?;
5951 }
5952 Ok(())
5953 }
5954 Statement::Assert { condition, message } => {
5955 write!(f, "ASSERT {condition}")?;
5956 if let Some(m) = message {
5957 write!(f, " AS {m}")?;
5958 }
5959 Ok(())
5960 }
5961 Statement::Grant(grant) => write!(f, "{grant}"),
5962 Statement::Deny(s) => write!(f, "{s}"),
5963 Statement::Revoke(revoke) => write!(f, "{revoke}"),
5964 Statement::Deallocate { name, prepare } => write!(
5965 f,
5966 "DEALLOCATE {prepare}{name}",
5967 prepare = if *prepare { "PREPARE " } else { "" },
5968 name = name,
5969 ),
5970 Statement::Execute {
5971 name,
5972 parameters,
5973 has_parentheses,
5974 immediate,
5975 into,
5976 using,
5977 output,
5978 default,
5979 } => {
5980 let (open, close) = if *has_parentheses {
5981 (if name.is_some() { "(" } else { " (" }, ")")
5983 } else {
5984 (if parameters.is_empty() { "" } else { " " }, "")
5985 };
5986 write!(f, "EXECUTE")?;
5987 if *immediate {
5988 write!(f, " IMMEDIATE")?;
5989 }
5990 if let Some(name) = name {
5991 write!(f, " {name}")?;
5992 }
5993 write!(f, "{open}{}{close}", display_comma_separated(parameters),)?;
5994 if !into.is_empty() {
5995 write!(f, " INTO {}", display_comma_separated(into))?;
5996 }
5997 if !using.is_empty() {
5998 write!(f, " USING {}", display_comma_separated(using))?;
5999 };
6000 if *output {
6001 write!(f, " OUTPUT")?;
6002 }
6003 if *default {
6004 write!(f, " DEFAULT")?;
6005 }
6006 Ok(())
6007 }
6008 Statement::Prepare {
6009 name,
6010 data_types,
6011 statement,
6012 } => {
6013 write!(f, "PREPARE {name} ")?;
6014 if !data_types.is_empty() {
6015 write!(f, "({}) ", display_comma_separated(data_types))?;
6016 }
6017 write!(f, "AS {statement}")
6018 }
6019 Statement::Comment {
6020 object_type,
6021 object_name,
6022 comment,
6023 if_exists,
6024 } => {
6025 write!(f, "COMMENT ")?;
6026 if *if_exists {
6027 write!(f, "IF EXISTS ")?
6028 };
6029 write!(f, "ON {object_type} {object_name} IS ")?;
6030 if let Some(c) = comment {
6031 write!(f, "'{c}'")
6032 } else {
6033 write!(f, "NULL")
6034 }
6035 }
6036 Statement::Savepoint { name } => {
6037 write!(f, "SAVEPOINT ")?;
6038 write!(f, "{name}")
6039 }
6040 Statement::ReleaseSavepoint { name } => {
6041 write!(f, "RELEASE SAVEPOINT {name}")
6042 }
6043 Statement::Merge(merge) => merge.fmt(f),
6044 Statement::Cache {
6045 table_name,
6046 table_flag,
6047 has_as,
6048 options,
6049 query,
6050 } => {
6051 if let Some(table_flag) = table_flag {
6052 write!(f, "CACHE {table_flag} TABLE {table_name}")?;
6053 } else {
6054 write!(f, "CACHE TABLE {table_name}")?;
6055 }
6056
6057 if !options.is_empty() {
6058 write!(f, " OPTIONS({})", display_comma_separated(options))?;
6059 }
6060
6061 match (*has_as, query) {
6062 (true, Some(query)) => write!(f, " AS {query}"),
6063 (true, None) => f.write_str(" AS"),
6064 (false, Some(query)) => write!(f, " {query}"),
6065 (false, None) => Ok(()),
6066 }
6067 }
6068 Statement::UNCache {
6069 table_name,
6070 if_exists,
6071 } => {
6072 if *if_exists {
6073 write!(f, "UNCACHE TABLE IF EXISTS {table_name}")
6074 } else {
6075 write!(f, "UNCACHE TABLE {table_name}")
6076 }
6077 }
6078 Statement::CreateSequence {
6079 temporary,
6080 if_not_exists,
6081 name,
6082 data_type,
6083 sequence_options,
6084 owned_by,
6085 } => {
6086 let as_type: String = if let Some(dt) = data_type.as_ref() {
6087 [" AS ", &dt.to_string()].concat()
6090 } else {
6091 "".to_string()
6092 };
6093 write!(
6094 f,
6095 "CREATE {temporary}SEQUENCE {if_not_exists}{name}{as_type}",
6096 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
6097 temporary = if *temporary { "TEMPORARY " } else { "" },
6098 name = name,
6099 as_type = as_type
6100 )?;
6101 for sequence_option in sequence_options {
6102 write!(f, "{sequence_option}")?;
6103 }
6104 if let Some(ob) = owned_by.as_ref() {
6105 write!(f, " OWNED BY {ob}")?;
6106 }
6107 write!(f, "")
6108 }
6109 Statement::CreateStage {
6110 or_replace,
6111 temporary,
6112 if_not_exists,
6113 name,
6114 stage_params,
6115 directory_table_params,
6116 file_format,
6117 copy_options,
6118 comment,
6119 ..
6120 } => {
6121 write!(
6122 f,
6123 "CREATE {or_replace}{temp}STAGE {if_not_exists}{name}{stage_params}",
6124 temp = if *temporary { "TEMPORARY " } else { "" },
6125 or_replace = if *or_replace { "OR REPLACE " } else { "" },
6126 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
6127 )?;
6128 if !directory_table_params.options.is_empty() {
6129 write!(f, " DIRECTORY=({directory_table_params})")?;
6130 }
6131 if !file_format.options.is_empty() {
6132 write!(f, " FILE_FORMAT=({file_format})")?;
6133 }
6134 if !copy_options.options.is_empty() {
6135 write!(f, " COPY_OPTIONS=({copy_options})")?;
6136 }
6137 if comment.is_some() {
6138 write!(f, " COMMENT='{}'", comment.as_ref().unwrap())?;
6139 }
6140 Ok(())
6141 }
6142 Statement::CopyIntoSnowflake {
6143 kind,
6144 into,
6145 into_columns,
6146 from_obj,
6147 from_obj_alias,
6148 stage_params,
6149 from_transformations,
6150 from_query,
6151 files,
6152 pattern,
6153 file_format,
6154 copy_options,
6155 validation_mode,
6156 partition,
6157 } => {
6158 write!(f, "COPY INTO {into}")?;
6159 if let Some(into_columns) = into_columns {
6160 write!(f, " ({})", display_comma_separated(into_columns))?;
6161 }
6162 if let Some(from_transformations) = from_transformations {
6163 if let Some(from_stage) = from_obj {
6165 write!(
6166 f,
6167 " FROM (SELECT {} FROM {}{}",
6168 display_separated(from_transformations, ", "),
6169 from_stage,
6170 stage_params
6171 )?;
6172 }
6173 if let Some(from_obj_alias) = from_obj_alias {
6174 write!(f, " AS {from_obj_alias}")?;
6175 }
6176 write!(f, ")")?;
6177 } else if let Some(from_obj) = from_obj {
6178 write!(f, " FROM {from_obj}{stage_params}")?;
6180 if let Some(from_obj_alias) = from_obj_alias {
6181 write!(f, " AS {from_obj_alias}")?;
6182 }
6183 } else if let Some(from_query) = from_query {
6184 write!(f, " FROM ({from_query})")?;
6186 }
6187
6188 if let Some(files) = files {
6189 write!(f, " FILES = ('{}')", display_separated(files, "', '"))?;
6190 }
6191 if let Some(pattern) = pattern {
6192 write!(f, " PATTERN = '{pattern}'")?;
6193 }
6194 if let Some(partition) = partition {
6195 write!(f, " PARTITION BY {partition}")?;
6196 }
6197 if !file_format.options.is_empty() {
6198 write!(f, " FILE_FORMAT=({file_format})")?;
6199 }
6200 if !copy_options.options.is_empty() {
6201 match kind {
6202 CopyIntoSnowflakeKind::Table => {
6203 write!(f, " COPY_OPTIONS=({copy_options})")?
6204 }
6205 CopyIntoSnowflakeKind::Location => write!(f, " {copy_options}")?,
6206 }
6207 }
6208 if let Some(validation_mode) = validation_mode {
6209 write!(f, " VALIDATION_MODE = {validation_mode}")?;
6210 }
6211 Ok(())
6212 }
6213 Statement::CreateType {
6214 name,
6215 representation,
6216 } => {
6217 write!(f, "CREATE TYPE {name}")?;
6218 if let Some(repr) = representation {
6219 write!(f, " {repr}")?;
6220 }
6221 Ok(())
6222 }
6223 Statement::Pragma { name, value, is_eq } => {
6224 write!(f, "PRAGMA {name}")?;
6225 if value.is_some() {
6226 let val = value.as_ref().unwrap();
6227 if *is_eq {
6228 write!(f, " = {val}")?;
6229 } else {
6230 write!(f, "({val})")?;
6231 }
6232 }
6233 Ok(())
6234 }
6235 Statement::Lock(lock) => lock.fmt(f),
6236 Statement::LockTables { tables } => {
6237 write!(f, "LOCK TABLES {}", display_comma_separated(tables))
6238 }
6239 Statement::UnlockTables => {
6240 write!(f, "UNLOCK TABLES")
6241 }
6242 Statement::Unload {
6243 query,
6244 query_text,
6245 to,
6246 auth,
6247 with,
6248 options,
6249 } => {
6250 write!(f, "UNLOAD(")?;
6251 if let Some(query) = query {
6252 write!(f, "{query}")?;
6253 }
6254 if let Some(query_text) = query_text {
6255 write!(f, "'{query_text}'")?;
6256 }
6257 write!(f, ") TO {to}")?;
6258 if let Some(auth) = auth {
6259 write!(f, " IAM_ROLE {auth}")?;
6260 }
6261 if !with.is_empty() {
6262 write!(f, " WITH ({})", display_comma_separated(with))?;
6263 }
6264 if !options.is_empty() {
6265 write!(f, " {}", display_separated(options, " "))?;
6266 }
6267 Ok(())
6268 }
6269 Statement::OptimizeTable {
6270 name,
6271 has_table_keyword,
6272 on_cluster,
6273 partition,
6274 include_final,
6275 deduplicate,
6276 predicate,
6277 zorder,
6278 } => {
6279 write!(f, "OPTIMIZE")?;
6280 if *has_table_keyword {
6281 write!(f, " TABLE")?;
6282 }
6283 write!(f, " {name}")?;
6284 if let Some(on_cluster) = on_cluster {
6285 write!(f, " ON CLUSTER {on_cluster}")?;
6286 }
6287 if let Some(partition) = partition {
6288 write!(f, " {partition}")?;
6289 }
6290 if *include_final {
6291 write!(f, " FINAL")?;
6292 }
6293 if let Some(deduplicate) = deduplicate {
6294 write!(f, " {deduplicate}")?;
6295 }
6296 if let Some(predicate) = predicate {
6297 write!(f, " WHERE {predicate}")?;
6298 }
6299 if let Some(zorder) = zorder {
6300 write!(f, " ZORDER BY ({})", display_comma_separated(zorder))?;
6301 }
6302 Ok(())
6303 }
6304 Statement::LISTEN { channel } => {
6305 write!(f, "LISTEN {channel}")?;
6306 Ok(())
6307 }
6308 Statement::UNLISTEN { channel } => {
6309 write!(f, "UNLISTEN {channel}")?;
6310 Ok(())
6311 }
6312 Statement::NOTIFY { channel, payload } => {
6313 write!(f, "NOTIFY {channel}")?;
6314 if let Some(payload) = payload {
6315 write!(f, ", '{payload}'")?;
6316 }
6317 Ok(())
6318 }
6319 Statement::RenameTable(rename_tables) => {
6320 write!(f, "RENAME TABLE {}", display_comma_separated(rename_tables))
6321 }
6322 Statement::RaisError {
6323 message,
6324 severity,
6325 state,
6326 arguments,
6327 options,
6328 } => {
6329 write!(f, "RAISERROR({message}, {severity}, {state}")?;
6330 if !arguments.is_empty() {
6331 write!(f, ", {}", display_comma_separated(arguments))?;
6332 }
6333 write!(f, ")")?;
6334 if !options.is_empty() {
6335 write!(f, " WITH {}", display_comma_separated(options))?;
6336 }
6337 Ok(())
6338 }
6339 Statement::Throw(s) => write!(f, "{s}"),
6340 Statement::Print(s) => write!(f, "{s}"),
6341 Statement::WaitFor(s) => write!(f, "{s}"),
6342 Statement::Return(r) => write!(f, "{r}"),
6343 Statement::List(command) => write!(f, "LIST {command}"),
6344 Statement::Remove(command) => write!(f, "REMOVE {command}"),
6345 Statement::ExportData(e) => write!(f, "{e}"),
6346 Statement::CreateUser(s) => write!(f, "{s}"),
6347 Statement::AlterSchema(s) => write!(f, "{s}"),
6348 Statement::Vacuum(s) => write!(f, "{s}"),
6349 Statement::AlterUser(s) => write!(f, "{s}"),
6350 Statement::Reset(s) => write!(f, "{s}"),
6351 }
6352 }
6353}
6354
6355#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6362#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6363#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6364pub enum SequenceOptions {
6365 IncrementBy(Expr, bool),
6367 MinValue(Option<Expr>),
6369 MaxValue(Option<Expr>),
6371 StartWith(Expr, bool),
6373 Cache(Expr),
6375 Cycle(bool),
6377}
6378
6379impl fmt::Display for SequenceOptions {
6380 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6381 match self {
6382 SequenceOptions::IncrementBy(increment, by) => {
6383 write!(
6384 f,
6385 " INCREMENT{by} {increment}",
6386 by = if *by { " BY" } else { "" },
6387 increment = increment
6388 )
6389 }
6390 SequenceOptions::MinValue(Some(expr)) => {
6391 write!(f, " MINVALUE {expr}")
6392 }
6393 SequenceOptions::MinValue(None) => {
6394 write!(f, " NO MINVALUE")
6395 }
6396 SequenceOptions::MaxValue(Some(expr)) => {
6397 write!(f, " MAXVALUE {expr}")
6398 }
6399 SequenceOptions::MaxValue(None) => {
6400 write!(f, " NO MAXVALUE")
6401 }
6402 SequenceOptions::StartWith(start, with) => {
6403 write!(
6404 f,
6405 " START{with} {start}",
6406 with = if *with { " WITH" } else { "" },
6407 start = start
6408 )
6409 }
6410 SequenceOptions::Cache(cache) => {
6411 write!(f, " CACHE {}", *cache)
6412 }
6413 SequenceOptions::Cycle(no) => {
6414 write!(f, " {}CYCLE", if *no { "NO " } else { "" })
6415 }
6416 }
6417 }
6418}
6419
6420#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6422#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6423#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6424pub struct SetAssignment {
6425 pub scope: Option<ContextModifier>,
6427 pub name: ObjectName,
6429 pub value: Expr,
6431}
6432
6433impl fmt::Display for SetAssignment {
6434 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6435 write!(
6436 f,
6437 "{}{} = {}",
6438 self.scope.map(|s| format!("{s}")).unwrap_or_default(),
6439 self.name,
6440 self.value
6441 )
6442 }
6443}
6444
6445#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6449#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6450#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6451pub struct TruncateTableTarget {
6452 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
6454 pub name: ObjectName,
6455 pub only: bool,
6461 pub has_asterisk: bool,
6467}
6468
6469impl fmt::Display for TruncateTableTarget {
6470 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6471 if self.only {
6472 write!(f, "ONLY ")?;
6473 };
6474 write!(f, "{}", self.name)?;
6475 if self.has_asterisk {
6476 write!(f, " *")?;
6477 };
6478 Ok(())
6479 }
6480}
6481
6482#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6486#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6487#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6488pub struct Lock {
6489 pub tables: Vec<LockTableTarget>,
6491 pub lock_mode: Option<LockTableMode>,
6493 pub nowait: bool,
6495}
6496
6497impl fmt::Display for Lock {
6498 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6499 write!(f, "LOCK TABLE {}", display_comma_separated(&self.tables))?;
6500 if let Some(lock_mode) = &self.lock_mode {
6501 write!(f, " IN {lock_mode} MODE")?;
6502 }
6503 if self.nowait {
6504 write!(f, " NOWAIT")?;
6505 }
6506 Ok(())
6507 }
6508}
6509
6510#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6514#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6515#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6516pub struct LockTableTarget {
6517 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
6519 pub name: ObjectName,
6520 pub only: bool,
6522 pub has_asterisk: bool,
6524}
6525
6526impl fmt::Display for LockTableTarget {
6527 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6528 if self.only {
6529 write!(f, "ONLY ")?;
6530 }
6531 write!(f, "{}", self.name)?;
6532 if self.has_asterisk {
6533 write!(f, " *")?;
6534 }
6535 Ok(())
6536 }
6537}
6538
6539#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6543#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6544#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6545pub enum LockTableMode {
6546 AccessShare,
6548 RowShare,
6550 RowExclusive,
6552 ShareUpdateExclusive,
6554 Share,
6556 ShareRowExclusive,
6558 Exclusive,
6560 AccessExclusive,
6562}
6563
6564impl fmt::Display for LockTableMode {
6565 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6566 let text = match self {
6567 Self::AccessShare => "ACCESS SHARE",
6568 Self::RowShare => "ROW SHARE",
6569 Self::RowExclusive => "ROW EXCLUSIVE",
6570 Self::ShareUpdateExclusive => "SHARE UPDATE EXCLUSIVE",
6571 Self::Share => "SHARE",
6572 Self::ShareRowExclusive => "SHARE ROW EXCLUSIVE",
6573 Self::Exclusive => "EXCLUSIVE",
6574 Self::AccessExclusive => "ACCESS EXCLUSIVE",
6575 };
6576 write!(f, "{text}")
6577 }
6578}
6579
6580#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6583#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6584#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6585pub enum TruncateIdentityOption {
6586 Restart,
6588 Continue,
6590}
6591
6592#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6595#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6596#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6597pub enum CascadeOption {
6598 Cascade,
6600 Restrict,
6602}
6603
6604impl Display for CascadeOption {
6605 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6606 match self {
6607 CascadeOption::Cascade => write!(f, "CASCADE"),
6608 CascadeOption::Restrict => write!(f, "RESTRICT"),
6609 }
6610 }
6611}
6612
6613#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6615#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6616#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6617pub enum BeginTransactionKind {
6618 Transaction,
6620 Work,
6622 Tran,
6625}
6626
6627impl Display for BeginTransactionKind {
6628 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6629 match self {
6630 BeginTransactionKind::Transaction => write!(f, "TRANSACTION"),
6631 BeginTransactionKind::Work => write!(f, "WORK"),
6632 BeginTransactionKind::Tran => write!(f, "TRAN"),
6633 }
6634 }
6635}
6636
6637#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6640#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6641#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6642pub enum MinMaxValue {
6643 Empty,
6645 None,
6647 Some(Expr),
6649}
6650
6651#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6652#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6653#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6654#[non_exhaustive]
6655pub enum OnInsert {
6657 DuplicateKeyUpdate(Vec<Assignment>),
6659 OnConflict(OnConflict),
6661}
6662
6663#[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 struct InsertAliases {
6668 pub row_alias: ObjectName,
6670 pub col_aliases: Option<Vec<Ident>>,
6672}
6673
6674#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6675#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6676#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6677pub struct TableAliasWithoutColumns {
6679 pub explicit: bool,
6681 pub alias: Ident,
6683}
6684
6685#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6686#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6687#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6688pub struct OnConflict {
6690 pub conflict_target: Option<ConflictTarget>,
6692 pub action: OnConflictAction,
6694}
6695#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6696#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6697#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6698pub enum ConflictTarget {
6700 Columns(Vec<Ident>),
6702 OnConstraint(ObjectName),
6704}
6705#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6706#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6707#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6708pub enum OnConflictAction {
6710 DoNothing,
6712 DoUpdate(DoUpdate),
6714}
6715
6716#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6717#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6718#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6719pub struct DoUpdate {
6721 pub assignments: Vec<Assignment>,
6723 pub selection: Option<Expr>,
6725}
6726
6727impl fmt::Display for OnInsert {
6728 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6729 match self {
6730 Self::DuplicateKeyUpdate(expr) => write!(
6731 f,
6732 " ON DUPLICATE KEY UPDATE {}",
6733 display_comma_separated(expr)
6734 ),
6735 Self::OnConflict(o) => write!(f, "{o}"),
6736 }
6737 }
6738}
6739impl fmt::Display for OnConflict {
6740 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6741 write!(f, " ON CONFLICT")?;
6742 if let Some(target) = &self.conflict_target {
6743 write!(f, "{target}")?;
6744 }
6745 write!(f, " {}", self.action)
6746 }
6747}
6748impl fmt::Display for ConflictTarget {
6749 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6750 match self {
6751 ConflictTarget::Columns(cols) => write!(f, "({})", display_comma_separated(cols)),
6752 ConflictTarget::OnConstraint(name) => write!(f, " ON CONSTRAINT {name}"),
6753 }
6754 }
6755}
6756impl fmt::Display for OnConflictAction {
6757 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6758 match self {
6759 Self::DoNothing => write!(f, "DO NOTHING"),
6760 Self::DoUpdate(do_update) => {
6761 write!(f, "DO UPDATE")?;
6762 if !do_update.assignments.is_empty() {
6763 write!(
6764 f,
6765 " SET {}",
6766 display_comma_separated(&do_update.assignments)
6767 )?;
6768 }
6769 if let Some(selection) = &do_update.selection {
6770 write!(f, " WHERE {selection}")?;
6771 }
6772 Ok(())
6773 }
6774 }
6775 }
6776}
6777
6778#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6780#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6781#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6782pub enum Privileges {
6783 All {
6785 with_privileges_keyword: bool,
6787 },
6788 Actions(Vec<Action>),
6790}
6791
6792impl fmt::Display for Privileges {
6793 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6794 match self {
6795 Privileges::All {
6796 with_privileges_keyword,
6797 } => {
6798 write!(
6799 f,
6800 "ALL{}",
6801 if *with_privileges_keyword {
6802 " PRIVILEGES"
6803 } else {
6804 ""
6805 }
6806 )
6807 }
6808 Privileges::Actions(actions) => {
6809 write!(f, "{}", display_comma_separated(actions))
6810 }
6811 }
6812 }
6813}
6814
6815#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6817#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6818#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6819pub enum FetchDirection {
6820 Count {
6822 limit: ValueWithSpan,
6824 },
6825 Next,
6827 Prior,
6829 First,
6831 Last,
6833 Absolute {
6835 limit: ValueWithSpan,
6837 },
6838 Relative {
6840 limit: ValueWithSpan,
6842 },
6843 All,
6845 Forward {
6849 limit: Option<ValueWithSpan>,
6851 },
6852 ForwardAll,
6854 Backward {
6858 limit: Option<ValueWithSpan>,
6860 },
6861 BackwardAll,
6863}
6864
6865impl fmt::Display for FetchDirection {
6866 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6867 match self {
6868 FetchDirection::Count { limit } => f.write_str(&limit.to_string())?,
6869 FetchDirection::Next => f.write_str("NEXT")?,
6870 FetchDirection::Prior => f.write_str("PRIOR")?,
6871 FetchDirection::First => f.write_str("FIRST")?,
6872 FetchDirection::Last => f.write_str("LAST")?,
6873 FetchDirection::Absolute { limit } => {
6874 f.write_str("ABSOLUTE ")?;
6875 f.write_str(&limit.to_string())?;
6876 }
6877 FetchDirection::Relative { limit } => {
6878 f.write_str("RELATIVE ")?;
6879 f.write_str(&limit.to_string())?;
6880 }
6881 FetchDirection::All => f.write_str("ALL")?,
6882 FetchDirection::Forward { limit } => {
6883 f.write_str("FORWARD")?;
6884
6885 if let Some(l) = limit {
6886 f.write_str(" ")?;
6887 f.write_str(&l.to_string())?;
6888 }
6889 }
6890 FetchDirection::ForwardAll => f.write_str("FORWARD ALL")?,
6891 FetchDirection::Backward { limit } => {
6892 f.write_str("BACKWARD")?;
6893
6894 if let Some(l) = limit {
6895 f.write_str(" ")?;
6896 f.write_str(&l.to_string())?;
6897 }
6898 }
6899 FetchDirection::BackwardAll => f.write_str("BACKWARD ALL")?,
6900 };
6901
6902 Ok(())
6903 }
6904}
6905
6906#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6910#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6911#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6912pub enum FetchPosition {
6913 From,
6915 In,
6917}
6918
6919impl fmt::Display for FetchPosition {
6920 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6921 match self {
6922 FetchPosition::From => f.write_str("FROM")?,
6923 FetchPosition::In => f.write_str("IN")?,
6924 };
6925
6926 Ok(())
6927 }
6928}
6929
6930#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6932#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6933#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6934pub enum Action {
6935 AddSearchOptimization,
6937 Apply {
6939 apply_type: ActionApplyType,
6941 },
6942 ApplyBudget,
6944 AttachListing,
6946 AttachPolicy,
6948 Audit,
6950 BindServiceEndpoint,
6952 Connect,
6954 Create {
6956 obj_type: Option<ActionCreateObjectType>,
6958 },
6959 DatabaseRole {
6961 role: ObjectName,
6963 },
6964 Delete,
6966 Drop,
6968 EvolveSchema,
6970 Exec {
6972 obj_type: Option<ActionExecuteObjectType>,
6974 },
6975 Execute {
6977 obj_type: Option<ActionExecuteObjectType>,
6979 },
6980 Failover,
6982 ImportedPrivileges,
6984 ImportShare,
6986 Insert {
6988 columns: Option<Vec<Ident>>,
6990 },
6991 Manage {
6993 manage_type: ActionManageType,
6995 },
6996 ManageReleases,
6998 ManageVersions,
7000 Modify {
7002 modify_type: Option<ActionModifyType>,
7004 },
7005 Monitor {
7007 monitor_type: Option<ActionMonitorType>,
7009 },
7010 Operate,
7012 OverrideShareRestrictions,
7014 Ownership,
7016 PurchaseDataExchangeListing,
7018
7019 Read,
7021 ReadSession,
7023 References {
7025 columns: Option<Vec<Ident>>,
7027 },
7028 Replicate,
7030 ResolveAll,
7032 Role {
7034 role: ObjectName,
7036 },
7037 Select {
7039 columns: Option<Vec<Ident>>,
7041 },
7042 Temporary,
7044 Trigger,
7046 Truncate,
7048 Update {
7050 columns: Option<Vec<Ident>>,
7052 },
7053 Usage,
7055}
7056
7057impl fmt::Display for Action {
7058 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7059 match self {
7060 Action::AddSearchOptimization => f.write_str("ADD SEARCH OPTIMIZATION")?,
7061 Action::Apply { apply_type } => write!(f, "APPLY {apply_type}")?,
7062 Action::ApplyBudget => f.write_str("APPLYBUDGET")?,
7063 Action::AttachListing => f.write_str("ATTACH LISTING")?,
7064 Action::AttachPolicy => f.write_str("ATTACH POLICY")?,
7065 Action::Audit => f.write_str("AUDIT")?,
7066 Action::BindServiceEndpoint => f.write_str("BIND SERVICE ENDPOINT")?,
7067 Action::Connect => f.write_str("CONNECT")?,
7068 Action::Create { obj_type } => {
7069 f.write_str("CREATE")?;
7070 if let Some(obj_type) = obj_type {
7071 write!(f, " {obj_type}")?
7072 }
7073 }
7074 Action::DatabaseRole { role } => write!(f, "DATABASE ROLE {role}")?,
7075 Action::Delete => f.write_str("DELETE")?,
7076 Action::Drop => f.write_str("DROP")?,
7077 Action::EvolveSchema => f.write_str("EVOLVE SCHEMA")?,
7078 Action::Exec { obj_type } => {
7079 f.write_str("EXEC")?;
7080 if let Some(obj_type) = obj_type {
7081 write!(f, " {obj_type}")?
7082 }
7083 }
7084 Action::Execute { obj_type } => {
7085 f.write_str("EXECUTE")?;
7086 if let Some(obj_type) = obj_type {
7087 write!(f, " {obj_type}")?
7088 }
7089 }
7090 Action::Failover => f.write_str("FAILOVER")?,
7091 Action::ImportedPrivileges => f.write_str("IMPORTED PRIVILEGES")?,
7092 Action::ImportShare => f.write_str("IMPORT SHARE")?,
7093 Action::Insert { .. } => f.write_str("INSERT")?,
7094 Action::Manage { manage_type } => write!(f, "MANAGE {manage_type}")?,
7095 Action::ManageReleases => f.write_str("MANAGE RELEASES")?,
7096 Action::ManageVersions => f.write_str("MANAGE VERSIONS")?,
7097 Action::Modify { modify_type } => {
7098 write!(f, "MODIFY")?;
7099 if let Some(modify_type) = modify_type {
7100 write!(f, " {modify_type}")?;
7101 }
7102 }
7103 Action::Monitor { monitor_type } => {
7104 write!(f, "MONITOR")?;
7105 if let Some(monitor_type) = monitor_type {
7106 write!(f, " {monitor_type}")?
7107 }
7108 }
7109 Action::Operate => f.write_str("OPERATE")?,
7110 Action::OverrideShareRestrictions => f.write_str("OVERRIDE SHARE RESTRICTIONS")?,
7111 Action::Ownership => f.write_str("OWNERSHIP")?,
7112 Action::PurchaseDataExchangeListing => f.write_str("PURCHASE DATA EXCHANGE LISTING")?,
7113 Action::Read => f.write_str("READ")?,
7114 Action::ReadSession => f.write_str("READ SESSION")?,
7115 Action::References { .. } => f.write_str("REFERENCES")?,
7116 Action::Replicate => f.write_str("REPLICATE")?,
7117 Action::ResolveAll => f.write_str("RESOLVE ALL")?,
7118 Action::Role { role } => write!(f, "ROLE {role}")?,
7119 Action::Select { .. } => f.write_str("SELECT")?,
7120 Action::Temporary => f.write_str("TEMPORARY")?,
7121 Action::Trigger => f.write_str("TRIGGER")?,
7122 Action::Truncate => f.write_str("TRUNCATE")?,
7123 Action::Update { .. } => f.write_str("UPDATE")?,
7124 Action::Usage => f.write_str("USAGE")?,
7125 };
7126 match self {
7127 Action::Insert { columns }
7128 | Action::References { columns }
7129 | Action::Select { columns }
7130 | Action::Update { columns } => {
7131 if let Some(columns) = columns {
7132 write!(f, " ({})", display_comma_separated(columns))?;
7133 }
7134 }
7135 _ => (),
7136 };
7137 Ok(())
7138 }
7139}
7140
7141#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7142#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7143#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7144pub enum ActionCreateObjectType {
7147 Account,
7149 Application,
7151 ApplicationPackage,
7153 ComputePool,
7155 DataExchangeListing,
7157 Database,
7159 ExternalVolume,
7161 FailoverGroup,
7163 Integration,
7165 NetworkPolicy,
7167 OrganiationListing,
7169 ReplicationGroup,
7171 Role,
7173 Schema,
7175 Share,
7177 User,
7179 Warehouse,
7181}
7182
7183impl fmt::Display for ActionCreateObjectType {
7184 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7185 match self {
7186 ActionCreateObjectType::Account => write!(f, "ACCOUNT"),
7187 ActionCreateObjectType::Application => write!(f, "APPLICATION"),
7188 ActionCreateObjectType::ApplicationPackage => write!(f, "APPLICATION PACKAGE"),
7189 ActionCreateObjectType::ComputePool => write!(f, "COMPUTE POOL"),
7190 ActionCreateObjectType::DataExchangeListing => write!(f, "DATA EXCHANGE LISTING"),
7191 ActionCreateObjectType::Database => write!(f, "DATABASE"),
7192 ActionCreateObjectType::ExternalVolume => write!(f, "EXTERNAL VOLUME"),
7193 ActionCreateObjectType::FailoverGroup => write!(f, "FAILOVER GROUP"),
7194 ActionCreateObjectType::Integration => write!(f, "INTEGRATION"),
7195 ActionCreateObjectType::NetworkPolicy => write!(f, "NETWORK POLICY"),
7196 ActionCreateObjectType::OrganiationListing => write!(f, "ORGANIZATION LISTING"),
7197 ActionCreateObjectType::ReplicationGroup => write!(f, "REPLICATION GROUP"),
7198 ActionCreateObjectType::Role => write!(f, "ROLE"),
7199 ActionCreateObjectType::Schema => write!(f, "SCHEMA"),
7200 ActionCreateObjectType::Share => write!(f, "SHARE"),
7201 ActionCreateObjectType::User => write!(f, "USER"),
7202 ActionCreateObjectType::Warehouse => write!(f, "WAREHOUSE"),
7203 }
7204 }
7205}
7206
7207#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7208#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7209#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7210pub enum ActionApplyType {
7213 AggregationPolicy,
7215 AuthenticationPolicy,
7217 JoinPolicy,
7219 MaskingPolicy,
7221 PackagesPolicy,
7223 PasswordPolicy,
7225 ProjectionPolicy,
7227 RowAccessPolicy,
7229 SessionPolicy,
7231 Tag,
7233}
7234
7235impl fmt::Display for ActionApplyType {
7236 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7237 match self {
7238 ActionApplyType::AggregationPolicy => write!(f, "AGGREGATION POLICY"),
7239 ActionApplyType::AuthenticationPolicy => write!(f, "AUTHENTICATION POLICY"),
7240 ActionApplyType::JoinPolicy => write!(f, "JOIN POLICY"),
7241 ActionApplyType::MaskingPolicy => write!(f, "MASKING POLICY"),
7242 ActionApplyType::PackagesPolicy => write!(f, "PACKAGES POLICY"),
7243 ActionApplyType::PasswordPolicy => write!(f, "PASSWORD POLICY"),
7244 ActionApplyType::ProjectionPolicy => write!(f, "PROJECTION POLICY"),
7245 ActionApplyType::RowAccessPolicy => write!(f, "ROW ACCESS POLICY"),
7246 ActionApplyType::SessionPolicy => write!(f, "SESSION POLICY"),
7247 ActionApplyType::Tag => write!(f, "TAG"),
7248 }
7249 }
7250}
7251
7252#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7253#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7254#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7255pub enum ActionExecuteObjectType {
7258 Alert,
7260 DataMetricFunction,
7262 ManagedAlert,
7264 ManagedTask,
7266 Task,
7268}
7269
7270impl fmt::Display for ActionExecuteObjectType {
7271 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7272 match self {
7273 ActionExecuteObjectType::Alert => write!(f, "ALERT"),
7274 ActionExecuteObjectType::DataMetricFunction => write!(f, "DATA METRIC FUNCTION"),
7275 ActionExecuteObjectType::ManagedAlert => write!(f, "MANAGED ALERT"),
7276 ActionExecuteObjectType::ManagedTask => write!(f, "MANAGED TASK"),
7277 ActionExecuteObjectType::Task => write!(f, "TASK"),
7278 }
7279 }
7280}
7281
7282#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7283#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7284#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7285pub enum ActionManageType {
7288 AccountSupportCases,
7290 EventSharing,
7292 Grants,
7294 ListingAutoFulfillment,
7296 OrganizationSupportCases,
7298 UserSupportCases,
7300 Warehouses,
7302}
7303
7304impl fmt::Display for ActionManageType {
7305 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7306 match self {
7307 ActionManageType::AccountSupportCases => write!(f, "ACCOUNT SUPPORT CASES"),
7308 ActionManageType::EventSharing => write!(f, "EVENT SHARING"),
7309 ActionManageType::Grants => write!(f, "GRANTS"),
7310 ActionManageType::ListingAutoFulfillment => write!(f, "LISTING AUTO FULFILLMENT"),
7311 ActionManageType::OrganizationSupportCases => write!(f, "ORGANIZATION SUPPORT CASES"),
7312 ActionManageType::UserSupportCases => write!(f, "USER SUPPORT CASES"),
7313 ActionManageType::Warehouses => write!(f, "WAREHOUSES"),
7314 }
7315 }
7316}
7317
7318#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7319#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7320#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7321pub enum ActionModifyType {
7324 LogLevel,
7326 TraceLevel,
7328 SessionLogLevel,
7330 SessionTraceLevel,
7332}
7333
7334impl fmt::Display for ActionModifyType {
7335 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7336 match self {
7337 ActionModifyType::LogLevel => write!(f, "LOG LEVEL"),
7338 ActionModifyType::TraceLevel => write!(f, "TRACE LEVEL"),
7339 ActionModifyType::SessionLogLevel => write!(f, "SESSION LOG LEVEL"),
7340 ActionModifyType::SessionTraceLevel => write!(f, "SESSION TRACE LEVEL"),
7341 }
7342 }
7343}
7344
7345#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7346#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7347#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7348pub enum ActionMonitorType {
7351 Execution,
7353 Security,
7355 Usage,
7357}
7358
7359impl fmt::Display for ActionMonitorType {
7360 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7361 match self {
7362 ActionMonitorType::Execution => write!(f, "EXECUTION"),
7363 ActionMonitorType::Security => write!(f, "SECURITY"),
7364 ActionMonitorType::Usage => write!(f, "USAGE"),
7365 }
7366 }
7367}
7368
7369#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7371#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7372#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7373pub struct Grantee {
7374 pub grantee_type: GranteesType,
7376 pub name: Option<GranteeName>,
7378}
7379
7380impl fmt::Display for Grantee {
7381 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7382 match self.grantee_type {
7383 GranteesType::Role => {
7384 write!(f, "ROLE ")?;
7385 }
7386 GranteesType::Share => {
7387 write!(f, "SHARE ")?;
7388 }
7389 GranteesType::User => {
7390 write!(f, "USER ")?;
7391 }
7392 GranteesType::Group => {
7393 write!(f, "GROUP ")?;
7394 }
7395 GranteesType::Public => {
7396 write!(f, "PUBLIC ")?;
7397 }
7398 GranteesType::DatabaseRole => {
7399 write!(f, "DATABASE ROLE ")?;
7400 }
7401 GranteesType::Application => {
7402 write!(f, "APPLICATION ")?;
7403 }
7404 GranteesType::ApplicationRole => {
7405 write!(f, "APPLICATION ROLE ")?;
7406 }
7407 GranteesType::None => (),
7408 }
7409 if let Some(ref name) = self.name {
7410 name.fmt(f)?;
7411 }
7412 Ok(())
7413 }
7414}
7415
7416#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7417#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7418#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7419pub enum GranteesType {
7421 Role,
7423 Share,
7425 User,
7427 Group,
7429 Public,
7431 DatabaseRole,
7433 Application,
7435 ApplicationRole,
7437 None,
7439}
7440
7441#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7443#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7444#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7445pub enum GranteeName {
7446 ObjectName(ObjectName),
7448 UserHost {
7450 user: Ident,
7452 host: Ident,
7454 },
7455}
7456
7457impl fmt::Display for GranteeName {
7458 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7459 match self {
7460 GranteeName::ObjectName(name) => name.fmt(f),
7461 GranteeName::UserHost { user, host } => {
7462 write!(f, "{user}@{host}")
7463 }
7464 }
7465 }
7466}
7467
7468#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7470#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7471#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7472pub enum GrantObjects {
7473 AllSequencesInSchema {
7475 schemas: Vec<ObjectName>,
7477 },
7478 AllTablesInSchema {
7480 schemas: Vec<ObjectName>,
7482 },
7483 AllViewsInSchema {
7485 schemas: Vec<ObjectName>,
7487 },
7488 AllMaterializedViewsInSchema {
7490 schemas: Vec<ObjectName>,
7492 },
7493 AllExternalTablesInSchema {
7495 schemas: Vec<ObjectName>,
7497 },
7498 AllFunctionsInSchema {
7500 schemas: Vec<ObjectName>,
7502 },
7503 FutureSchemasInDatabase {
7505 databases: Vec<ObjectName>,
7507 },
7508 FutureTablesInSchema {
7510 schemas: Vec<ObjectName>,
7512 },
7513 FutureViewsInSchema {
7515 schemas: Vec<ObjectName>,
7517 },
7518 FutureExternalTablesInSchema {
7520 schemas: Vec<ObjectName>,
7522 },
7523 FutureMaterializedViewsInSchema {
7525 schemas: Vec<ObjectName>,
7527 },
7528 FutureSequencesInSchema {
7530 schemas: Vec<ObjectName>,
7532 },
7533 Databases(Vec<ObjectName>),
7535 Schemas(Vec<ObjectName>),
7537 Sequences(Vec<ObjectName>),
7539 Tables(Vec<ObjectName>),
7541 Views(Vec<ObjectName>),
7543 Warehouses(Vec<ObjectName>),
7545 Integrations(Vec<ObjectName>),
7547 ResourceMonitors(Vec<ObjectName>),
7549 Users(Vec<ObjectName>),
7551 ComputePools(Vec<ObjectName>),
7553 Connections(Vec<ObjectName>),
7555 FailoverGroup(Vec<ObjectName>),
7557 ReplicationGroup(Vec<ObjectName>),
7559 ExternalVolumes(Vec<ObjectName>),
7561 Procedure {
7567 name: ObjectName,
7569 arg_types: Vec<DataType>,
7571 },
7572
7573 Function {
7579 name: ObjectName,
7581 arg_types: Vec<DataType>,
7583 },
7584}
7585
7586impl fmt::Display for GrantObjects {
7587 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7588 match self {
7589 GrantObjects::Sequences(sequences) => {
7590 write!(f, "SEQUENCE {}", display_comma_separated(sequences))
7591 }
7592 GrantObjects::Databases(databases) => {
7593 write!(f, "DATABASE {}", display_comma_separated(databases))
7594 }
7595 GrantObjects::Schemas(schemas) => {
7596 write!(f, "SCHEMA {}", display_comma_separated(schemas))
7597 }
7598 GrantObjects::Tables(tables) => {
7599 write!(f, "{}", display_comma_separated(tables))
7600 }
7601 GrantObjects::Views(views) => {
7602 write!(f, "VIEW {}", display_comma_separated(views))
7603 }
7604 GrantObjects::Warehouses(warehouses) => {
7605 write!(f, "WAREHOUSE {}", display_comma_separated(warehouses))
7606 }
7607 GrantObjects::Integrations(integrations) => {
7608 write!(f, "INTEGRATION {}", display_comma_separated(integrations))
7609 }
7610 GrantObjects::AllSequencesInSchema { schemas } => {
7611 write!(
7612 f,
7613 "ALL SEQUENCES IN SCHEMA {}",
7614 display_comma_separated(schemas)
7615 )
7616 }
7617 GrantObjects::AllTablesInSchema { schemas } => {
7618 write!(
7619 f,
7620 "ALL TABLES IN SCHEMA {}",
7621 display_comma_separated(schemas)
7622 )
7623 }
7624 GrantObjects::AllExternalTablesInSchema { schemas } => {
7625 write!(
7626 f,
7627 "ALL EXTERNAL TABLES IN SCHEMA {}",
7628 display_comma_separated(schemas)
7629 )
7630 }
7631 GrantObjects::AllViewsInSchema { schemas } => {
7632 write!(
7633 f,
7634 "ALL VIEWS IN SCHEMA {}",
7635 display_comma_separated(schemas)
7636 )
7637 }
7638 GrantObjects::AllMaterializedViewsInSchema { schemas } => {
7639 write!(
7640 f,
7641 "ALL MATERIALIZED VIEWS IN SCHEMA {}",
7642 display_comma_separated(schemas)
7643 )
7644 }
7645 GrantObjects::AllFunctionsInSchema { schemas } => {
7646 write!(
7647 f,
7648 "ALL FUNCTIONS IN SCHEMA {}",
7649 display_comma_separated(schemas)
7650 )
7651 }
7652 GrantObjects::FutureSchemasInDatabase { databases } => {
7653 write!(
7654 f,
7655 "FUTURE SCHEMAS IN DATABASE {}",
7656 display_comma_separated(databases)
7657 )
7658 }
7659 GrantObjects::FutureTablesInSchema { schemas } => {
7660 write!(
7661 f,
7662 "FUTURE TABLES IN SCHEMA {}",
7663 display_comma_separated(schemas)
7664 )
7665 }
7666 GrantObjects::FutureExternalTablesInSchema { schemas } => {
7667 write!(
7668 f,
7669 "FUTURE EXTERNAL TABLES IN SCHEMA {}",
7670 display_comma_separated(schemas)
7671 )
7672 }
7673 GrantObjects::FutureViewsInSchema { schemas } => {
7674 write!(
7675 f,
7676 "FUTURE VIEWS IN SCHEMA {}",
7677 display_comma_separated(schemas)
7678 )
7679 }
7680 GrantObjects::FutureMaterializedViewsInSchema { schemas } => {
7681 write!(
7682 f,
7683 "FUTURE MATERIALIZED VIEWS IN SCHEMA {}",
7684 display_comma_separated(schemas)
7685 )
7686 }
7687 GrantObjects::FutureSequencesInSchema { schemas } => {
7688 write!(
7689 f,
7690 "FUTURE SEQUENCES IN SCHEMA {}",
7691 display_comma_separated(schemas)
7692 )
7693 }
7694 GrantObjects::ResourceMonitors(objects) => {
7695 write!(f, "RESOURCE MONITOR {}", display_comma_separated(objects))
7696 }
7697 GrantObjects::Users(objects) => {
7698 write!(f, "USER {}", display_comma_separated(objects))
7699 }
7700 GrantObjects::ComputePools(objects) => {
7701 write!(f, "COMPUTE POOL {}", display_comma_separated(objects))
7702 }
7703 GrantObjects::Connections(objects) => {
7704 write!(f, "CONNECTION {}", display_comma_separated(objects))
7705 }
7706 GrantObjects::FailoverGroup(objects) => {
7707 write!(f, "FAILOVER GROUP {}", display_comma_separated(objects))
7708 }
7709 GrantObjects::ReplicationGroup(objects) => {
7710 write!(f, "REPLICATION GROUP {}", display_comma_separated(objects))
7711 }
7712 GrantObjects::ExternalVolumes(objects) => {
7713 write!(f, "EXTERNAL VOLUME {}", display_comma_separated(objects))
7714 }
7715 GrantObjects::Procedure { name, arg_types } => {
7716 write!(f, "PROCEDURE {name}")?;
7717 if !arg_types.is_empty() {
7718 write!(f, "({})", display_comma_separated(arg_types))?;
7719 }
7720 Ok(())
7721 }
7722 GrantObjects::Function { name, arg_types } => {
7723 write!(f, "FUNCTION {name}")?;
7724 if !arg_types.is_empty() {
7725 write!(f, "({})", display_comma_separated(arg_types))?;
7726 }
7727 Ok(())
7728 }
7729 }
7730 }
7731}
7732
7733#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7737#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7738#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7739pub struct DenyStatement {
7740 pub privileges: Privileges,
7742 pub objects: GrantObjects,
7744 pub grantees: Vec<Grantee>,
7746 pub granted_by: Option<Ident>,
7748 pub cascade: Option<CascadeOption>,
7750}
7751
7752impl fmt::Display for DenyStatement {
7753 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7754 write!(f, "DENY {}", self.privileges)?;
7755 write!(f, " ON {}", self.objects)?;
7756 if !self.grantees.is_empty() {
7757 write!(f, " TO {}", display_comma_separated(&self.grantees))?;
7758 }
7759 if let Some(cascade) = &self.cascade {
7760 write!(f, " {cascade}")?;
7761 }
7762 if let Some(granted_by) = &self.granted_by {
7763 write!(f, " AS {granted_by}")?;
7764 }
7765 Ok(())
7766 }
7767}
7768
7769#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7771#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7772#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7773pub struct Assignment {
7774 pub target: AssignmentTarget,
7776 pub value: Expr,
7778}
7779
7780impl fmt::Display for Assignment {
7781 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7782 write!(f, "{} = {}", self.target, self.value)
7783 }
7784}
7785
7786#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7790#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7791#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7792pub enum AssignmentTarget {
7793 ColumnName(ObjectName),
7795 Tuple(Vec<ObjectName>),
7797}
7798
7799impl fmt::Display for AssignmentTarget {
7800 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7801 match self {
7802 AssignmentTarget::ColumnName(column) => write!(f, "{column}"),
7803 AssignmentTarget::Tuple(columns) => write!(f, "({})", display_comma_separated(columns)),
7804 }
7805 }
7806}
7807
7808#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7809#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7810#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7811pub enum FunctionArgExpr {
7813 Expr(Expr),
7815 QualifiedWildcard(ObjectName),
7817 Wildcard,
7819 WildcardWithOptions(WildcardAdditionalOptions),
7823}
7824
7825impl From<Expr> for FunctionArgExpr {
7826 fn from(wildcard_expr: Expr) -> Self {
7827 match wildcard_expr {
7828 Expr::QualifiedWildcard(prefix, _) => Self::QualifiedWildcard(prefix),
7829 Expr::Wildcard(_) => Self::Wildcard,
7830 expr => Self::Expr(expr),
7831 }
7832 }
7833}
7834
7835impl fmt::Display for FunctionArgExpr {
7836 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7837 match self {
7838 FunctionArgExpr::Expr(expr) => write!(f, "{expr}"),
7839 FunctionArgExpr::QualifiedWildcard(prefix) => write!(f, "{prefix}.*"),
7840 FunctionArgExpr::Wildcard => f.write_str("*"),
7841 FunctionArgExpr::WildcardWithOptions(opts) => write!(f, "*{opts}"),
7842 }
7843 }
7844}
7845
7846#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7847#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7848#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7849pub enum FunctionArgOperator {
7851 Equals,
7853 RightArrow,
7855 Assignment,
7857 Colon,
7859 Value,
7861}
7862
7863impl fmt::Display for FunctionArgOperator {
7864 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7865 match self {
7866 FunctionArgOperator::Equals => f.write_str("="),
7867 FunctionArgOperator::RightArrow => f.write_str("=>"),
7868 FunctionArgOperator::Assignment => f.write_str(":="),
7869 FunctionArgOperator::Colon => f.write_str(":"),
7870 FunctionArgOperator::Value => f.write_str("VALUE"),
7871 }
7872 }
7873}
7874
7875#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7876#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7877#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7878pub enum FunctionArg {
7880 Named {
7884 name: Ident,
7886 arg: FunctionArgExpr,
7888 operator: FunctionArgOperator,
7890 },
7891 ExprNamed {
7895 name: Expr,
7897 arg: FunctionArgExpr,
7899 operator: FunctionArgOperator,
7901 },
7902 Unnamed(FunctionArgExpr),
7904}
7905
7906impl fmt::Display for FunctionArg {
7907 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7908 match self {
7909 FunctionArg::Named {
7910 name,
7911 arg,
7912 operator,
7913 } => write!(f, "{name} {operator} {arg}"),
7914 FunctionArg::ExprNamed {
7915 name,
7916 arg,
7917 operator,
7918 } => write!(f, "{name} {operator} {arg}"),
7919 FunctionArg::Unnamed(unnamed_arg) => write!(f, "{unnamed_arg}"),
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 CloseCursor {
7929 All,
7931 Specific {
7933 name: Ident,
7935 },
7936}
7937
7938impl fmt::Display for CloseCursor {
7939 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7940 match self {
7941 CloseCursor::All => write!(f, "ALL"),
7942 CloseCursor::Specific { name } => write!(f, "{name}"),
7943 }
7944 }
7945}
7946
7947#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7949#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7950#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7951pub struct DropDomain {
7952 pub if_exists: bool,
7954 pub name: ObjectName,
7956 pub drop_behavior: Option<DropBehavior>,
7958}
7959
7960#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7964#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7965#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7966pub struct TypedString {
7967 pub data_type: DataType,
7969 pub value: ValueWithSpan,
7972 pub uses_odbc_syntax: bool,
7983}
7984
7985impl fmt::Display for TypedString {
7986 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7987 let data_type = &self.data_type;
7988 let value = &self.value;
7989 match self.uses_odbc_syntax {
7990 false => {
7991 write!(f, "{data_type}")?;
7992 write!(f, " {value}")
7993 }
7994 true => {
7995 let prefix = match data_type {
7996 DataType::Date => "d",
7997 DataType::Time(..) => "t",
7998 DataType::Timestamp(..) => "ts",
7999 _ => "?",
8000 };
8001 write!(f, "{{{prefix} {value}}}")
8002 }
8003 }
8004 }
8005}
8006
8007#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8009#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8010#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8011pub struct Function {
8012 pub name: ObjectName,
8014 pub uses_odbc_syntax: bool,
8023 pub parameters: FunctionArguments,
8033 pub args: FunctionArguments,
8036 pub filter: Option<Box<Expr>>,
8038 pub null_treatment: Option<NullTreatment>,
8047 pub over: Option<WindowType>,
8049 pub within_group: Vec<OrderByExpr>,
8057}
8058
8059impl fmt::Display for Function {
8060 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8061 if self.uses_odbc_syntax {
8062 write!(f, "{{fn ")?;
8063 }
8064
8065 write!(f, "{}{}{}", self.name, self.parameters, self.args)?;
8066
8067 if !self.within_group.is_empty() {
8068 write!(
8069 f,
8070 " WITHIN GROUP (ORDER BY {})",
8071 display_comma_separated(&self.within_group)
8072 )?;
8073 }
8074
8075 if let Some(filter_cond) = &self.filter {
8076 write!(f, " FILTER (WHERE {filter_cond})")?;
8077 }
8078
8079 if let Some(null_treatment) = &self.null_treatment {
8080 write!(f, " {null_treatment}")?;
8081 }
8082
8083 if let Some(o) = &self.over {
8084 f.write_str(" OVER ")?;
8085 o.fmt(f)?;
8086 }
8087
8088 if self.uses_odbc_syntax {
8089 write!(f, "}}")?;
8090 }
8091
8092 Ok(())
8093 }
8094}
8095
8096#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8098#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8099#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8100pub enum FunctionArguments {
8101 None,
8104 Subquery(Box<Query>),
8107 List(FunctionArgumentList),
8110}
8111
8112impl fmt::Display for FunctionArguments {
8113 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8114 match self {
8115 FunctionArguments::None => Ok(()),
8116 FunctionArguments::Subquery(query) => write!(f, "({query})"),
8117 FunctionArguments::List(args) => write!(f, "({args})"),
8118 }
8119 }
8120}
8121
8122#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8124#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8125#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8126pub struct FunctionArgumentList {
8127 pub duplicate_treatment: Option<DuplicateTreatment>,
8129 pub args: Vec<FunctionArg>,
8131 pub clauses: Vec<FunctionArgumentClause>,
8133}
8134
8135impl fmt::Display for FunctionArgumentList {
8136 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8137 if let Some(duplicate_treatment) = self.duplicate_treatment {
8138 write!(f, "{duplicate_treatment} ")?;
8139 }
8140 write!(f, "{}", display_comma_separated(&self.args))?;
8141 if !self.clauses.is_empty() {
8142 if !self.args.is_empty() {
8143 write!(f, " ")?;
8144 }
8145 write!(f, "{}", display_separated(&self.clauses, " "))?;
8146 }
8147 Ok(())
8148 }
8149}
8150
8151#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8152#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8153#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8154pub enum FunctionArgumentClause {
8156 IgnoreOrRespectNulls(NullTreatment),
8165 OrderBy(Vec<OrderByExpr>),
8169 Limit(Expr),
8171 OnOverflow(ListAggOnOverflow),
8175 Having(HavingBound),
8184 Separator(ValueWithSpan),
8188 JsonNullClause(JsonNullClause),
8194 JsonReturningClause(JsonReturningClause),
8198}
8199
8200impl fmt::Display for FunctionArgumentClause {
8201 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8202 match self {
8203 FunctionArgumentClause::IgnoreOrRespectNulls(null_treatment) => {
8204 write!(f, "{null_treatment}")
8205 }
8206 FunctionArgumentClause::OrderBy(order_by) => {
8207 write!(f, "ORDER BY {}", display_comma_separated(order_by))
8208 }
8209 FunctionArgumentClause::Limit(limit) => write!(f, "LIMIT {limit}"),
8210 FunctionArgumentClause::OnOverflow(on_overflow) => write!(f, "{on_overflow}"),
8211 FunctionArgumentClause::Having(bound) => write!(f, "{bound}"),
8212 FunctionArgumentClause::Separator(sep) => write!(f, "SEPARATOR {sep}"),
8213 FunctionArgumentClause::JsonNullClause(null_clause) => write!(f, "{null_clause}"),
8214 FunctionArgumentClause::JsonReturningClause(returning_clause) => {
8215 write!(f, "{returning_clause}")
8216 }
8217 }
8218 }
8219}
8220
8221#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8223#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8224#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8225pub struct Method {
8226 pub expr: Box<Expr>,
8228 pub method_chain: Vec<Function>,
8231}
8232
8233impl fmt::Display for Method {
8234 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8235 write!(
8236 f,
8237 "{}.{}",
8238 self.expr,
8239 display_separated(&self.method_chain, ".")
8240 )
8241 }
8242}
8243
8244#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8245#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8246#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8247pub enum DuplicateTreatment {
8249 Distinct,
8251 All,
8253}
8254
8255impl fmt::Display for DuplicateTreatment {
8256 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8257 match self {
8258 DuplicateTreatment::Distinct => write!(f, "DISTINCT"),
8259 DuplicateTreatment::All => write!(f, "ALL"),
8260 }
8261 }
8262}
8263
8264#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8265#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8266#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8267pub enum AnalyzeFormatKind {
8269 Keyword(AnalyzeFormat),
8271 Assignment(AnalyzeFormat),
8273}
8274
8275impl fmt::Display for AnalyzeFormatKind {
8276 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8277 match self {
8278 AnalyzeFormatKind::Keyword(format) => write!(f, "FORMAT {format}"),
8279 AnalyzeFormatKind::Assignment(format) => write!(f, "FORMAT={format}"),
8280 }
8281 }
8282}
8283
8284#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8285#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8286#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8287pub enum AnalyzeFormat {
8289 TEXT,
8291 GRAPHVIZ,
8293 JSON,
8295 TRADITIONAL,
8297 TREE,
8299}
8300
8301impl fmt::Display for AnalyzeFormat {
8302 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8303 f.write_str(match self {
8304 AnalyzeFormat::TEXT => "TEXT",
8305 AnalyzeFormat::GRAPHVIZ => "GRAPHVIZ",
8306 AnalyzeFormat::JSON => "JSON",
8307 AnalyzeFormat::TRADITIONAL => "TRADITIONAL",
8308 AnalyzeFormat::TREE => "TREE",
8309 })
8310 }
8311}
8312
8313#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8315#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8316#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8317pub enum FileFormat {
8318 TEXTFILE,
8320 SEQUENCEFILE,
8322 ORC,
8324 PARQUET,
8326 AVRO,
8328 RCFILE,
8330 JSONFILE,
8332}
8333
8334impl fmt::Display for FileFormat {
8335 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8336 use self::FileFormat::*;
8337 f.write_str(match self {
8338 TEXTFILE => "TEXTFILE",
8339 SEQUENCEFILE => "SEQUENCEFILE",
8340 ORC => "ORC",
8341 PARQUET => "PARQUET",
8342 AVRO => "AVRO",
8343 RCFILE => "RCFILE",
8344 JSONFILE => "JSONFILE",
8345 })
8346 }
8347}
8348
8349#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8351#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8352#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8353pub enum ListAggOnOverflow {
8354 Error,
8356
8357 Truncate {
8359 filler: Option<Box<Expr>>,
8361 with_count: bool,
8363 },
8364}
8365
8366impl fmt::Display for ListAggOnOverflow {
8367 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8368 write!(f, "ON OVERFLOW")?;
8369 match self {
8370 ListAggOnOverflow::Error => write!(f, " ERROR"),
8371 ListAggOnOverflow::Truncate { filler, with_count } => {
8372 write!(f, " TRUNCATE")?;
8373 if let Some(filler) = filler {
8374 write!(f, " {filler}")?;
8375 }
8376 if *with_count {
8377 write!(f, " WITH")?;
8378 } else {
8379 write!(f, " WITHOUT")?;
8380 }
8381 write!(f, " COUNT")
8382 }
8383 }
8384 }
8385}
8386
8387#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8389#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8390#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8391pub struct HavingBound(pub HavingBoundKind, pub Expr);
8392
8393impl fmt::Display for HavingBound {
8394 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8395 write!(f, "HAVING {} {}", self.0, self.1)
8396 }
8397}
8398
8399#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8400#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8401#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8402pub enum HavingBoundKind {
8404 Min,
8406 Max,
8408}
8409
8410impl fmt::Display for HavingBoundKind {
8411 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8412 match self {
8413 HavingBoundKind::Min => write!(f, "MIN"),
8414 HavingBoundKind::Max => write!(f, "MAX"),
8415 }
8416 }
8417}
8418
8419#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8420#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8421#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8422pub enum ObjectType {
8424 Collation,
8426 Table,
8428 View,
8430 MaterializedView,
8432 Index,
8434 Schema,
8436 Database,
8438 Role,
8440 Sequence,
8442 Stage,
8444 Type,
8446 User,
8448 Stream,
8450}
8451
8452impl fmt::Display for ObjectType {
8453 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8454 f.write_str(match self {
8455 ObjectType::Collation => "COLLATION",
8456 ObjectType::Table => "TABLE",
8457 ObjectType::View => "VIEW",
8458 ObjectType::MaterializedView => "MATERIALIZED VIEW",
8459 ObjectType::Index => "INDEX",
8460 ObjectType::Schema => "SCHEMA",
8461 ObjectType::Database => "DATABASE",
8462 ObjectType::Role => "ROLE",
8463 ObjectType::Sequence => "SEQUENCE",
8464 ObjectType::Stage => "STAGE",
8465 ObjectType::Type => "TYPE",
8466 ObjectType::User => "USER",
8467 ObjectType::Stream => "STREAM",
8468 })
8469 }
8470}
8471
8472#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8473#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8474#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8475pub enum KillType {
8477 Connection,
8479 Query,
8481 Mutation,
8483}
8484
8485impl fmt::Display for KillType {
8486 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8487 f.write_str(match self {
8488 KillType::Connection => "CONNECTION",
8490 KillType::Query => "QUERY",
8491 KillType::Mutation => "MUTATION",
8493 })
8494 }
8495}
8496
8497#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8498#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8499#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8500pub enum HiveDistributionStyle {
8502 PARTITIONED {
8504 columns: Vec<ColumnDef>,
8506 },
8507 SKEWED {
8509 columns: Vec<ColumnDef>,
8511 on: Vec<ColumnDef>,
8513 stored_as_directories: bool,
8515 },
8516 NONE,
8518}
8519
8520#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8521#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8522#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8523pub enum HiveRowFormat {
8525 SERDE {
8527 class: String,
8529 },
8530 DELIMITED {
8532 delimiters: Vec<HiveRowDelimiter>,
8534 },
8535}
8536
8537#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8538#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8539#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8540pub struct HiveLoadDataFormat {
8542 pub serde: Expr,
8544 pub input_format: Expr,
8546}
8547
8548#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8549#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8550#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8551pub struct HiveRowDelimiter {
8553 pub delimiter: HiveDelimiter,
8555 pub char: Ident,
8557}
8558
8559impl fmt::Display for HiveRowDelimiter {
8560 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8561 write!(f, "{} ", self.delimiter)?;
8562 write!(f, "{}", self.char)
8563 }
8564}
8565
8566#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8567#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8568#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8569pub enum HiveDelimiter {
8571 FieldsTerminatedBy,
8573 FieldsEscapedBy,
8575 CollectionItemsTerminatedBy,
8577 MapKeysTerminatedBy,
8579 LinesTerminatedBy,
8581 NullDefinedAs,
8583}
8584
8585impl fmt::Display for HiveDelimiter {
8586 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8587 use HiveDelimiter::*;
8588 f.write_str(match self {
8589 FieldsTerminatedBy => "FIELDS TERMINATED BY",
8590 FieldsEscapedBy => "ESCAPED BY",
8591 CollectionItemsTerminatedBy => "COLLECTION ITEMS TERMINATED BY",
8592 MapKeysTerminatedBy => "MAP KEYS TERMINATED BY",
8593 LinesTerminatedBy => "LINES TERMINATED BY",
8594 NullDefinedAs => "NULL DEFINED AS",
8595 })
8596 }
8597}
8598
8599#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8600#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8601#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8602pub enum HiveDescribeFormat {
8604 Extended,
8606 Formatted,
8608}
8609
8610impl fmt::Display for HiveDescribeFormat {
8611 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8612 use HiveDescribeFormat::*;
8613 f.write_str(match self {
8614 Extended => "EXTENDED",
8615 Formatted => "FORMATTED",
8616 })
8617 }
8618}
8619
8620#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8621#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8622#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8623pub enum DescribeAlias {
8625 Describe,
8627 Explain,
8629 Desc,
8631}
8632
8633impl fmt::Display for DescribeAlias {
8634 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8635 use DescribeAlias::*;
8636 f.write_str(match self {
8637 Describe => "DESCRIBE",
8638 Explain => "EXPLAIN",
8639 Desc => "DESC",
8640 })
8641 }
8642}
8643
8644#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8645#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8646#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8647#[allow(clippy::large_enum_variant)]
8648pub enum HiveIOFormat {
8650 IOF {
8652 input_format: Expr,
8654 output_format: Expr,
8656 },
8657 FileFormat {
8659 format: FileFormat,
8661 },
8662}
8663
8664#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
8665#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8666#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8667pub struct HiveFormat {
8669 pub row_format: Option<HiveRowFormat>,
8671 pub serde_properties: Option<Vec<SqlOption>>,
8673 pub storage: Option<HiveIOFormat>,
8675 pub location: Option<String>,
8677}
8678
8679#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8680#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8681#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8682pub struct ClusteredIndex {
8684 pub name: Ident,
8686 pub asc: Option<bool>,
8688}
8689
8690impl fmt::Display for ClusteredIndex {
8691 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8692 write!(f, "{}", self.name)?;
8693 match self.asc {
8694 Some(true) => write!(f, " ASC"),
8695 Some(false) => write!(f, " DESC"),
8696 _ => Ok(()),
8697 }
8698 }
8699}
8700
8701#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8702#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8703#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8704pub enum TableOptionsClustered {
8706 ColumnstoreIndex,
8708 ColumnstoreIndexOrder(Vec<Ident>),
8710 Index(Vec<ClusteredIndex>),
8712}
8713
8714impl fmt::Display for TableOptionsClustered {
8715 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8716 match self {
8717 TableOptionsClustered::ColumnstoreIndex => {
8718 write!(f, "CLUSTERED COLUMNSTORE INDEX")
8719 }
8720 TableOptionsClustered::ColumnstoreIndexOrder(values) => {
8721 write!(
8722 f,
8723 "CLUSTERED COLUMNSTORE INDEX ORDER ({})",
8724 display_comma_separated(values)
8725 )
8726 }
8727 TableOptionsClustered::Index(values) => {
8728 write!(f, "CLUSTERED INDEX ({})", display_comma_separated(values))
8729 }
8730 }
8731 }
8732}
8733
8734#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
8736#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8737#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8738pub enum PartitionRangeDirection {
8739 Left,
8741 Right,
8743}
8744
8745#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8746#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8747#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8748pub enum SqlOption {
8750 Clustered(TableOptionsClustered),
8754 Ident(Ident),
8758 KeyValue {
8762 key: Ident,
8764 value: Expr,
8766 },
8767 Partition {
8774 column_name: Ident,
8776 range_direction: Option<PartitionRangeDirection>,
8778 for_values: Vec<Expr>,
8780 },
8781 Comment(CommentDef),
8783 TableSpace(TablespaceOption),
8786 NamedParenthesizedList(NamedParenthesizedList),
8793}
8794
8795impl fmt::Display for SqlOption {
8796 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8797 match self {
8798 SqlOption::Clustered(c) => write!(f, "{c}"),
8799 SqlOption::Ident(ident) => {
8800 write!(f, "{ident}")
8801 }
8802 SqlOption::KeyValue { key: name, value } => {
8803 write!(f, "{name} = {value}")
8804 }
8805 SqlOption::Partition {
8806 column_name,
8807 range_direction,
8808 for_values,
8809 } => {
8810 let direction = match range_direction {
8811 Some(PartitionRangeDirection::Left) => " LEFT",
8812 Some(PartitionRangeDirection::Right) => " RIGHT",
8813 None => "",
8814 };
8815
8816 write!(
8817 f,
8818 "PARTITION ({} RANGE{} FOR VALUES ({}))",
8819 column_name,
8820 direction,
8821 display_comma_separated(for_values)
8822 )
8823 }
8824 SqlOption::TableSpace(tablespace_option) => {
8825 write!(f, "TABLESPACE {}", tablespace_option.name)?;
8826 match tablespace_option.storage {
8827 Some(StorageType::Disk) => write!(f, " STORAGE DISK"),
8828 Some(StorageType::Memory) => write!(f, " STORAGE MEMORY"),
8829 None => Ok(()),
8830 }
8831 }
8832 SqlOption::Comment(comment) => match comment {
8833 CommentDef::WithEq(comment) => {
8834 write!(f, "COMMENT = '{comment}'")
8835 }
8836 CommentDef::WithoutEq(comment) => {
8837 write!(f, "COMMENT '{comment}'")
8838 }
8839 },
8840 SqlOption::NamedParenthesizedList(value) => {
8841 write!(f, "{} = ", value.key)?;
8842 if let Some(key) = &value.name {
8843 write!(f, "{key}")?;
8844 }
8845 if !value.values.is_empty() {
8846 write!(f, "({})", display_comma_separated(&value.values))?
8847 }
8848 Ok(())
8849 }
8850 }
8851 }
8852}
8853
8854#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
8855#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8856#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8857pub enum StorageType {
8859 Disk,
8861 Memory,
8863}
8864
8865#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
8866#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8867#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8868pub struct TablespaceOption {
8871 pub name: String,
8873 pub storage: Option<StorageType>,
8875}
8876
8877#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8878#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8879#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8880pub struct SecretOption {
8882 pub key: Ident,
8884 pub value: Ident,
8886}
8887
8888impl fmt::Display for SecretOption {
8889 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8890 write!(f, "{} {}", self.key, self.value)
8891 }
8892}
8893
8894#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8898#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8899#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8900pub struct CreateServerStatement {
8901 pub name: ObjectName,
8903 pub if_not_exists: bool,
8905 pub server_type: Option<Ident>,
8907 pub version: Option<Ident>,
8909 pub foreign_data_wrapper: ObjectName,
8911 pub options: Option<Vec<CreateServerOption>>,
8913}
8914
8915impl fmt::Display for CreateServerStatement {
8916 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8917 let CreateServerStatement {
8918 name,
8919 if_not_exists,
8920 server_type,
8921 version,
8922 foreign_data_wrapper,
8923 options,
8924 } = self;
8925
8926 write!(
8927 f,
8928 "CREATE SERVER {if_not_exists}{name} ",
8929 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
8930 )?;
8931
8932 if let Some(st) = server_type {
8933 write!(f, "TYPE {st} ")?;
8934 }
8935
8936 if let Some(v) = version {
8937 write!(f, "VERSION {v} ")?;
8938 }
8939
8940 write!(f, "FOREIGN DATA WRAPPER {foreign_data_wrapper}")?;
8941
8942 if let Some(o) = options {
8943 write!(f, " OPTIONS ({o})", o = display_comma_separated(o))?;
8944 }
8945
8946 Ok(())
8947 }
8948}
8949
8950#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8952#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8953#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8954pub struct CreateServerOption {
8955 pub key: Ident,
8957 pub value: Ident,
8959}
8960
8961impl fmt::Display for CreateServerOption {
8962 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8963 write!(f, "{} {}", self.key, self.value)
8964 }
8965}
8966
8967#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8968#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8969#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8970pub enum AttachDuckDBDatabaseOption {
8972 ReadOnly(Option<bool>),
8974 Type(Ident),
8976}
8977
8978impl fmt::Display for AttachDuckDBDatabaseOption {
8979 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8980 match self {
8981 AttachDuckDBDatabaseOption::ReadOnly(Some(true)) => write!(f, "READ_ONLY true"),
8982 AttachDuckDBDatabaseOption::ReadOnly(Some(false)) => write!(f, "READ_ONLY false"),
8983 AttachDuckDBDatabaseOption::ReadOnly(None) => write!(f, "READ_ONLY"),
8984 AttachDuckDBDatabaseOption::Type(t) => write!(f, "TYPE {t}"),
8985 }
8986 }
8987}
8988
8989#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8990#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8991#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8992pub enum TransactionMode {
8994 AccessMode(TransactionAccessMode),
8996 IsolationLevel(TransactionIsolationLevel),
8998}
8999
9000impl fmt::Display for TransactionMode {
9001 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9002 use TransactionMode::*;
9003 match self {
9004 AccessMode(access_mode) => write!(f, "{access_mode}"),
9005 IsolationLevel(iso_level) => write!(f, "ISOLATION LEVEL {iso_level}"),
9006 }
9007 }
9008}
9009
9010#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9011#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9012#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9013pub enum TransactionAccessMode {
9015 ReadOnly,
9017 ReadWrite,
9019}
9020
9021impl fmt::Display for TransactionAccessMode {
9022 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9023 use TransactionAccessMode::*;
9024 f.write_str(match self {
9025 ReadOnly => "READ ONLY",
9026 ReadWrite => "READ WRITE",
9027 })
9028 }
9029}
9030
9031#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9032#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9033#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9034pub enum TransactionIsolationLevel {
9036 ReadUncommitted,
9038 ReadCommitted,
9040 RepeatableRead,
9042 Serializable,
9044 Snapshot,
9046}
9047
9048impl fmt::Display for TransactionIsolationLevel {
9049 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9050 use TransactionIsolationLevel::*;
9051 f.write_str(match self {
9052 ReadUncommitted => "READ UNCOMMITTED",
9053 ReadCommitted => "READ COMMITTED",
9054 RepeatableRead => "REPEATABLE READ",
9055 Serializable => "SERIALIZABLE",
9056 Snapshot => "SNAPSHOT",
9057 })
9058 }
9059}
9060
9061#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9066#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9067#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9068pub enum TransactionModifier {
9069 Deferred,
9071 Immediate,
9073 Exclusive,
9075 Try,
9077 Catch,
9079}
9080
9081impl fmt::Display for TransactionModifier {
9082 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9083 use TransactionModifier::*;
9084 f.write_str(match self {
9085 Deferred => "DEFERRED",
9086 Immediate => "IMMEDIATE",
9087 Exclusive => "EXCLUSIVE",
9088 Try => "TRY",
9089 Catch => "CATCH",
9090 })
9091 }
9092}
9093
9094#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9095#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9096#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9097pub enum ShowStatementFilter {
9099 Like(String),
9101 ILike(String),
9103 Where(Expr),
9105 NoKeyword(String),
9107}
9108
9109impl fmt::Display for ShowStatementFilter {
9110 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9111 use ShowStatementFilter::*;
9112 match self {
9113 Like(pattern) => write!(f, "LIKE '{}'", value::escape_single_quote_string(pattern)),
9114 ILike(pattern) => write!(f, "ILIKE {}", value::escape_single_quote_string(pattern)),
9115 Where(expr) => write!(f, "WHERE {expr}"),
9116 NoKeyword(pattern) => write!(f, "'{}'", value::escape_single_quote_string(pattern)),
9117 }
9118 }
9119}
9120
9121#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9122#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9123#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9124pub enum ShowStatementInClause {
9126 IN,
9128 FROM,
9130}
9131
9132impl fmt::Display for ShowStatementInClause {
9133 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9134 use ShowStatementInClause::*;
9135 match self {
9136 FROM => write!(f, "FROM"),
9137 IN => write!(f, "IN"),
9138 }
9139 }
9140}
9141
9142#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9147#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9148#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9149pub enum SqliteOnConflict {
9150 Rollback,
9152 Abort,
9154 Fail,
9156 Ignore,
9158 Replace,
9160}
9161
9162impl fmt::Display for SqliteOnConflict {
9163 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9164 use SqliteOnConflict::*;
9165 match self {
9166 Rollback => write!(f, "OR ROLLBACK"),
9167 Abort => write!(f, "OR ABORT"),
9168 Fail => write!(f, "OR FAIL"),
9169 Ignore => write!(f, "OR IGNORE"),
9170 Replace => write!(f, "OR REPLACE"),
9171 }
9172 }
9173}
9174
9175#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9181#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9182#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9183pub enum MysqlInsertPriority {
9184 LowPriority,
9186 Delayed,
9188 HighPriority,
9190}
9191
9192impl fmt::Display for crate::ast::MysqlInsertPriority {
9193 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9194 use MysqlInsertPriority::*;
9195 match self {
9196 LowPriority => write!(f, "LOW_PRIORITY"),
9197 Delayed => write!(f, "DELAYED"),
9198 HighPriority => write!(f, "HIGH_PRIORITY"),
9199 }
9200 }
9201}
9202
9203#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9204#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9205#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9206pub enum CopySource {
9208 Table {
9210 table_name: ObjectName,
9212 columns: Vec<Ident>,
9215 },
9216 Query(Box<Query>),
9218}
9219
9220#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9221#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9222#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9223pub enum CopyTarget {
9225 Stdin,
9227 Stdout,
9229 File {
9231 filename: String,
9233 },
9234 Program {
9236 command: String,
9238 },
9239}
9240
9241impl fmt::Display for CopyTarget {
9242 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9243 use CopyTarget::*;
9244 match self {
9245 Stdin => write!(f, "STDIN"),
9246 Stdout => write!(f, "STDOUT"),
9247 File { filename } => write!(f, "'{}'", value::escape_single_quote_string(filename)),
9248 Program { command } => write!(
9249 f,
9250 "PROGRAM '{}'",
9251 value::escape_single_quote_string(command)
9252 ),
9253 }
9254 }
9255}
9256
9257#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9258#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9259#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9260pub enum OnCommit {
9262 DeleteRows,
9264 PreserveRows,
9266 Drop,
9268}
9269
9270#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9274#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9275#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9276pub enum CopyOption {
9277 Format(Ident),
9279 Freeze(bool),
9281 Delimiter(char),
9283 Null(String),
9285 Header(bool),
9287 Quote(char),
9289 Escape(char),
9291 ForceQuote(Vec<Ident>),
9293 ForceNotNull(Vec<Ident>),
9295 ForceNull(Vec<Ident>),
9297 Encoding(String),
9299}
9300
9301impl fmt::Display for CopyOption {
9302 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9303 use CopyOption::*;
9304 match self {
9305 Format(name) => write!(f, "FORMAT {name}"),
9306 Freeze(true) => write!(f, "FREEZE"),
9307 Freeze(false) => write!(f, "FREEZE FALSE"),
9308 Delimiter(char) => write!(f, "DELIMITER '{char}'"),
9309 Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)),
9310 Header(true) => write!(f, "HEADER"),
9311 Header(false) => write!(f, "HEADER FALSE"),
9312 Quote(char) => write!(f, "QUOTE '{char}'"),
9313 Escape(char) => write!(f, "ESCAPE '{char}'"),
9314 ForceQuote(columns) => write!(f, "FORCE_QUOTE ({})", display_comma_separated(columns)),
9315 ForceNotNull(columns) => {
9316 write!(f, "FORCE_NOT_NULL ({})", display_comma_separated(columns))
9317 }
9318 ForceNull(columns) => write!(f, "FORCE_NULL ({})", display_comma_separated(columns)),
9319 Encoding(name) => write!(f, "ENCODING '{}'", value::escape_single_quote_string(name)),
9320 }
9321 }
9322}
9323
9324#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9329#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9330#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9331pub enum CopyLegacyOption {
9332 AcceptAnyDate,
9334 AcceptInvChars(Option<String>),
9336 AddQuotes,
9338 AllowOverwrite,
9340 Binary,
9342 BlankAsNull,
9344 Bzip2,
9346 CleanPath,
9348 CompUpdate {
9350 preset: bool,
9352 enabled: Option<bool>,
9354 },
9355 Csv(Vec<CopyLegacyCsvOption>),
9357 DateFormat(Option<String>),
9359 Delimiter(char),
9361 EmptyAsNull,
9363 Encrypted {
9365 auto: bool,
9367 },
9368 Escape,
9370 Extension(String),
9372 FixedWidth(String),
9374 Gzip,
9376 Header,
9378 IamRole(IamRoleKind),
9380 IgnoreHeader(u64),
9382 Json(Option<String>),
9384 Manifest {
9386 verbose: bool,
9388 },
9389 MaxFileSize(FileSize),
9391 Null(String),
9393 Parallel(Option<bool>),
9395 Parquet,
9397 PartitionBy(UnloadPartitionBy),
9399 Region(String),
9401 RemoveQuotes,
9403 RowGroupSize(FileSize),
9405 StatUpdate(Option<bool>),
9407 TimeFormat(Option<String>),
9409 TruncateColumns,
9411 Zstd,
9413 Credentials(String),
9416}
9417
9418impl fmt::Display for CopyLegacyOption {
9419 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9420 use CopyLegacyOption::*;
9421 match self {
9422 AcceptAnyDate => write!(f, "ACCEPTANYDATE"),
9423 AcceptInvChars(ch) => {
9424 write!(f, "ACCEPTINVCHARS")?;
9425 if let Some(ch) = ch {
9426 write!(f, " '{}'", value::escape_single_quote_string(ch))?;
9427 }
9428 Ok(())
9429 }
9430 AddQuotes => write!(f, "ADDQUOTES"),
9431 AllowOverwrite => write!(f, "ALLOWOVERWRITE"),
9432 Binary => write!(f, "BINARY"),
9433 BlankAsNull => write!(f, "BLANKSASNULL"),
9434 Bzip2 => write!(f, "BZIP2"),
9435 CleanPath => write!(f, "CLEANPATH"),
9436 CompUpdate { preset, enabled } => {
9437 write!(f, "COMPUPDATE")?;
9438 if *preset {
9439 write!(f, " PRESET")?;
9440 } else if let Some(enabled) = enabled {
9441 write!(
9442 f,
9443 "{}",
9444 match enabled {
9445 true => " TRUE",
9446 false => " FALSE",
9447 }
9448 )?;
9449 }
9450 Ok(())
9451 }
9452 Csv(opts) => {
9453 write!(f, "CSV")?;
9454 if !opts.is_empty() {
9455 write!(f, " {}", display_separated(opts, " "))?;
9456 }
9457 Ok(())
9458 }
9459 DateFormat(fmt) => {
9460 write!(f, "DATEFORMAT")?;
9461 if let Some(fmt) = fmt {
9462 write!(f, " '{}'", value::escape_single_quote_string(fmt))?;
9463 }
9464 Ok(())
9465 }
9466 Delimiter(char) => write!(f, "DELIMITER '{char}'"),
9467 EmptyAsNull => write!(f, "EMPTYASNULL"),
9468 Encrypted { auto } => write!(f, "ENCRYPTED{}", if *auto { " AUTO" } else { "" }),
9469 Escape => write!(f, "ESCAPE"),
9470 Extension(ext) => write!(f, "EXTENSION '{}'", value::escape_single_quote_string(ext)),
9471 FixedWidth(spec) => write!(
9472 f,
9473 "FIXEDWIDTH '{}'",
9474 value::escape_single_quote_string(spec)
9475 ),
9476 Gzip => write!(f, "GZIP"),
9477 Header => write!(f, "HEADER"),
9478 IamRole(role) => write!(f, "IAM_ROLE {role}"),
9479 IgnoreHeader(num_rows) => write!(f, "IGNOREHEADER {num_rows}"),
9480 Json(opt) => {
9481 write!(f, "JSON")?;
9482 if let Some(opt) = opt {
9483 write!(f, " AS '{}'", value::escape_single_quote_string(opt))?;
9484 }
9485 Ok(())
9486 }
9487 Manifest { verbose } => write!(f, "MANIFEST{}", if *verbose { " VERBOSE" } else { "" }),
9488 MaxFileSize(file_size) => write!(f, "MAXFILESIZE {file_size}"),
9489 Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)),
9490 Parallel(enabled) => {
9491 write!(
9492 f,
9493 "PARALLEL{}",
9494 match enabled {
9495 Some(true) => " TRUE",
9496 Some(false) => " FALSE",
9497 _ => "",
9498 }
9499 )
9500 }
9501 Parquet => write!(f, "PARQUET"),
9502 PartitionBy(p) => write!(f, "{p}"),
9503 Region(region) => write!(f, "REGION '{}'", value::escape_single_quote_string(region)),
9504 RemoveQuotes => write!(f, "REMOVEQUOTES"),
9505 RowGroupSize(file_size) => write!(f, "ROWGROUPSIZE {file_size}"),
9506 StatUpdate(enabled) => {
9507 write!(
9508 f,
9509 "STATUPDATE{}",
9510 match enabled {
9511 Some(true) => " TRUE",
9512 Some(false) => " FALSE",
9513 _ => "",
9514 }
9515 )
9516 }
9517 TimeFormat(fmt) => {
9518 write!(f, "TIMEFORMAT")?;
9519 if let Some(fmt) = fmt {
9520 write!(f, " '{}'", value::escape_single_quote_string(fmt))?;
9521 }
9522 Ok(())
9523 }
9524 TruncateColumns => write!(f, "TRUNCATECOLUMNS"),
9525 Zstd => write!(f, "ZSTD"),
9526 Credentials(s) => write!(f, "CREDENTIALS '{}'", value::escape_single_quote_string(s)),
9527 }
9528 }
9529}
9530
9531#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9535#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9536#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9537pub struct FileSize {
9538 pub size: ValueWithSpan,
9540 pub unit: Option<FileSizeUnit>,
9542}
9543
9544impl fmt::Display for FileSize {
9545 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9546 write!(f, "{}", self.size)?;
9547 if let Some(unit) = &self.unit {
9548 write!(f, " {unit}")?;
9549 }
9550 Ok(())
9551 }
9552}
9553
9554#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9556#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9557#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9558pub enum FileSizeUnit {
9559 MB,
9561 GB,
9563}
9564
9565impl fmt::Display for FileSizeUnit {
9566 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9567 match self {
9568 FileSizeUnit::MB => write!(f, "MB"),
9569 FileSizeUnit::GB => write!(f, "GB"),
9570 }
9571 }
9572}
9573
9574#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9580#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9581#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9582pub struct UnloadPartitionBy {
9583 pub columns: Vec<Ident>,
9585 pub include: bool,
9587}
9588
9589impl fmt::Display for UnloadPartitionBy {
9590 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9591 write!(
9592 f,
9593 "PARTITION BY ({}){}",
9594 display_comma_separated(&self.columns),
9595 if self.include { " INCLUDE" } else { "" }
9596 )
9597 }
9598}
9599
9600#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9604#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9605#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9606pub enum IamRoleKind {
9607 Default,
9609 Arn(String),
9611}
9612
9613impl fmt::Display for IamRoleKind {
9614 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9615 match self {
9616 IamRoleKind::Default => write!(f, "DEFAULT"),
9617 IamRoleKind::Arn(arn) => write!(f, "'{arn}'"),
9618 }
9619 }
9620}
9621
9622#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9626#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9627#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9628pub enum CopyLegacyCsvOption {
9629 Header,
9631 Quote(char),
9633 Escape(char),
9635 ForceQuote(Vec<Ident>),
9637 ForceNotNull(Vec<Ident>),
9639}
9640
9641impl fmt::Display for CopyLegacyCsvOption {
9642 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9643 use CopyLegacyCsvOption::*;
9644 match self {
9645 Header => write!(f, "HEADER"),
9646 Quote(char) => write!(f, "QUOTE '{char}'"),
9647 Escape(char) => write!(f, "ESCAPE '{char}'"),
9648 ForceQuote(columns) => write!(f, "FORCE QUOTE {}", display_comma_separated(columns)),
9649 ForceNotNull(columns) => {
9650 write!(f, "FORCE NOT NULL {}", display_comma_separated(columns))
9651 }
9652 }
9653 }
9654}
9655
9656#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9658#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9659#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9660pub enum DiscardObject {
9661 ALL,
9663 PLANS,
9665 SEQUENCES,
9667 TEMP,
9669}
9670
9671impl fmt::Display for DiscardObject {
9672 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9673 match self {
9674 DiscardObject::ALL => f.write_str("ALL"),
9675 DiscardObject::PLANS => f.write_str("PLANS"),
9676 DiscardObject::SEQUENCES => f.write_str("SEQUENCES"),
9677 DiscardObject::TEMP => f.write_str("TEMP"),
9678 }
9679 }
9680}
9681
9682#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9684#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9685#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9686pub enum FlushType {
9687 BinaryLogs,
9689 EngineLogs,
9691 ErrorLogs,
9693 GeneralLogs,
9695 Hosts,
9697 Logs,
9699 Privileges,
9701 OptimizerCosts,
9703 RelayLogs,
9705 SlowLogs,
9707 Status,
9709 UserResources,
9711 Tables,
9713}
9714
9715impl fmt::Display for FlushType {
9716 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9717 match self {
9718 FlushType::BinaryLogs => f.write_str("BINARY LOGS"),
9719 FlushType::EngineLogs => f.write_str("ENGINE LOGS"),
9720 FlushType::ErrorLogs => f.write_str("ERROR LOGS"),
9721 FlushType::GeneralLogs => f.write_str("GENERAL LOGS"),
9722 FlushType::Hosts => f.write_str("HOSTS"),
9723 FlushType::Logs => f.write_str("LOGS"),
9724 FlushType::Privileges => f.write_str("PRIVILEGES"),
9725 FlushType::OptimizerCosts => f.write_str("OPTIMIZER_COSTS"),
9726 FlushType::RelayLogs => f.write_str("RELAY LOGS"),
9727 FlushType::SlowLogs => f.write_str("SLOW LOGS"),
9728 FlushType::Status => f.write_str("STATUS"),
9729 FlushType::UserResources => f.write_str("USER_RESOURCES"),
9730 FlushType::Tables => f.write_str("TABLES"),
9731 }
9732 }
9733}
9734
9735#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9737#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9738#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9739pub enum FlushLocation {
9740 NoWriteToBinlog,
9742 Local,
9744}
9745
9746impl fmt::Display for FlushLocation {
9747 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9748 match self {
9749 FlushLocation::NoWriteToBinlog => f.write_str("NO_WRITE_TO_BINLOG"),
9750 FlushLocation::Local => f.write_str("LOCAL"),
9751 }
9752 }
9753}
9754
9755#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9757#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9758#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9759pub enum ContextModifier {
9760 Local,
9762 Session,
9764 Global,
9766}
9767
9768impl fmt::Display for ContextModifier {
9769 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9770 match self {
9771 Self::Local => {
9772 write!(f, "LOCAL ")
9773 }
9774 Self::Session => {
9775 write!(f, "SESSION ")
9776 }
9777 Self::Global => {
9778 write!(f, "GLOBAL ")
9779 }
9780 }
9781 }
9782}
9783
9784#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9786#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9787pub enum DropFunctionOption {
9788 Restrict,
9790 Cascade,
9792}
9793
9794impl fmt::Display for DropFunctionOption {
9795 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9796 match self {
9797 DropFunctionOption::Restrict => write!(f, "RESTRICT "),
9798 DropFunctionOption::Cascade => write!(f, "CASCADE "),
9799 }
9800 }
9801}
9802
9803#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9805#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9806#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9807pub struct FunctionDesc {
9808 pub name: ObjectName,
9810 pub args: Option<Vec<OperateFunctionArg>>,
9812}
9813
9814impl fmt::Display for FunctionDesc {
9815 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9816 write!(f, "{}", self.name)?;
9817 if let Some(args) = &self.args {
9818 write!(f, "({})", display_comma_separated(args))?;
9819 }
9820 Ok(())
9821 }
9822}
9823
9824#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9826#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9827#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9828pub struct OperateFunctionArg {
9829 pub mode: Option<ArgMode>,
9831 pub name: Option<Ident>,
9833 pub data_type: DataType,
9835 pub default_expr: Option<Expr>,
9837}
9838
9839impl OperateFunctionArg {
9840 pub fn unnamed(data_type: DataType) -> Self {
9842 Self {
9843 mode: None,
9844 name: None,
9845 data_type,
9846 default_expr: None,
9847 }
9848 }
9849
9850 pub fn with_name(name: &str, data_type: DataType) -> Self {
9852 Self {
9853 mode: None,
9854 name: Some(name.into()),
9855 data_type,
9856 default_expr: None,
9857 }
9858 }
9859}
9860
9861impl fmt::Display for OperateFunctionArg {
9862 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9863 if let Some(mode) = &self.mode {
9864 write!(f, "{mode} ")?;
9865 }
9866 if let Some(name) = &self.name {
9867 write!(f, "{name} ")?;
9868 }
9869 write!(f, "{}", self.data_type)?;
9870 if let Some(default_expr) = &self.default_expr {
9871 write!(f, " = {default_expr}")?;
9872 }
9873 Ok(())
9874 }
9875}
9876
9877#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9879#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9880#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9881pub enum ArgMode {
9882 In,
9884 Out,
9886 InOut,
9888 Variadic,
9890}
9891
9892impl fmt::Display for ArgMode {
9893 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9894 match self {
9895 ArgMode::In => write!(f, "IN"),
9896 ArgMode::Out => write!(f, "OUT"),
9897 ArgMode::InOut => write!(f, "INOUT"),
9898 ArgMode::Variadic => write!(f, "VARIADIC"),
9899 }
9900 }
9901}
9902
9903#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9905#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9906#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9907pub enum FunctionBehavior {
9908 Immutable,
9910 Stable,
9912 Volatile,
9914}
9915
9916impl fmt::Display for FunctionBehavior {
9917 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9918 match self {
9919 FunctionBehavior::Immutable => write!(f, "IMMUTABLE"),
9920 FunctionBehavior::Stable => write!(f, "STABLE"),
9921 FunctionBehavior::Volatile => write!(f, "VOLATILE"),
9922 }
9923 }
9924}
9925
9926#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9930#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9931#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9932pub enum FunctionSecurity {
9933 Definer,
9935 Invoker,
9937}
9938
9939impl fmt::Display for FunctionSecurity {
9940 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9941 match self {
9942 FunctionSecurity::Definer => write!(f, "SECURITY DEFINER"),
9943 FunctionSecurity::Invoker => write!(f, "SECURITY INVOKER"),
9944 }
9945 }
9946}
9947
9948#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9952#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9953#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9954pub enum FunctionSetValue {
9955 Default,
9957 Values(Vec<Expr>),
9959 FromCurrent,
9961}
9962
9963#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9967#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9968#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9969pub struct FunctionDefinitionSetParam {
9970 pub name: ObjectName,
9972 pub value: FunctionSetValue,
9974}
9975
9976impl fmt::Display for FunctionDefinitionSetParam {
9977 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9978 write!(f, "SET {} ", self.name)?;
9979 match &self.value {
9980 FunctionSetValue::Default => write!(f, "= DEFAULT"),
9981 FunctionSetValue::Values(values) => {
9982 write!(f, "= {}", display_comma_separated(values))
9983 }
9984 FunctionSetValue::FromCurrent => write!(f, "FROM CURRENT"),
9985 }
9986 }
9987}
9988
9989#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9991#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9992#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9993pub enum FunctionCalledOnNull {
9994 CalledOnNullInput,
9996 ReturnsNullOnNullInput,
9998 Strict,
10000}
10001
10002impl fmt::Display for FunctionCalledOnNull {
10003 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10004 match self {
10005 FunctionCalledOnNull::CalledOnNullInput => write!(f, "CALLED ON NULL INPUT"),
10006 FunctionCalledOnNull::ReturnsNullOnNullInput => write!(f, "RETURNS NULL ON NULL INPUT"),
10007 FunctionCalledOnNull::Strict => write!(f, "STRICT"),
10008 }
10009 }
10010}
10011
10012#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10014#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10015#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10016pub enum FunctionParallel {
10017 Unsafe,
10019 Restricted,
10021 Safe,
10023}
10024
10025impl fmt::Display for FunctionParallel {
10026 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10027 match self {
10028 FunctionParallel::Unsafe => write!(f, "PARALLEL UNSAFE"),
10029 FunctionParallel::Restricted => write!(f, "PARALLEL RESTRICTED"),
10030 FunctionParallel::Safe => write!(f, "PARALLEL SAFE"),
10031 }
10032 }
10033}
10034
10035#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10039#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10040#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10041pub enum FunctionDeterminismSpecifier {
10042 Deterministic,
10044 NotDeterministic,
10046}
10047
10048impl fmt::Display for FunctionDeterminismSpecifier {
10049 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10050 match self {
10051 FunctionDeterminismSpecifier::Deterministic => {
10052 write!(f, "DETERMINISTIC")
10053 }
10054 FunctionDeterminismSpecifier::NotDeterministic => {
10055 write!(f, "NOT DETERMINISTIC")
10056 }
10057 }
10058 }
10059}
10060
10061#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10068#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10069#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10070pub enum CreateFunctionBody {
10071 AsBeforeOptions {
10084 body: Expr,
10086 link_symbol: Option<Expr>,
10095 },
10096 AsAfterOptions(Expr),
10108 AsBeginEnd(BeginEndStatements),
10124 Return(Expr),
10135
10136 AsReturnExpr(Expr),
10147
10148 AsReturnSelect(Select),
10159}
10160
10161#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10162#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10163#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10164pub enum CreateFunctionUsing {
10166 Jar(String),
10168 File(String),
10170 Archive(String),
10172}
10173
10174impl fmt::Display for CreateFunctionUsing {
10175 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10176 write!(f, "USING ")?;
10177 match self {
10178 CreateFunctionUsing::Jar(uri) => write!(f, "JAR '{uri}'"),
10179 CreateFunctionUsing::File(uri) => write!(f, "FILE '{uri}'"),
10180 CreateFunctionUsing::Archive(uri) => write!(f, "ARCHIVE '{uri}'"),
10181 }
10182 }
10183}
10184
10185#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10190#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10191#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10192pub struct MacroArg {
10193 pub name: Ident,
10195 pub default_expr: Option<Expr>,
10197}
10198
10199impl MacroArg {
10200 pub fn new(name: &str) -> Self {
10202 Self {
10203 name: name.into(),
10204 default_expr: None,
10205 }
10206 }
10207}
10208
10209impl fmt::Display for MacroArg {
10210 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10211 write!(f, "{}", self.name)?;
10212 if let Some(default_expr) = &self.default_expr {
10213 write!(f, " := {default_expr}")?;
10214 }
10215 Ok(())
10216 }
10217}
10218
10219#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10220#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10221#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10222pub enum MacroDefinition {
10224 Expr(Expr),
10226 Table(Box<Query>),
10228}
10229
10230impl fmt::Display for MacroDefinition {
10231 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10232 match self {
10233 MacroDefinition::Expr(expr) => write!(f, "{expr}")?,
10234 MacroDefinition::Table(query) => write!(f, "{query}")?,
10235 }
10236 Ok(())
10237 }
10238}
10239
10240#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10244#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10245#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10246pub enum SchemaName {
10247 Simple(ObjectName),
10249 UnnamedAuthorization(Ident),
10251 NamedAuthorization(ObjectName, Ident),
10253}
10254
10255impl fmt::Display for SchemaName {
10256 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10257 match self {
10258 SchemaName::Simple(name) => {
10259 write!(f, "{name}")
10260 }
10261 SchemaName::UnnamedAuthorization(authorization) => {
10262 write!(f, "AUTHORIZATION {authorization}")
10263 }
10264 SchemaName::NamedAuthorization(name, authorization) => {
10265 write!(f, "{name} AUTHORIZATION {authorization}")
10266 }
10267 }
10268 }
10269}
10270
10271#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10275#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10276#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10277pub enum SearchModifier {
10278 InNaturalLanguageMode,
10280 InNaturalLanguageModeWithQueryExpansion,
10282 InBooleanMode,
10284 WithQueryExpansion,
10286}
10287
10288impl fmt::Display for SearchModifier {
10289 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10290 match self {
10291 Self::InNaturalLanguageMode => {
10292 write!(f, "IN NATURAL LANGUAGE MODE")?;
10293 }
10294 Self::InNaturalLanguageModeWithQueryExpansion => {
10295 write!(f, "IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION")?;
10296 }
10297 Self::InBooleanMode => {
10298 write!(f, "IN BOOLEAN MODE")?;
10299 }
10300 Self::WithQueryExpansion => {
10301 write!(f, "WITH QUERY EXPANSION")?;
10302 }
10303 }
10304
10305 Ok(())
10306 }
10307}
10308
10309#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10311#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10312#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10313pub struct LockTable {
10314 pub table: Ident,
10316 pub alias: Option<Ident>,
10318 pub lock_type: LockTableType,
10320}
10321
10322impl fmt::Display for LockTable {
10323 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10324 let Self {
10325 table: tbl_name,
10326 alias,
10327 lock_type,
10328 } = self;
10329
10330 write!(f, "{tbl_name} ")?;
10331 if let Some(alias) = alias {
10332 write!(f, "AS {alias} ")?;
10333 }
10334 write!(f, "{lock_type}")?;
10335 Ok(())
10336 }
10337}
10338
10339#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10340#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10341#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10342pub enum LockTableType {
10344 Read {
10346 local: bool,
10348 },
10349 Write {
10351 low_priority: bool,
10353 },
10354}
10355
10356impl fmt::Display for LockTableType {
10357 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10358 match self {
10359 Self::Read { local } => {
10360 write!(f, "READ")?;
10361 if *local {
10362 write!(f, " LOCAL")?;
10363 }
10364 }
10365 Self::Write { low_priority } => {
10366 if *low_priority {
10367 write!(f, "LOW_PRIORITY ")?;
10368 }
10369 write!(f, "WRITE")?;
10370 }
10371 }
10372
10373 Ok(())
10374 }
10375}
10376
10377#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10378#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10379#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10380pub struct HiveSetLocation {
10382 pub has_set: bool,
10384 pub location: Ident,
10386}
10387
10388impl fmt::Display for HiveSetLocation {
10389 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10390 if self.has_set {
10391 write!(f, "SET ")?;
10392 }
10393 write!(f, "LOCATION {}", self.location)
10394 }
10395}
10396
10397#[allow(clippy::large_enum_variant)]
10399#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10400#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10401#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10402pub enum MySQLColumnPosition {
10404 First,
10406 After(Ident),
10408}
10409
10410impl Display for MySQLColumnPosition {
10411 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10412 match self {
10413 MySQLColumnPosition::First => write!(f, "FIRST"),
10414 MySQLColumnPosition::After(ident) => {
10415 let column_name = &ident.value;
10416 write!(f, "AFTER {column_name}")
10417 }
10418 }
10419 }
10420}
10421
10422#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10424#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10425#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10426pub enum CreateViewAlgorithm {
10428 Undefined,
10430 Merge,
10432 TempTable,
10434}
10435
10436impl Display for CreateViewAlgorithm {
10437 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10438 match self {
10439 CreateViewAlgorithm::Undefined => write!(f, "UNDEFINED"),
10440 CreateViewAlgorithm::Merge => write!(f, "MERGE"),
10441 CreateViewAlgorithm::TempTable => write!(f, "TEMPTABLE"),
10442 }
10443 }
10444}
10445#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10447#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10448#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10449pub enum CreateViewSecurity {
10451 Definer,
10453 Invoker,
10455}
10456
10457impl Display for CreateViewSecurity {
10458 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10459 match self {
10460 CreateViewSecurity::Definer => write!(f, "DEFINER"),
10461 CreateViewSecurity::Invoker => write!(f, "INVOKER"),
10462 }
10463 }
10464}
10465
10466#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10470#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10471#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10472pub struct CreateViewParams {
10473 pub algorithm: Option<CreateViewAlgorithm>,
10475 pub definer: Option<GranteeName>,
10477 pub security: Option<CreateViewSecurity>,
10479}
10480
10481impl Display for CreateViewParams {
10482 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10483 let CreateViewParams {
10484 algorithm,
10485 definer,
10486 security,
10487 } = self;
10488 if let Some(algorithm) = algorithm {
10489 write!(f, "ALGORITHM = {algorithm} ")?;
10490 }
10491 if let Some(definers) = definer {
10492 write!(f, "DEFINER = {definers} ")?;
10493 }
10494 if let Some(security) = security {
10495 write!(f, "SQL SECURITY {security} ")?;
10496 }
10497 Ok(())
10498 }
10499}
10500
10501#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10502#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10503#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10504pub struct NamedParenthesizedList {
10512 pub key: Ident,
10514 pub name: Option<Ident>,
10516 pub values: Vec<Ident>,
10518}
10519
10520#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10525#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10526#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10527pub struct RowAccessPolicy {
10528 pub policy: ObjectName,
10530 pub on: Vec<Ident>,
10532}
10533
10534impl RowAccessPolicy {
10535 pub fn new(policy: ObjectName, on: Vec<Ident>) -> Self {
10537 Self { policy, on }
10538 }
10539}
10540
10541impl Display for RowAccessPolicy {
10542 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10543 write!(
10544 f,
10545 "WITH ROW ACCESS POLICY {} ON ({})",
10546 self.policy,
10547 display_comma_separated(self.on.as_slice())
10548 )
10549 }
10550}
10551
10552#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10556#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10557#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10558pub struct StorageLifecyclePolicy {
10559 pub policy: ObjectName,
10561 pub on: Vec<Ident>,
10563}
10564
10565impl Display for StorageLifecyclePolicy {
10566 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10567 write!(
10568 f,
10569 "WITH STORAGE LIFECYCLE POLICY {} ON ({})",
10570 self.policy,
10571 display_comma_separated(self.on.as_slice())
10572 )
10573 }
10574}
10575
10576#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10580#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10581#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10582pub struct Tag {
10583 pub key: ObjectName,
10585 pub value: String,
10587}
10588
10589impl Tag {
10590 pub fn new(key: ObjectName, value: String) -> Self {
10592 Self { key, value }
10593 }
10594}
10595
10596impl Display for Tag {
10597 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10598 write!(f, "{}='{}'", self.key, self.value)
10599 }
10600}
10601
10602#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10606#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10607#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10608pub struct ContactEntry {
10609 pub purpose: String,
10611 pub contact: String,
10613}
10614
10615impl Display for ContactEntry {
10616 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10617 write!(f, "{} = {}", self.purpose, self.contact)
10618 }
10619}
10620
10621#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10623#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10624#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10625pub enum CommentDef {
10626 WithEq(String),
10629 WithoutEq(String),
10631}
10632
10633impl Display for CommentDef {
10634 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10635 match self {
10636 CommentDef::WithEq(comment) | CommentDef::WithoutEq(comment) => write!(f, "{comment}"),
10637 }
10638 }
10639}
10640
10641#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10656#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10657#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10658pub enum WrappedCollection<T> {
10659 NoWrapping(T),
10661 Parentheses(T),
10663}
10664
10665impl<T> Display for WrappedCollection<Vec<T>>
10666where
10667 T: Display,
10668{
10669 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10670 match self {
10671 WrappedCollection::NoWrapping(inner) => {
10672 write!(f, "{}", display_comma_separated(inner.as_slice()))
10673 }
10674 WrappedCollection::Parentheses(inner) => {
10675 write!(f, "({})", display_comma_separated(inner.as_slice()))
10676 }
10677 }
10678 }
10679}
10680
10681#[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 struct UtilityOption {
10708 pub name: Ident,
10710 pub arg: Option<Expr>,
10712}
10713
10714impl Display for UtilityOption {
10715 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10716 if let Some(ref arg) = self.arg {
10717 write!(f, "{} {}", self.name, arg)
10718 } else {
10719 write!(f, "{}", self.name)
10720 }
10721 }
10722}
10723
10724#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10728#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10729#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10730pub struct ShowStatementOptions {
10731 pub show_in: Option<ShowStatementIn>,
10733 pub starts_with: Option<ValueWithSpan>,
10735 pub limit: Option<Expr>,
10737 pub limit_from: Option<ValueWithSpan>,
10739 pub filter_position: Option<ShowStatementFilterPosition>,
10741}
10742
10743impl Display for ShowStatementOptions {
10744 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10745 let (like_in_infix, like_in_suffix) = match &self.filter_position {
10746 Some(ShowStatementFilterPosition::Infix(filter)) => {
10747 (format!(" {filter}"), "".to_string())
10748 }
10749 Some(ShowStatementFilterPosition::Suffix(filter)) => {
10750 ("".to_string(), format!(" {filter}"))
10751 }
10752 None => ("".to_string(), "".to_string()),
10753 };
10754 write!(
10755 f,
10756 "{like_in_infix}{show_in}{starts_with}{limit}{from}{like_in_suffix}",
10757 show_in = match &self.show_in {
10758 Some(i) => format!(" {i}"),
10759 None => String::new(),
10760 },
10761 starts_with = match &self.starts_with {
10762 Some(s) => format!(" STARTS WITH {s}"),
10763 None => String::new(),
10764 },
10765 limit = match &self.limit {
10766 Some(l) => format!(" LIMIT {l}"),
10767 None => String::new(),
10768 },
10769 from = match &self.limit_from {
10770 Some(f) => format!(" FROM {f}"),
10771 None => String::new(),
10772 }
10773 )?;
10774 Ok(())
10775 }
10776}
10777
10778#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10779#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10780#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10781pub enum ShowStatementFilterPosition {
10783 Infix(ShowStatementFilter), Suffix(ShowStatementFilter), }
10788
10789#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10790#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10791#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10792pub enum ShowStatementInParentType {
10794 Account,
10796 Database,
10798 Schema,
10800 Table,
10802 View,
10804}
10805
10806impl fmt::Display for ShowStatementInParentType {
10807 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10808 match self {
10809 ShowStatementInParentType::Account => write!(f, "ACCOUNT"),
10810 ShowStatementInParentType::Database => write!(f, "DATABASE"),
10811 ShowStatementInParentType::Schema => write!(f, "SCHEMA"),
10812 ShowStatementInParentType::Table => write!(f, "TABLE"),
10813 ShowStatementInParentType::View => write!(f, "VIEW"),
10814 }
10815 }
10816}
10817
10818#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10819#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10820#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10821pub struct ShowStatementIn {
10823 pub clause: ShowStatementInClause,
10825 pub parent_type: Option<ShowStatementInParentType>,
10827 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
10829 pub parent_name: Option<ObjectName>,
10830}
10831
10832impl fmt::Display for ShowStatementIn {
10833 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10834 write!(f, "{}", self.clause)?;
10835 if let Some(parent_type) = &self.parent_type {
10836 write!(f, " {parent_type}")?;
10837 }
10838 if let Some(parent_name) = &self.parent_name {
10839 write!(f, " {parent_name}")?;
10840 }
10841 Ok(())
10842 }
10843}
10844
10845#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10847#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10848#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10849pub struct ShowCharset {
10850 pub is_shorthand: bool,
10853 pub filter: Option<ShowStatementFilter>,
10855}
10856
10857impl fmt::Display for ShowCharset {
10858 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10859 write!(f, "SHOW")?;
10860 if self.is_shorthand {
10861 write!(f, " CHARSET")?;
10862 } else {
10863 write!(f, " CHARACTER SET")?;
10864 }
10865 if let Some(filter) = &self.filter {
10866 write!(f, " {filter}")?;
10867 }
10868 Ok(())
10869 }
10870}
10871
10872#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10873#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10874#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10875pub struct ShowObjects {
10877 pub terse: bool,
10879 pub show_options: ShowStatementOptions,
10881}
10882
10883#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10893#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10894#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10895pub enum JsonNullClause {
10896 NullOnNull,
10898 AbsentOnNull,
10900}
10901
10902impl Display for JsonNullClause {
10903 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10904 match self {
10905 JsonNullClause::NullOnNull => write!(f, "NULL ON NULL"),
10906 JsonNullClause::AbsentOnNull => write!(f, "ABSENT ON NULL"),
10907 }
10908 }
10909}
10910
10911#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10918#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10919#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10920pub struct JsonReturningClause {
10921 pub data_type: DataType,
10923}
10924
10925impl Display for JsonReturningClause {
10926 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10927 write!(f, "RETURNING {}", self.data_type)
10928 }
10929}
10930
10931#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10933#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10934#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10935pub struct RenameTable {
10936 pub old_name: ObjectName,
10938 pub new_name: ObjectName,
10940}
10941
10942impl fmt::Display for RenameTable {
10943 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10944 write!(f, "{} TO {}", self.old_name, self.new_name)?;
10945 Ok(())
10946 }
10947}
10948
10949#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10951#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10952#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10953pub enum TableObject {
10954 TableName(#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] ObjectName),
10960
10961 TableFunction(Function),
10968
10969 TableQuery(Box<Query>),
10978}
10979
10980impl fmt::Display for TableObject {
10981 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10982 match self {
10983 Self::TableName(table_name) => write!(f, "{table_name}"),
10984 Self::TableFunction(func) => write!(f, "FUNCTION {func}"),
10985 Self::TableQuery(table_query) => write!(f, "({table_query})"),
10986 }
10987 }
10988}
10989
10990#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10992#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10993#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10994pub struct SetSessionAuthorizationParam {
10995 pub scope: ContextModifier,
10997 pub kind: SetSessionAuthorizationParamKind,
10999}
11000
11001impl fmt::Display for SetSessionAuthorizationParam {
11002 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11003 write!(f, "{}", self.kind)
11004 }
11005}
11006
11007#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11009#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11010#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11011pub enum SetSessionAuthorizationParamKind {
11012 Default,
11014
11015 User(Ident),
11017}
11018
11019impl fmt::Display for SetSessionAuthorizationParamKind {
11020 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11021 match self {
11022 SetSessionAuthorizationParamKind::Default => write!(f, "DEFAULT"),
11023 SetSessionAuthorizationParamKind::User(name) => write!(f, "{}", name),
11024 }
11025 }
11026}
11027
11028#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11029#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11030#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11031pub enum SetSessionParamKind {
11033 Generic(SetSessionParamGeneric),
11035 IdentityInsert(SetSessionParamIdentityInsert),
11037 Offsets(SetSessionParamOffsets),
11039 Statistics(SetSessionParamStatistics),
11041}
11042
11043impl fmt::Display for SetSessionParamKind {
11044 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11045 match self {
11046 SetSessionParamKind::Generic(x) => write!(f, "{x}"),
11047 SetSessionParamKind::IdentityInsert(x) => write!(f, "{x}"),
11048 SetSessionParamKind::Offsets(x) => write!(f, "{x}"),
11049 SetSessionParamKind::Statistics(x) => write!(f, "{x}"),
11050 }
11051 }
11052}
11053
11054#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11055#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11056#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11057pub struct SetSessionParamGeneric {
11059 pub names: Vec<String>,
11061 pub value: String,
11063}
11064
11065impl fmt::Display for SetSessionParamGeneric {
11066 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11067 write!(f, "{} {}", display_comma_separated(&self.names), self.value)
11068 }
11069}
11070
11071#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11072#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11073#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11074pub struct SetSessionParamIdentityInsert {
11076 pub obj: ObjectName,
11078 pub value: SessionParamValue,
11080}
11081
11082impl fmt::Display for SetSessionParamIdentityInsert {
11083 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11084 write!(f, "IDENTITY_INSERT {} {}", self.obj, self.value)
11085 }
11086}
11087
11088#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11089#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11090#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11091pub struct SetSessionParamOffsets {
11093 pub keywords: Vec<String>,
11095 pub value: SessionParamValue,
11097}
11098
11099impl fmt::Display for SetSessionParamOffsets {
11100 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11101 write!(
11102 f,
11103 "OFFSETS {} {}",
11104 display_comma_separated(&self.keywords),
11105 self.value
11106 )
11107 }
11108}
11109
11110#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11111#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11112#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11113pub struct SetSessionParamStatistics {
11115 pub topic: SessionParamStatsTopic,
11117 pub value: SessionParamValue,
11119}
11120
11121impl fmt::Display for SetSessionParamStatistics {
11122 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11123 write!(f, "STATISTICS {} {}", self.topic, self.value)
11124 }
11125}
11126
11127#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11128#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11129#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11130pub enum SessionParamStatsTopic {
11132 IO,
11134 Profile,
11136 Time,
11138 Xml,
11140}
11141
11142impl fmt::Display for SessionParamStatsTopic {
11143 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11144 match self {
11145 SessionParamStatsTopic::IO => write!(f, "IO"),
11146 SessionParamStatsTopic::Profile => write!(f, "PROFILE"),
11147 SessionParamStatsTopic::Time => write!(f, "TIME"),
11148 SessionParamStatsTopic::Xml => write!(f, "XML"),
11149 }
11150 }
11151}
11152
11153#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11154#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11155#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11156pub enum SessionParamValue {
11158 On,
11160 Off,
11162}
11163
11164impl fmt::Display for SessionParamValue {
11165 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11166 match self {
11167 SessionParamValue::On => write!(f, "ON"),
11168 SessionParamValue::Off => write!(f, "OFF"),
11169 }
11170 }
11171}
11172
11173#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11180#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11181#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11182pub enum StorageSerializationPolicy {
11183 Compatible,
11185 Optimized,
11187}
11188
11189impl Display for StorageSerializationPolicy {
11190 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11191 match self {
11192 StorageSerializationPolicy::Compatible => write!(f, "COMPATIBLE"),
11193 StorageSerializationPolicy::Optimized => write!(f, "OPTIMIZED"),
11194 }
11195 }
11196}
11197
11198#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11205#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11206#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11207pub enum CatalogSyncNamespaceMode {
11208 Nest,
11210 Flatten,
11212}
11213
11214impl Display for CatalogSyncNamespaceMode {
11215 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11216 match self {
11217 CatalogSyncNamespaceMode::Nest => write!(f, "NEST"),
11218 CatalogSyncNamespaceMode::Flatten => write!(f, "FLATTEN"),
11219 }
11220 }
11221}
11222
11223#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11225#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11226#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11227pub enum CopyIntoSnowflakeKind {
11228 Table,
11231 Location,
11234}
11235
11236#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11237#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11238#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11239pub struct PrintStatement {
11241 pub message: Box<Expr>,
11243}
11244
11245impl fmt::Display for PrintStatement {
11246 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11247 write!(f, "PRINT {}", self.message)
11248 }
11249}
11250
11251#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11255#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11256#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11257pub enum WaitForType {
11258 Delay,
11260 Time,
11262}
11263
11264impl fmt::Display for WaitForType {
11265 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11266 match self {
11267 WaitForType::Delay => write!(f, "DELAY"),
11268 WaitForType::Time => write!(f, "TIME"),
11269 }
11270 }
11271}
11272
11273#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11277#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11278#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11279pub struct WaitForStatement {
11280 pub wait_type: WaitForType,
11282 pub expr: Expr,
11284}
11285
11286impl fmt::Display for WaitForStatement {
11287 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11288 write!(f, "WAITFOR {} {}", self.wait_type, self.expr)
11289 }
11290}
11291
11292#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11297#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11298#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11299pub struct ReturnStatement {
11300 pub value: Option<ReturnStatementValue>,
11302}
11303
11304impl fmt::Display for ReturnStatement {
11305 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11306 match &self.value {
11307 Some(ReturnStatementValue::Expr(expr)) => write!(f, "RETURN {expr}"),
11308 None => write!(f, "RETURN"),
11309 }
11310 }
11311}
11312
11313#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11315#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11316#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11317pub enum ReturnStatementValue {
11318 Expr(Expr),
11320}
11321
11322#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11324#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11325#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11326pub struct OpenStatement {
11327 pub cursor_name: Ident,
11329}
11330
11331impl fmt::Display for OpenStatement {
11332 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11333 write!(f, "OPEN {}", self.cursor_name)
11334 }
11335}
11336
11337#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11341#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11342#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11343pub enum NullInclusion {
11344 IncludeNulls,
11346 ExcludeNulls,
11348}
11349
11350impl fmt::Display for NullInclusion {
11351 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11352 match self {
11353 NullInclusion::IncludeNulls => write!(f, "INCLUDE NULLS"),
11354 NullInclusion::ExcludeNulls => write!(f, "EXCLUDE NULLS"),
11355 }
11356 }
11357}
11358
11359#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11367#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11368#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11369pub struct MemberOf {
11370 pub value: Box<Expr>,
11372 pub array: Box<Expr>,
11374}
11375
11376impl fmt::Display for MemberOf {
11377 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11378 write!(f, "{} MEMBER OF({})", self.value, self.array)
11379 }
11380}
11381
11382#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11383#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11384#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11385pub struct ExportData {
11387 pub options: Vec<SqlOption>,
11389 pub query: Box<Query>,
11391 pub connection: Option<ObjectName>,
11393}
11394
11395impl fmt::Display for ExportData {
11396 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11397 if let Some(connection) = &self.connection {
11398 write!(
11399 f,
11400 "EXPORT DATA WITH CONNECTION {connection} OPTIONS({}) AS {}",
11401 display_comma_separated(&self.options),
11402 self.query
11403 )
11404 } else {
11405 write!(
11406 f,
11407 "EXPORT DATA OPTIONS({}) AS {}",
11408 display_comma_separated(&self.options),
11409 self.query
11410 )
11411 }
11412 }
11413}
11414#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11423#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11424#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11425pub struct CreateUser {
11426 pub or_replace: bool,
11428 pub if_not_exists: bool,
11430 pub name: Ident,
11432 pub options: KeyValueOptions,
11434 pub with_tags: bool,
11436 pub tags: KeyValueOptions,
11438}
11439
11440impl fmt::Display for CreateUser {
11441 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11442 write!(f, "CREATE")?;
11443 if self.or_replace {
11444 write!(f, " OR REPLACE")?;
11445 }
11446 write!(f, " USER")?;
11447 if self.if_not_exists {
11448 write!(f, " IF NOT EXISTS")?;
11449 }
11450 write!(f, " {}", self.name)?;
11451 if !self.options.options.is_empty() {
11452 write!(f, " {}", self.options)?;
11453 }
11454 if !self.tags.options.is_empty() {
11455 if self.with_tags {
11456 write!(f, " WITH")?;
11457 }
11458 write!(f, " TAG ({})", self.tags)?;
11459 }
11460 Ok(())
11461 }
11462}
11463
11464#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11476#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11477#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11478pub struct AlterUser {
11479 pub if_exists: bool,
11481 pub name: Ident,
11483 pub rename_to: Option<Ident>,
11486 pub reset_password: bool,
11488 pub abort_all_queries: bool,
11490 pub add_role_delegation: Option<AlterUserAddRoleDelegation>,
11492 pub remove_role_delegation: Option<AlterUserRemoveRoleDelegation>,
11494 pub enroll_mfa: bool,
11496 pub set_default_mfa_method: Option<MfaMethodKind>,
11498 pub remove_mfa_method: Option<MfaMethodKind>,
11500 pub modify_mfa_method: Option<AlterUserModifyMfaMethod>,
11502 pub add_mfa_method_otp: Option<AlterUserAddMfaMethodOtp>,
11504 pub set_policy: Option<AlterUserSetPolicy>,
11506 pub unset_policy: Option<UserPolicyKind>,
11508 pub set_tag: KeyValueOptions,
11510 pub unset_tag: Vec<String>,
11512 pub set_props: KeyValueOptions,
11514 pub unset_props: Vec<String>,
11516 pub password: Option<AlterUserPassword>,
11518}
11519
11520#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11524#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11525#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11526pub struct AlterUserAddRoleDelegation {
11527 pub role: Ident,
11529 pub integration: Ident,
11531}
11532
11533#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11537#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11538#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11539pub struct AlterUserRemoveRoleDelegation {
11540 pub role: Option<Ident>,
11542 pub integration: Ident,
11544}
11545
11546#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11550#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11551#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11552pub struct AlterUserAddMfaMethodOtp {
11553 pub count: Option<ValueWithSpan>,
11555}
11556
11557#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11561#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11562#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11563pub struct AlterUserModifyMfaMethod {
11564 pub method: MfaMethodKind,
11566 pub comment: String,
11568}
11569
11570#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11572#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11573#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11574pub enum MfaMethodKind {
11575 PassKey,
11577 Totp,
11579 Duo,
11581}
11582
11583impl fmt::Display for MfaMethodKind {
11584 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11585 match self {
11586 MfaMethodKind::PassKey => write!(f, "PASSKEY"),
11587 MfaMethodKind::Totp => write!(f, "TOTP"),
11588 MfaMethodKind::Duo => write!(f, "DUO"),
11589 }
11590 }
11591}
11592
11593#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11597#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11598#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11599pub struct AlterUserSetPolicy {
11600 pub policy_kind: UserPolicyKind,
11602 pub policy: Ident,
11604}
11605
11606#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11608#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11609#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11610pub enum UserPolicyKind {
11611 Authentication,
11613 Password,
11615 Session,
11617}
11618
11619impl fmt::Display for UserPolicyKind {
11620 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11621 match self {
11622 UserPolicyKind::Authentication => write!(f, "AUTHENTICATION"),
11623 UserPolicyKind::Password => write!(f, "PASSWORD"),
11624 UserPolicyKind::Session => write!(f, "SESSION"),
11625 }
11626 }
11627}
11628
11629impl fmt::Display for AlterUser {
11630 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11631 write!(f, "ALTER")?;
11632 write!(f, " USER")?;
11633 if self.if_exists {
11634 write!(f, " IF EXISTS")?;
11635 }
11636 write!(f, " {}", self.name)?;
11637 if let Some(new_name) = &self.rename_to {
11638 write!(f, " RENAME TO {new_name}")?;
11639 }
11640 if self.reset_password {
11641 write!(f, " RESET PASSWORD")?;
11642 }
11643 if self.abort_all_queries {
11644 write!(f, " ABORT ALL QUERIES")?;
11645 }
11646 if let Some(role_delegation) = &self.add_role_delegation {
11647 let role = &role_delegation.role;
11648 let integration = &role_delegation.integration;
11649 write!(
11650 f,
11651 " ADD DELEGATED AUTHORIZATION OF ROLE {role} TO SECURITY INTEGRATION {integration}"
11652 )?;
11653 }
11654 if let Some(role_delegation) = &self.remove_role_delegation {
11655 write!(f, " REMOVE DELEGATED")?;
11656 match &role_delegation.role {
11657 Some(role) => write!(f, " AUTHORIZATION OF ROLE {role}")?,
11658 None => write!(f, " AUTHORIZATIONS")?,
11659 }
11660 let integration = &role_delegation.integration;
11661 write!(f, " FROM SECURITY INTEGRATION {integration}")?;
11662 }
11663 if self.enroll_mfa {
11664 write!(f, " ENROLL MFA")?;
11665 }
11666 if let Some(method) = &self.set_default_mfa_method {
11667 write!(f, " SET DEFAULT_MFA_METHOD {method}")?
11668 }
11669 if let Some(method) = &self.remove_mfa_method {
11670 write!(f, " REMOVE MFA METHOD {method}")?;
11671 }
11672 if let Some(modify) = &self.modify_mfa_method {
11673 let method = &modify.method;
11674 let comment = &modify.comment;
11675 write!(
11676 f,
11677 " MODIFY MFA METHOD {method} SET COMMENT '{}'",
11678 value::escape_single_quote_string(comment)
11679 )?;
11680 }
11681 if let Some(add_mfa_method_otp) = &self.add_mfa_method_otp {
11682 write!(f, " ADD MFA METHOD OTP")?;
11683 if let Some(count) = &add_mfa_method_otp.count {
11684 write!(f, " COUNT = {count}")?;
11685 }
11686 }
11687 if let Some(policy) = &self.set_policy {
11688 let policy_kind = &policy.policy_kind;
11689 let name = &policy.policy;
11690 write!(f, " SET {policy_kind} POLICY {name}")?;
11691 }
11692 if let Some(policy_kind) = &self.unset_policy {
11693 write!(f, " UNSET {policy_kind} POLICY")?;
11694 }
11695 if !self.set_tag.options.is_empty() {
11696 write!(f, " SET TAG {}", self.set_tag)?;
11697 }
11698 if !self.unset_tag.is_empty() {
11699 write!(f, " UNSET TAG {}", display_comma_separated(&self.unset_tag))?;
11700 }
11701 let has_props = !self.set_props.options.is_empty();
11702 if has_props {
11703 write!(f, " SET")?;
11704 write!(f, " {}", &self.set_props)?;
11705 }
11706 if !self.unset_props.is_empty() {
11707 write!(f, " UNSET {}", display_comma_separated(&self.unset_props))?;
11708 }
11709 if let Some(password) = &self.password {
11710 write!(f, " {}", password)?;
11711 }
11712 Ok(())
11713 }
11714}
11715
11716#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11720#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11721#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11722pub struct AlterUserPassword {
11723 pub encrypted: bool,
11725 pub password: Option<String>,
11727}
11728
11729impl Display for AlterUserPassword {
11730 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11731 if self.encrypted {
11732 write!(f, "ENCRYPTED ")?;
11733 }
11734 write!(f, "PASSWORD")?;
11735 match &self.password {
11736 None => write!(f, " NULL")?,
11737 Some(password) => write!(f, " '{}'", value::escape_single_quote_string(password))?,
11738 }
11739 Ok(())
11740 }
11741}
11742
11743#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11748#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11749#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11750pub enum CreateTableLikeKind {
11751 Parenthesized(CreateTableLike),
11756 Plain(CreateTableLike),
11762}
11763
11764#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11765#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11766#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11767pub enum CreateTableLikeDefaults {
11769 Including,
11771 Excluding,
11773}
11774
11775impl fmt::Display for CreateTableLikeDefaults {
11776 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11777 match self {
11778 CreateTableLikeDefaults::Including => write!(f, "INCLUDING DEFAULTS"),
11779 CreateTableLikeDefaults::Excluding => write!(f, "EXCLUDING DEFAULTS"),
11780 }
11781 }
11782}
11783
11784#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11785#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11786#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11787pub struct CreateTableLike {
11789 pub name: ObjectName,
11791 pub defaults: Option<CreateTableLikeDefaults>,
11793}
11794
11795impl fmt::Display for CreateTableLike {
11796 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11797 write!(f, "LIKE {}", self.name)?;
11798 if let Some(defaults) = &self.defaults {
11799 write!(f, " {defaults}")?;
11800 }
11801 Ok(())
11802 }
11803}
11804
11805#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11809#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11810#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11811pub enum RefreshModeKind {
11812 Auto,
11814 Full,
11816 Incremental,
11818}
11819
11820impl fmt::Display for RefreshModeKind {
11821 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11822 match self {
11823 RefreshModeKind::Auto => write!(f, "AUTO"),
11824 RefreshModeKind::Full => write!(f, "FULL"),
11825 RefreshModeKind::Incremental => write!(f, "INCREMENTAL"),
11826 }
11827 }
11828}
11829
11830#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11834#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11835#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11836pub enum InitializeKind {
11837 OnCreate,
11839 OnSchedule,
11841}
11842
11843impl fmt::Display for InitializeKind {
11844 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11845 match self {
11846 InitializeKind::OnCreate => write!(f, "ON_CREATE"),
11847 InitializeKind::OnSchedule => write!(f, "ON_SCHEDULE"),
11848 }
11849 }
11850}
11851
11852#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11859#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11860#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11861pub struct VacuumStatement {
11862 pub full: bool,
11864 pub sort_only: bool,
11866 pub delete_only: bool,
11868 pub reindex: bool,
11870 pub recluster: bool,
11872 pub table_name: Option<ObjectName>,
11874 pub threshold: Option<ValueWithSpan>,
11876 pub boost: bool,
11878}
11879
11880impl fmt::Display for VacuumStatement {
11881 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11882 write!(
11883 f,
11884 "VACUUM{}{}{}{}{}",
11885 if self.full { " FULL" } else { "" },
11886 if self.sort_only { " SORT ONLY" } else { "" },
11887 if self.delete_only { " DELETE ONLY" } else { "" },
11888 if self.reindex { " REINDEX" } else { "" },
11889 if self.recluster { " RECLUSTER" } else { "" },
11890 )?;
11891 if let Some(table_name) = &self.table_name {
11892 write!(f, " {table_name}")?;
11893 }
11894 if let Some(threshold) = &self.threshold {
11895 write!(f, " TO {threshold} PERCENT")?;
11896 }
11897 if self.boost {
11898 write!(f, " BOOST")?;
11899 }
11900 Ok(())
11901 }
11902}
11903
11904#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11906#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11907#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11908pub enum Reset {
11909 ALL,
11911
11912 ConfigurationParameter(ObjectName),
11914}
11915
11916#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11921#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11922#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11923pub struct ResetStatement {
11924 pub reset: Reset,
11926}
11927
11928#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11934#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11935#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11936pub struct OptimizerHint {
11937 pub prefix: String,
11944 pub text: String,
11946 pub style: OptimizerHintStyle,
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 OptimizerHintStyle {
11958 SingleLine {
11961 prefix: String,
11963 },
11964 MultiLine,
11967}
11968
11969impl fmt::Display for OptimizerHint {
11970 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11971 match &self.style {
11972 OptimizerHintStyle::SingleLine { prefix } => {
11973 f.write_str(prefix)?;
11974 f.write_str(&self.prefix)?;
11975 f.write_str("+")?;
11976 f.write_str(&self.text)
11977 }
11978 OptimizerHintStyle::MultiLine => {
11979 f.write_str("/*")?;
11980 f.write_str(&self.prefix)?;
11981 f.write_str("+")?;
11982 f.write_str(&self.text)?;
11983 f.write_str("*/")
11984 }
11985 }
11986 }
11987}
11988
11989impl fmt::Display for ResetStatement {
11990 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11991 match &self.reset {
11992 Reset::ALL => write!(f, "RESET ALL"),
11993 Reset::ConfigurationParameter(param) => write!(f, "RESET {}", param),
11994 }
11995 }
11996}
11997
11998impl From<Set> for Statement {
11999 fn from(s: Set) -> Self {
12000 Self::Set(s)
12001 }
12002}
12003
12004impl From<Query> for Statement {
12005 fn from(q: Query) -> Self {
12006 Box::new(q).into()
12007 }
12008}
12009
12010impl From<Box<Query>> for Statement {
12011 fn from(q: Box<Query>) -> Self {
12012 Self::Query(q)
12013 }
12014}
12015
12016impl From<Insert> for Statement {
12017 fn from(i: Insert) -> Self {
12018 Self::Insert(i)
12019 }
12020}
12021
12022impl From<Update> for Statement {
12023 fn from(u: Update) -> Self {
12024 Self::Update(u)
12025 }
12026}
12027
12028impl From<CreateView> for Statement {
12029 fn from(cv: CreateView) -> Self {
12030 Self::CreateView(cv)
12031 }
12032}
12033
12034impl From<CreateRole> for Statement {
12035 fn from(cr: CreateRole) -> Self {
12036 Self::CreateRole(cr)
12037 }
12038}
12039
12040impl From<AlterTable> for Statement {
12041 fn from(at: AlterTable) -> Self {
12042 Self::AlterTable(at)
12043 }
12044}
12045
12046impl From<DropFunction> for Statement {
12047 fn from(df: DropFunction) -> Self {
12048 Self::DropFunction(df)
12049 }
12050}
12051
12052impl From<CreateExtension> for Statement {
12053 fn from(ce: CreateExtension) -> Self {
12054 Self::CreateExtension(ce)
12055 }
12056}
12057
12058impl From<CreateCollation> for Statement {
12059 fn from(c: CreateCollation) -> Self {
12060 Self::CreateCollation(c)
12061 }
12062}
12063
12064impl From<DropExtension> for Statement {
12065 fn from(de: DropExtension) -> Self {
12066 Self::DropExtension(de)
12067 }
12068}
12069
12070impl From<CaseStatement> for Statement {
12071 fn from(c: CaseStatement) -> Self {
12072 Self::Case(c)
12073 }
12074}
12075
12076impl From<IfStatement> for Statement {
12077 fn from(i: IfStatement) -> Self {
12078 Self::If(i)
12079 }
12080}
12081
12082impl From<WhileStatement> for Statement {
12083 fn from(w: WhileStatement) -> Self {
12084 Self::While(w)
12085 }
12086}
12087
12088impl From<RaiseStatement> for Statement {
12089 fn from(r: RaiseStatement) -> Self {
12090 Self::Raise(r)
12091 }
12092}
12093
12094impl From<ThrowStatement> for Statement {
12095 fn from(t: ThrowStatement) -> Self {
12096 Self::Throw(t)
12097 }
12098}
12099
12100impl From<Function> for Statement {
12101 fn from(f: Function) -> Self {
12102 Self::Call(f)
12103 }
12104}
12105
12106impl From<OpenStatement> for Statement {
12107 fn from(o: OpenStatement) -> Self {
12108 Self::Open(o)
12109 }
12110}
12111
12112impl From<Delete> for Statement {
12113 fn from(d: Delete) -> Self {
12114 Self::Delete(d)
12115 }
12116}
12117
12118impl From<CreateTable> for Statement {
12119 fn from(c: CreateTable) -> Self {
12120 Self::CreateTable(c)
12121 }
12122}
12123
12124impl From<CreateIndex> for Statement {
12125 fn from(c: CreateIndex) -> Self {
12126 Self::CreateIndex(c)
12127 }
12128}
12129
12130impl From<CreateServerStatement> for Statement {
12131 fn from(c: CreateServerStatement) -> Self {
12132 Self::CreateServer(c)
12133 }
12134}
12135
12136impl From<CreateConnector> for Statement {
12137 fn from(c: CreateConnector) -> Self {
12138 Self::CreateConnector(c)
12139 }
12140}
12141
12142impl From<CreateOperator> for Statement {
12143 fn from(c: CreateOperator) -> Self {
12144 Self::CreateOperator(c)
12145 }
12146}
12147
12148impl From<CreateOperatorFamily> for Statement {
12149 fn from(c: CreateOperatorFamily) -> Self {
12150 Self::CreateOperatorFamily(c)
12151 }
12152}
12153
12154impl From<CreateOperatorClass> for Statement {
12155 fn from(c: CreateOperatorClass) -> Self {
12156 Self::CreateOperatorClass(c)
12157 }
12158}
12159
12160impl From<AlterSchema> for Statement {
12161 fn from(a: AlterSchema) -> Self {
12162 Self::AlterSchema(a)
12163 }
12164}
12165
12166impl From<AlterFunction> for Statement {
12167 fn from(a: AlterFunction) -> Self {
12168 Self::AlterFunction(a)
12169 }
12170}
12171
12172impl From<AlterType> for Statement {
12173 fn from(a: AlterType) -> Self {
12174 Self::AlterType(a)
12175 }
12176}
12177
12178impl From<AlterCollation> for Statement {
12179 fn from(a: AlterCollation) -> Self {
12180 Self::AlterCollation(a)
12181 }
12182}
12183
12184impl From<AlterOperator> for Statement {
12185 fn from(a: AlterOperator) -> Self {
12186 Self::AlterOperator(a)
12187 }
12188}
12189
12190impl From<AlterOperatorFamily> for Statement {
12191 fn from(a: AlterOperatorFamily) -> Self {
12192 Self::AlterOperatorFamily(a)
12193 }
12194}
12195
12196impl From<AlterOperatorClass> for Statement {
12197 fn from(a: AlterOperatorClass) -> Self {
12198 Self::AlterOperatorClass(a)
12199 }
12200}
12201
12202impl From<Merge> for Statement {
12203 fn from(m: Merge) -> Self {
12204 Self::Merge(m)
12205 }
12206}
12207
12208impl From<AlterUser> for Statement {
12209 fn from(a: AlterUser) -> Self {
12210 Self::AlterUser(a)
12211 }
12212}
12213
12214impl From<DropDomain> for Statement {
12215 fn from(d: DropDomain) -> Self {
12216 Self::DropDomain(d)
12217 }
12218}
12219
12220impl From<ShowCharset> for Statement {
12221 fn from(s: ShowCharset) -> Self {
12222 Self::ShowCharset(s)
12223 }
12224}
12225
12226impl From<ShowObjects> for Statement {
12227 fn from(s: ShowObjects) -> Self {
12228 Self::ShowObjects(s)
12229 }
12230}
12231
12232impl From<Use> for Statement {
12233 fn from(u: Use) -> Self {
12234 Self::Use(u)
12235 }
12236}
12237
12238impl From<CreateFunction> for Statement {
12239 fn from(c: CreateFunction) -> Self {
12240 Self::CreateFunction(c)
12241 }
12242}
12243
12244impl From<CreateTrigger> for Statement {
12245 fn from(c: CreateTrigger) -> Self {
12246 Self::CreateTrigger(c)
12247 }
12248}
12249
12250impl From<DropTrigger> for Statement {
12251 fn from(d: DropTrigger) -> Self {
12252 Self::DropTrigger(d)
12253 }
12254}
12255
12256impl From<DropOperator> for Statement {
12257 fn from(d: DropOperator) -> Self {
12258 Self::DropOperator(d)
12259 }
12260}
12261
12262impl From<DropOperatorFamily> for Statement {
12263 fn from(d: DropOperatorFamily) -> Self {
12264 Self::DropOperatorFamily(d)
12265 }
12266}
12267
12268impl From<DropOperatorClass> for Statement {
12269 fn from(d: DropOperatorClass) -> Self {
12270 Self::DropOperatorClass(d)
12271 }
12272}
12273
12274impl From<DenyStatement> for Statement {
12275 fn from(d: DenyStatement) -> Self {
12276 Self::Deny(d)
12277 }
12278}
12279
12280impl From<CreateDomain> for Statement {
12281 fn from(c: CreateDomain) -> Self {
12282 Self::CreateDomain(c)
12283 }
12284}
12285
12286impl From<RenameTable> for Statement {
12287 fn from(r: RenameTable) -> Self {
12288 vec![r].into()
12289 }
12290}
12291
12292impl From<Vec<RenameTable>> for Statement {
12293 fn from(r: Vec<RenameTable>) -> Self {
12294 Self::RenameTable(r)
12295 }
12296}
12297
12298impl From<PrintStatement> for Statement {
12299 fn from(p: PrintStatement) -> Self {
12300 Self::Print(p)
12301 }
12302}
12303
12304impl From<ReturnStatement> for Statement {
12305 fn from(r: ReturnStatement) -> Self {
12306 Self::Return(r)
12307 }
12308}
12309
12310impl From<ExportData> for Statement {
12311 fn from(e: ExportData) -> Self {
12312 Self::ExportData(e)
12313 }
12314}
12315
12316impl From<CreateUser> for Statement {
12317 fn from(c: CreateUser) -> Self {
12318 Self::CreateUser(c)
12319 }
12320}
12321
12322impl From<VacuumStatement> for Statement {
12323 fn from(v: VacuumStatement) -> Self {
12324 Self::Vacuum(v)
12325 }
12326}
12327
12328impl From<ResetStatement> for Statement {
12329 fn from(r: ResetStatement) -> Self {
12330 Self::Reset(r)
12331 }
12332}
12333
12334#[cfg(test)]
12335mod tests {
12336 use crate::tokenizer::Location;
12337
12338 use super::*;
12339
12340 #[test]
12341 fn test_window_frame_default() {
12342 let window_frame = WindowFrame::default();
12343 assert_eq!(WindowFrameBound::Preceding(None), window_frame.start_bound);
12344 }
12345
12346 #[test]
12347 fn test_grouping_sets_display() {
12348 let grouping_sets = Expr::GroupingSets(vec![
12350 vec![Expr::Identifier(Ident::new("a"))],
12351 vec![Expr::Identifier(Ident::new("b"))],
12352 ]);
12353 assert_eq!("GROUPING SETS ((a), (b))", format!("{grouping_sets}"));
12354
12355 let grouping_sets = Expr::GroupingSets(vec![vec![
12357 Expr::Identifier(Ident::new("a")),
12358 Expr::Identifier(Ident::new("b")),
12359 ]]);
12360 assert_eq!("GROUPING SETS ((a, b))", format!("{grouping_sets}"));
12361
12362 let grouping_sets = Expr::GroupingSets(vec![
12364 vec![
12365 Expr::Identifier(Ident::new("a")),
12366 Expr::Identifier(Ident::new("b")),
12367 ],
12368 vec![
12369 Expr::Identifier(Ident::new("c")),
12370 Expr::Identifier(Ident::new("d")),
12371 ],
12372 ]);
12373 assert_eq!("GROUPING SETS ((a, b), (c, d))", format!("{grouping_sets}"));
12374 }
12375
12376 #[test]
12377 fn test_rollup_display() {
12378 let rollup = Expr::Rollup(vec![vec![Expr::Identifier(Ident::new("a"))]]);
12379 assert_eq!("ROLLUP (a)", format!("{rollup}"));
12380
12381 let rollup = Expr::Rollup(vec![vec![
12382 Expr::Identifier(Ident::new("a")),
12383 Expr::Identifier(Ident::new("b")),
12384 ]]);
12385 assert_eq!("ROLLUP ((a, b))", format!("{rollup}"));
12386
12387 let rollup = Expr::Rollup(vec![
12388 vec![Expr::Identifier(Ident::new("a"))],
12389 vec![Expr::Identifier(Ident::new("b"))],
12390 ]);
12391 assert_eq!("ROLLUP (a, b)", format!("{rollup}"));
12392
12393 let rollup = Expr::Rollup(vec![
12394 vec![Expr::Identifier(Ident::new("a"))],
12395 vec![
12396 Expr::Identifier(Ident::new("b")),
12397 Expr::Identifier(Ident::new("c")),
12398 ],
12399 vec![Expr::Identifier(Ident::new("d"))],
12400 ]);
12401 assert_eq!("ROLLUP (a, (b, c), d)", format!("{rollup}"));
12402 }
12403
12404 #[test]
12405 fn test_cube_display() {
12406 let cube = Expr::Cube(vec![vec![Expr::Identifier(Ident::new("a"))]]);
12407 assert_eq!("CUBE (a)", format!("{cube}"));
12408
12409 let cube = Expr::Cube(vec![vec![
12410 Expr::Identifier(Ident::new("a")),
12411 Expr::Identifier(Ident::new("b")),
12412 ]]);
12413 assert_eq!("CUBE ((a, b))", format!("{cube}"));
12414
12415 let cube = Expr::Cube(vec![
12416 vec![Expr::Identifier(Ident::new("a"))],
12417 vec![Expr::Identifier(Ident::new("b"))],
12418 ]);
12419 assert_eq!("CUBE (a, b)", format!("{cube}"));
12420
12421 let cube = Expr::Cube(vec![
12422 vec![Expr::Identifier(Ident::new("a"))],
12423 vec![
12424 Expr::Identifier(Ident::new("b")),
12425 Expr::Identifier(Ident::new("c")),
12426 ],
12427 vec![Expr::Identifier(Ident::new("d"))],
12428 ]);
12429 assert_eq!("CUBE (a, (b, c), d)", format!("{cube}"));
12430 }
12431
12432 #[test]
12433 fn test_interval_display() {
12434 let interval = Expr::Interval(Interval {
12435 value: Box::new(Expr::Value(
12436 Value::SingleQuotedString(String::from("123:45.67")).with_empty_span(),
12437 )),
12438 leading_field: Some(DateTimeField::Minute),
12439 leading_precision: Some(10),
12440 last_field: Some(DateTimeField::Second),
12441 fractional_seconds_precision: Some(9),
12442 });
12443 assert_eq!(
12444 "INTERVAL '123:45.67' MINUTE (10) TO SECOND (9)",
12445 format!("{interval}"),
12446 );
12447
12448 let interval = Expr::Interval(Interval {
12449 value: Box::new(Expr::Value(
12450 Value::SingleQuotedString(String::from("5")).with_empty_span(),
12451 )),
12452 leading_field: Some(DateTimeField::Second),
12453 leading_precision: Some(1),
12454 last_field: None,
12455 fractional_seconds_precision: Some(3),
12456 });
12457 assert_eq!("INTERVAL '5' SECOND (1, 3)", format!("{interval}"));
12458 }
12459
12460 #[test]
12461 fn test_one_or_many_with_parens_deref() {
12462 use core::ops::Index;
12463
12464 let one = OneOrManyWithParens::One("a");
12465
12466 assert_eq!(one.deref(), &["a"]);
12467 assert_eq!(<OneOrManyWithParens<_> as Deref>::deref(&one), &["a"]);
12468
12469 assert_eq!(one[0], "a");
12470 assert_eq!(one.index(0), &"a");
12471 assert_eq!(
12472 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&one, 0),
12473 &"a"
12474 );
12475
12476 assert_eq!(one.len(), 1);
12477 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&one), 1);
12478
12479 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12480
12481 assert_eq!(many1.deref(), &["b"]);
12482 assert_eq!(<OneOrManyWithParens<_> as Deref>::deref(&many1), &["b"]);
12483
12484 assert_eq!(many1[0], "b");
12485 assert_eq!(many1.index(0), &"b");
12486 assert_eq!(
12487 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many1, 0),
12488 &"b"
12489 );
12490
12491 assert_eq!(many1.len(), 1);
12492 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&many1), 1);
12493
12494 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12495
12496 assert_eq!(many2.deref(), &["c", "d"]);
12497 assert_eq!(
12498 <OneOrManyWithParens<_> as Deref>::deref(&many2),
12499 &["c", "d"]
12500 );
12501
12502 assert_eq!(many2[0], "c");
12503 assert_eq!(many2.index(0), &"c");
12504 assert_eq!(
12505 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many2, 0),
12506 &"c"
12507 );
12508
12509 assert_eq!(many2[1], "d");
12510 assert_eq!(many2.index(1), &"d");
12511 assert_eq!(
12512 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many2, 1),
12513 &"d"
12514 );
12515
12516 assert_eq!(many2.len(), 2);
12517 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&many2), 2);
12518 }
12519
12520 #[test]
12521 fn test_one_or_many_with_parens_as_ref() {
12522 let one = OneOrManyWithParens::One("a");
12523
12524 assert_eq!(one.as_ref(), &["a"]);
12525 assert_eq!(<OneOrManyWithParens<_> as AsRef<_>>::as_ref(&one), &["a"]);
12526
12527 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12528
12529 assert_eq!(many1.as_ref(), &["b"]);
12530 assert_eq!(<OneOrManyWithParens<_> as AsRef<_>>::as_ref(&many1), &["b"]);
12531
12532 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12533
12534 assert_eq!(many2.as_ref(), &["c", "d"]);
12535 assert_eq!(
12536 <OneOrManyWithParens<_> as AsRef<_>>::as_ref(&many2),
12537 &["c", "d"]
12538 );
12539 }
12540
12541 #[test]
12542 fn test_one_or_many_with_parens_ref_into_iter() {
12543 let one = OneOrManyWithParens::One("a");
12544
12545 assert_eq!(Vec::from_iter(&one), vec![&"a"]);
12546
12547 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12548
12549 assert_eq!(Vec::from_iter(&many1), vec![&"b"]);
12550
12551 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12552
12553 assert_eq!(Vec::from_iter(&many2), vec![&"c", &"d"]);
12554 }
12555
12556 #[test]
12557 fn test_one_or_many_with_parens_value_into_iter() {
12558 use core::iter::once;
12559
12560 fn test_steps<I>(ours: OneOrManyWithParens<usize>, inner: I, n: usize)
12562 where
12563 I: IntoIterator<Item = usize, IntoIter: DoubleEndedIterator + Clone> + Clone,
12564 {
12565 fn checks<I>(ours: OneOrManyWithParensIntoIter<usize>, inner: I)
12566 where
12567 I: Iterator<Item = usize> + Clone + DoubleEndedIterator,
12568 {
12569 assert_eq!(ours.size_hint(), inner.size_hint());
12570 assert_eq!(ours.clone().count(), inner.clone().count());
12571
12572 assert_eq!(
12573 ours.clone().fold(1, |a, v| a + v),
12574 inner.clone().fold(1, |a, v| a + v)
12575 );
12576
12577 assert_eq!(Vec::from_iter(ours.clone()), Vec::from_iter(inner.clone()));
12578 assert_eq!(
12579 Vec::from_iter(ours.clone().rev()),
12580 Vec::from_iter(inner.clone().rev())
12581 );
12582 }
12583
12584 let mut ours_next = ours.clone().into_iter();
12585 let mut inner_next = inner.clone().into_iter();
12586
12587 for _ in 0..n {
12588 checks(ours_next.clone(), inner_next.clone());
12589
12590 assert_eq!(ours_next.next(), inner_next.next());
12591 }
12592
12593 let mut ours_next_back = ours.clone().into_iter();
12594 let mut inner_next_back = inner.clone().into_iter();
12595
12596 for _ in 0..n {
12597 checks(ours_next_back.clone(), inner_next_back.clone());
12598
12599 assert_eq!(ours_next_back.next_back(), inner_next_back.next_back());
12600 }
12601
12602 let mut ours_mixed = ours.clone().into_iter();
12603 let mut inner_mixed = inner.clone().into_iter();
12604
12605 for i in 0..n {
12606 checks(ours_mixed.clone(), inner_mixed.clone());
12607
12608 if i % 2 == 0 {
12609 assert_eq!(ours_mixed.next_back(), inner_mixed.next_back());
12610 } else {
12611 assert_eq!(ours_mixed.next(), inner_mixed.next());
12612 }
12613 }
12614
12615 let mut ours_mixed2 = ours.into_iter();
12616 let mut inner_mixed2 = inner.into_iter();
12617
12618 for i in 0..n {
12619 checks(ours_mixed2.clone(), inner_mixed2.clone());
12620
12621 if i % 2 == 0 {
12622 assert_eq!(ours_mixed2.next(), inner_mixed2.next());
12623 } else {
12624 assert_eq!(ours_mixed2.next_back(), inner_mixed2.next_back());
12625 }
12626 }
12627 }
12628
12629 test_steps(OneOrManyWithParens::One(1), once(1), 3);
12630 test_steps(OneOrManyWithParens::Many(vec![2]), vec![2], 3);
12631 test_steps(OneOrManyWithParens::Many(vec![3, 4]), vec![3, 4], 4);
12632 }
12633
12634 #[test]
12637 fn test_ident_ord() {
12638 let mut a = Ident::with_span(Span::new(Location::new(1, 1), Location::new(1, 1)), "a");
12639 let mut b = Ident::with_span(Span::new(Location::new(2, 2), Location::new(2, 2)), "b");
12640
12641 assert!(a < b);
12642 std::mem::swap(&mut a.span, &mut b.span);
12643 assert!(a < b);
12644 }
12645}