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, ForeignKeyConstraint, FullTextOrSpatialConstraint,
142 IndexConstraint, PrimaryKeyConstraint, TableConstraint, UniqueConstraint,
143};
144mod operator;
145mod query;
146mod spans;
147pub use spans::Spanned;
148
149pub mod comments;
150mod trigger;
151mod value;
152
153#[cfg(feature = "visitor")]
154mod visitor;
155
156pub struct DisplaySeparated<'a, T>
158where
159 T: fmt::Display,
160{
161 slice: &'a [T],
162 sep: &'static str,
163}
164
165impl<T> fmt::Display for DisplaySeparated<'_, T>
166where
167 T: fmt::Display,
168{
169 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
170 let mut delim = "";
171 for t in self.slice {
172 f.write_str(delim)?;
173 delim = self.sep;
174 t.fmt(f)?;
175 }
176 Ok(())
177 }
178}
179
180pub(crate) fn display_separated<'a, T>(slice: &'a [T], sep: &'static str) -> DisplaySeparated<'a, T>
181where
182 T: fmt::Display,
183{
184 DisplaySeparated { slice, sep }
185}
186
187pub(crate) fn display_comma_separated<T>(slice: &[T]) -> DisplaySeparated<'_, T>
188where
189 T: fmt::Display,
190{
191 DisplaySeparated { slice, sep: ", " }
192}
193
194fn format_statement_list(f: &mut fmt::Formatter, statements: &[Statement]) -> fmt::Result {
197 write!(f, "{}", display_separated(statements, "; "))?;
198 write!(f, ";")
201}
202
203#[derive(Debug, Clone)]
205#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
206#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
207pub struct Ident {
208 pub value: String,
210 pub quote_style: Option<char>,
213 pub span: Span,
215}
216
217impl PartialEq for Ident {
218 fn eq(&self, other: &Self) -> bool {
219 let Ident {
220 value,
221 quote_style,
222 span: _,
224 } = self;
225
226 value == &other.value && quote_style == &other.quote_style
227 }
228}
229
230impl core::hash::Hash for Ident {
231 fn hash<H: hash::Hasher>(&self, state: &mut H) {
232 let Ident {
233 value,
234 quote_style,
235 span: _,
237 } = self;
238
239 value.hash(state);
240 quote_style.hash(state);
241 }
242}
243
244impl Eq for Ident {}
245
246impl PartialOrd for Ident {
247 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
248 Some(self.cmp(other))
249 }
250}
251
252impl Ord for Ident {
253 fn cmp(&self, other: &Self) -> Ordering {
254 let Ident {
255 value,
256 quote_style,
257 span: _,
259 } = self;
260
261 let Ident {
262 value: other_value,
263 quote_style: other_quote_style,
264 span: _,
266 } = other;
267
268 value
270 .cmp(other_value)
271 .then_with(|| quote_style.cmp(other_quote_style))
272 }
273}
274
275impl Ident {
276 pub fn new<S>(value: S) -> Self
278 where
279 S: Into<String>,
280 {
281 Ident {
282 value: value.into(),
283 quote_style: None,
284 span: Span::empty(),
285 }
286 }
287
288 pub fn with_quote<S>(quote: char, value: S) -> Self
291 where
292 S: Into<String>,
293 {
294 assert!(quote == '\'' || quote == '"' || quote == '`' || quote == '[');
295 Ident {
296 value: value.into(),
297 quote_style: Some(quote),
298 span: Span::empty(),
299 }
300 }
301
302 pub fn with_span<S>(span: Span, value: S) -> Self
304 where
305 S: Into<String>,
306 {
307 Ident {
308 value: value.into(),
309 quote_style: None,
310 span,
311 }
312 }
313
314 pub fn with_quote_and_span<S>(quote: char, span: Span, value: S) -> Self
316 where
317 S: Into<String>,
318 {
319 assert!(quote == '\'' || quote == '"' || quote == '`' || quote == '[');
320 Ident {
321 value: value.into(),
322 quote_style: Some(quote),
323 span,
324 }
325 }
326}
327
328impl From<&str> for Ident {
329 fn from(value: &str) -> Self {
330 Ident {
331 value: value.to_string(),
332 quote_style: None,
333 span: Span::empty(),
334 }
335 }
336}
337
338impl fmt::Display for Ident {
339 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
340 match self.quote_style {
341 Some(q) if q == '"' || q == '\'' || q == '`' => {
342 let escaped = value::escape_quoted_string(&self.value, q);
343 write!(f, "{q}{escaped}{q}")
344 }
345 Some('[') => write!(f, "[{}]", self.value),
346 None => f.write_str(&self.value),
347 _ => panic!("unexpected quote style"),
348 }
349 }
350}
351
352#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
354#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
355#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
356pub struct ObjectName(pub Vec<ObjectNamePart>);
357
358impl From<Vec<Ident>> for ObjectName {
359 fn from(idents: Vec<Ident>) -> Self {
360 ObjectName(idents.into_iter().map(ObjectNamePart::Identifier).collect())
361 }
362}
363
364impl From<Ident> for ObjectName {
365 fn from(ident: Ident) -> Self {
366 ObjectName(vec![ObjectNamePart::Identifier(ident)])
367 }
368}
369
370impl fmt::Display for ObjectName {
371 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
372 write!(f, "{}", display_separated(&self.0, "."))
373 }
374}
375
376#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
378#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
379#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
380pub enum ObjectNamePart {
381 Identifier(Ident),
383 Function(ObjectNamePartFunction),
385}
386
387impl ObjectNamePart {
388 pub fn as_ident(&self) -> Option<&Ident> {
390 match self {
391 ObjectNamePart::Identifier(ident) => Some(ident),
392 ObjectNamePart::Function(_) => None,
393 }
394 }
395}
396
397impl fmt::Display for ObjectNamePart {
398 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
399 match self {
400 ObjectNamePart::Identifier(ident) => write!(f, "{ident}"),
401 ObjectNamePart::Function(func) => write!(f, "{func}"),
402 }
403 }
404}
405
406#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
411#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
412#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
413pub struct ObjectNamePartFunction {
414 pub name: Ident,
416 pub args: Vec<FunctionArg>,
418}
419
420impl fmt::Display for ObjectNamePartFunction {
421 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
422 write!(f, "{}(", self.name)?;
423 write!(f, "{})", display_comma_separated(&self.args))
424 }
425}
426
427#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
430#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
431#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
432pub struct Array {
433 pub elem: Vec<Expr>,
435
436 pub named: bool,
438}
439
440impl fmt::Display for Array {
441 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
442 write!(
443 f,
444 "{}[{}]",
445 if self.named { "ARRAY" } else { "" },
446 display_comma_separated(&self.elem)
447 )
448 }
449}
450
451#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
460#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
461#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
462pub struct Interval {
463 pub value: Box<Expr>,
465 pub leading_field: Option<DateTimeField>,
467 pub leading_precision: Option<u64>,
469 pub last_field: Option<DateTimeField>,
471 pub fractional_seconds_precision: Option<u64>,
475}
476
477impl fmt::Display for Interval {
478 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
479 let value = self.value.as_ref();
480 match (
481 &self.leading_field,
482 self.leading_precision,
483 self.fractional_seconds_precision,
484 ) {
485 (
486 Some(DateTimeField::Second),
487 Some(leading_precision),
488 Some(fractional_seconds_precision),
489 ) => {
490 assert!(self.last_field.is_none());
493 write!(
494 f,
495 "INTERVAL {value} SECOND ({leading_precision}, {fractional_seconds_precision})"
496 )
497 }
498 _ => {
499 write!(f, "INTERVAL {value}")?;
500 if let Some(leading_field) = &self.leading_field {
501 write!(f, " {leading_field}")?;
502 }
503 if let Some(leading_precision) = self.leading_precision {
504 write!(f, " ({leading_precision})")?;
505 }
506 if let Some(last_field) = &self.last_field {
507 write!(f, " TO {last_field}")?;
508 }
509 if let Some(fractional_seconds_precision) = self.fractional_seconds_precision {
510 write!(f, " ({fractional_seconds_precision})")?;
511 }
512 Ok(())
513 }
514 }
515 }
516}
517
518#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
522#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
523#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
524pub struct StructField {
525 pub field_name: Option<Ident>,
527 pub field_type: DataType,
529 pub options: Option<Vec<SqlOption>>,
532}
533
534impl fmt::Display for StructField {
535 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
536 if let Some(name) = &self.field_name {
537 write!(f, "{name} {}", self.field_type)?;
538 } else {
539 write!(f, "{}", self.field_type)?;
540 }
541 if let Some(options) = &self.options {
542 write!(f, " OPTIONS({})", display_separated(options, ", "))
543 } else {
544 Ok(())
545 }
546 }
547}
548
549#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
553#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
554#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
555pub struct UnionField {
556 pub field_name: Ident,
558 pub field_type: DataType,
560}
561
562impl fmt::Display for UnionField {
563 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
564 write!(f, "{} {}", self.field_name, self.field_type)
565 }
566}
567
568#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
572#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
573#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
574pub struct DictionaryField {
575 pub key: Ident,
577 pub value: Box<Expr>,
579}
580
581impl fmt::Display for DictionaryField {
582 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
583 write!(f, "{}: {}", self.key, self.value)
584 }
585}
586
587#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
589#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
590#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
591pub struct Map {
592 pub entries: Vec<MapEntry>,
594}
595
596impl Display for Map {
597 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
598 write!(f, "MAP {{{}}}", display_comma_separated(&self.entries))
599 }
600}
601
602#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
606#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
607#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
608pub struct MapEntry {
609 pub key: Box<Expr>,
611 pub value: Box<Expr>,
613}
614
615impl fmt::Display for MapEntry {
616 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
617 write!(f, "{}: {}", self.key, self.value)
618 }
619}
620
621#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
624#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
625#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
626pub enum CastFormat {
627 Value(ValueWithSpan),
629 ValueAtTimeZone(ValueWithSpan, ValueWithSpan),
631}
632
633#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
635#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
636#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
637pub enum JsonPathElem {
638 Dot {
642 key: String,
644 quoted: bool,
646 },
647 Bracket {
652 key: Expr,
654 },
655 ColonBracket {
660 key: Expr,
662 },
663}
664
665#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
670#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
671#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
672pub struct JsonPath {
673 pub path: Vec<JsonPathElem>,
675}
676
677impl fmt::Display for JsonPath {
678 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
679 for (i, elem) in self.path.iter().enumerate() {
680 match elem {
681 JsonPathElem::Dot { key, quoted } => {
682 if i == 0 {
683 write!(f, ":")?;
684 } else {
685 write!(f, ".")?;
686 }
687
688 if *quoted {
689 write!(f, "\"{}\"", escape_double_quote_string(key))?;
690 } else {
691 write!(f, "{key}")?;
692 }
693 }
694 JsonPathElem::Bracket { key } => {
695 write!(f, "[{key}]")?;
696 }
697 JsonPathElem::ColonBracket { key } => {
698 write!(f, ":[{key}]")?;
699 }
700 }
701 }
702 Ok(())
703 }
704}
705
706#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
708#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
709#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
710pub enum CastKind {
711 Cast,
713 TryCast,
718 SafeCast,
722 DoubleColon,
724}
725
726#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
730#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
731#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
732pub enum ConstraintReferenceMatchKind {
733 Full,
735 Partial,
737 Simple,
739}
740
741impl fmt::Display for ConstraintReferenceMatchKind {
742 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
743 match self {
744 Self::Full => write!(f, "MATCH FULL"),
745 Self::Partial => write!(f, "MATCH PARTIAL"),
746 Self::Simple => write!(f, "MATCH SIMPLE"),
747 }
748 }
749}
750
751#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
758#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
759#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
760pub enum ExtractSyntax {
761 From,
763 Comma,
765}
766
767#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
776#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
777#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
778pub enum CeilFloorKind {
779 DateTimeField(DateTimeField),
781 Scale(ValueWithSpan),
783}
784
785#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
788#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
789#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
790pub struct CaseWhen {
791 pub condition: Expr,
793 pub result: Expr,
795}
796
797impl fmt::Display for CaseWhen {
798 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
799 f.write_str("WHEN ")?;
800 self.condition.fmt(f)?;
801 f.write_str(" THEN")?;
802 SpaceOrNewline.fmt(f)?;
803 Indent(&self.result).fmt(f)?;
804 Ok(())
805 }
806}
807
808#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
826#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
827#[cfg_attr(
828 feature = "visitor",
829 derive(Visit, VisitMut),
830 visit(with = "visit_expr")
831)]
832pub enum Expr {
833 Identifier(Ident),
835 CompoundIdentifier(Vec<Ident>),
837 CompoundFieldAccess {
856 root: Box<Expr>,
858 access_chain: Vec<AccessExpr>,
860 },
861 JsonAccess {
867 value: Box<Expr>,
869 path: JsonPath,
871 },
872 IsFalse(Box<Expr>),
874 IsNotFalse(Box<Expr>),
876 IsTrue(Box<Expr>),
878 IsNotTrue(Box<Expr>),
880 IsNull(Box<Expr>),
882 IsNotNull(Box<Expr>),
884 IsUnknown(Box<Expr>),
886 IsNotUnknown(Box<Expr>),
888 IsDistinctFrom(Box<Expr>, Box<Expr>),
890 IsNotDistinctFrom(Box<Expr>, Box<Expr>),
892 IsNormalized {
894 expr: Box<Expr>,
896 form: Option<NormalizationForm>,
898 negated: bool,
900 },
901 InList {
903 expr: Box<Expr>,
905 list: Vec<Expr>,
907 negated: bool,
909 },
910 InSubquery {
912 expr: Box<Expr>,
914 subquery: Box<Query>,
916 negated: bool,
918 },
919 InUnnest {
921 expr: Box<Expr>,
923 array_expr: Box<Expr>,
925 negated: bool,
927 },
928 Between {
930 expr: Box<Expr>,
932 negated: bool,
934 low: Box<Expr>,
936 high: Box<Expr>,
938 },
939 BinaryOp {
941 left: Box<Expr>,
943 op: BinaryOperator,
945 right: Box<Expr>,
947 },
948 Like {
950 negated: bool,
952 any: bool,
955 expr: Box<Expr>,
957 pattern: Box<Expr>,
959 escape_char: Option<ValueWithSpan>,
961 },
962 ILike {
964 negated: bool,
966 any: bool,
969 expr: Box<Expr>,
971 pattern: Box<Expr>,
973 escape_char: Option<ValueWithSpan>,
975 },
976 SimilarTo {
978 negated: bool,
980 expr: Box<Expr>,
982 pattern: Box<Expr>,
984 escape_char: Option<ValueWithSpan>,
986 },
987 RLike {
989 negated: bool,
991 expr: Box<Expr>,
993 pattern: Box<Expr>,
995 regexp: bool,
997 },
998 AnyOp {
1001 left: Box<Expr>,
1003 compare_op: BinaryOperator,
1005 right: Box<Expr>,
1007 is_some: bool,
1009 },
1010 AllOp {
1013 left: Box<Expr>,
1015 compare_op: BinaryOperator,
1017 right: Box<Expr>,
1019 },
1020
1021 UnaryOp {
1023 op: UnaryOperator,
1025 expr: Box<Expr>,
1027 },
1028 Convert {
1030 is_try: bool,
1033 expr: Box<Expr>,
1035 data_type: Option<DataType>,
1037 charset: Option<ObjectName>,
1039 target_before_value: bool,
1041 styles: Vec<Expr>,
1045 },
1046 Cast {
1048 kind: CastKind,
1050 expr: Box<Expr>,
1052 data_type: DataType,
1054 array: bool,
1060 format: Option<CastFormat>,
1064 },
1065 AtTimeZone {
1067 timestamp: Box<Expr>,
1069 time_zone: Box<Expr>,
1071 },
1072 Extract {
1080 field: DateTimeField,
1082 syntax: ExtractSyntax,
1084 expr: Box<Expr>,
1086 },
1087 Ceil {
1094 expr: Box<Expr>,
1096 field: CeilFloorKind,
1098 },
1099 Floor {
1106 expr: Box<Expr>,
1108 field: CeilFloorKind,
1110 },
1111 Position {
1115 expr: Box<Expr>,
1117 r#in: Box<Expr>,
1119 },
1120 Substring {
1128 expr: Box<Expr>,
1130 substring_from: Option<Box<Expr>>,
1132 substring_for: Option<Box<Expr>>,
1134
1135 special: bool,
1139
1140 shorthand: bool,
1143 },
1144 Trim {
1150 trim_where: Option<TrimWhereField>,
1152 trim_what: Option<Box<Expr>>,
1154 expr: Box<Expr>,
1156 trim_characters: Option<Vec<Expr>>,
1158 },
1159 Overlay {
1163 expr: Box<Expr>,
1165 overlay_what: Box<Expr>,
1167 overlay_from: Box<Expr>,
1169 overlay_for: Option<Box<Expr>>,
1171 },
1172 Collate {
1174 expr: Box<Expr>,
1176 collation: ObjectName,
1178 },
1179 Nested(Box<Expr>),
1181 Value(ValueWithSpan),
1183 Prefixed {
1187 prefix: Ident,
1189 value: Box<Expr>,
1192 },
1193 TypedString(TypedString),
1197 Function(Function),
1199 Case {
1205 case_token: AttachedToken,
1207 end_token: AttachedToken,
1209 operand: Option<Box<Expr>>,
1211 conditions: Vec<CaseWhen>,
1213 else_result: Option<Box<Expr>>,
1215 },
1216 Exists {
1219 subquery: Box<Query>,
1221 negated: bool,
1223 },
1224 Subquery(Box<Query>),
1227 GroupingSets(Vec<Vec<Expr>>),
1229 Cube(Vec<Vec<Expr>>),
1231 Rollup(Vec<Vec<Expr>>),
1233 Tuple(Vec<Expr>),
1235 Struct {
1244 values: Vec<Expr>,
1246 fields: Vec<StructField>,
1248 },
1249 Named {
1257 expr: Box<Expr>,
1259 name: Ident,
1261 },
1262 Dictionary(Vec<DictionaryField>),
1270 Map(Map),
1278 Array(Array),
1280 Interval(Interval),
1282 MatchAgainst {
1293 columns: Vec<ObjectName>,
1295 match_value: ValueWithSpan,
1297 opt_search_modifier: Option<SearchModifier>,
1299 },
1300 Wildcard(AttachedToken),
1302 QualifiedWildcard(ObjectName, AttachedToken),
1305 OuterJoin(Box<Expr>),
1320 Prior(Box<Expr>),
1322 Lambda(LambdaFunction),
1333 MemberOf(MemberOf),
1335}
1336
1337impl Expr {
1338 pub fn value(value: impl Into<ValueWithSpan>) -> Self {
1340 Expr::Value(value.into())
1341 }
1342}
1343
1344#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1346#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1347#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1348pub enum Subscript {
1349 Index {
1351 index: Expr,
1353 },
1354
1355 Slice {
1377 lower_bound: Option<Expr>,
1379 upper_bound: Option<Expr>,
1381 stride: Option<Expr>,
1383 },
1384}
1385
1386impl fmt::Display for Subscript {
1387 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1388 match self {
1389 Subscript::Index { index } => write!(f, "{index}"),
1390 Subscript::Slice {
1391 lower_bound,
1392 upper_bound,
1393 stride,
1394 } => {
1395 if let Some(lower) = lower_bound {
1396 write!(f, "{lower}")?;
1397 }
1398 write!(f, ":")?;
1399 if let Some(upper) = upper_bound {
1400 write!(f, "{upper}")?;
1401 }
1402 if let Some(stride) = stride {
1403 write!(f, ":")?;
1404 write!(f, "{stride}")?;
1405 }
1406 Ok(())
1407 }
1408 }
1409 }
1410}
1411
1412#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1415#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1416#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1417pub enum AccessExpr {
1418 Dot(Expr),
1420 Subscript(Subscript),
1422}
1423
1424impl fmt::Display for AccessExpr {
1425 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1426 match self {
1427 AccessExpr::Dot(expr) => write!(f, ".{expr}"),
1428 AccessExpr::Subscript(subscript) => write!(f, "[{subscript}]"),
1429 }
1430 }
1431}
1432
1433#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1435#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1436#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1437pub struct LambdaFunction {
1438 pub params: OneOrManyWithParens<LambdaFunctionParameter>,
1440 pub body: Box<Expr>,
1442 pub syntax: LambdaSyntax,
1444}
1445
1446impl fmt::Display for LambdaFunction {
1447 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1448 match self.syntax {
1449 LambdaSyntax::Arrow => write!(f, "{} -> {}", self.params, self.body),
1450 LambdaSyntax::LambdaKeyword => {
1451 write!(f, "lambda ")?;
1454 match &self.params {
1455 OneOrManyWithParens::One(p) => write!(f, "{p}")?,
1456 OneOrManyWithParens::Many(ps) => write!(f, "{}", display_comma_separated(ps))?,
1457 };
1458 write!(f, " : {}", self.body)
1459 }
1460 }
1461 }
1462}
1463
1464#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1466#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1467#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1468pub struct LambdaFunctionParameter {
1469 pub name: Ident,
1471 pub data_type: Option<DataType>,
1474}
1475
1476impl fmt::Display for LambdaFunctionParameter {
1477 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1478 match &self.data_type {
1479 Some(dt) => write!(f, "{} {}", self.name, dt),
1480 None => write!(f, "{}", self.name),
1481 }
1482 }
1483}
1484
1485#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy)]
1487#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1488#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1489pub enum LambdaSyntax {
1490 Arrow,
1497 LambdaKeyword,
1502}
1503
1504#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1527#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1528#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1529pub enum OneOrManyWithParens<T> {
1530 One(T),
1532 Many(Vec<T>),
1534}
1535
1536impl<T> Deref for OneOrManyWithParens<T> {
1537 type Target = [T];
1538
1539 fn deref(&self) -> &[T] {
1540 match self {
1541 OneOrManyWithParens::One(one) => core::slice::from_ref(one),
1542 OneOrManyWithParens::Many(many) => many,
1543 }
1544 }
1545}
1546
1547impl<T> AsRef<[T]> for OneOrManyWithParens<T> {
1548 fn as_ref(&self) -> &[T] {
1549 self
1550 }
1551}
1552
1553impl<'a, T> IntoIterator for &'a OneOrManyWithParens<T> {
1554 type Item = &'a T;
1555 type IntoIter = core::slice::Iter<'a, T>;
1556
1557 fn into_iter(self) -> Self::IntoIter {
1558 self.iter()
1559 }
1560}
1561
1562#[derive(Debug, Clone)]
1564pub struct OneOrManyWithParensIntoIter<T> {
1565 inner: OneOrManyWithParensIntoIterInner<T>,
1566}
1567
1568#[derive(Debug, Clone)]
1569enum OneOrManyWithParensIntoIterInner<T> {
1570 One(core::iter::Once<T>),
1571 Many(<Vec<T> as IntoIterator>::IntoIter),
1572}
1573
1574impl<T> core::iter::FusedIterator for OneOrManyWithParensIntoIter<T>
1575where
1576 core::iter::Once<T>: core::iter::FusedIterator,
1577 <Vec<T> as IntoIterator>::IntoIter: core::iter::FusedIterator,
1578{
1579}
1580
1581impl<T> core::iter::ExactSizeIterator for OneOrManyWithParensIntoIter<T>
1582where
1583 core::iter::Once<T>: core::iter::ExactSizeIterator,
1584 <Vec<T> as IntoIterator>::IntoIter: core::iter::ExactSizeIterator,
1585{
1586}
1587
1588impl<T> core::iter::Iterator for OneOrManyWithParensIntoIter<T> {
1589 type Item = T;
1590
1591 fn next(&mut self) -> Option<Self::Item> {
1592 match &mut self.inner {
1593 OneOrManyWithParensIntoIterInner::One(one) => one.next(),
1594 OneOrManyWithParensIntoIterInner::Many(many) => many.next(),
1595 }
1596 }
1597
1598 fn size_hint(&self) -> (usize, Option<usize>) {
1599 match &self.inner {
1600 OneOrManyWithParensIntoIterInner::One(one) => one.size_hint(),
1601 OneOrManyWithParensIntoIterInner::Many(many) => many.size_hint(),
1602 }
1603 }
1604
1605 fn count(self) -> usize
1606 where
1607 Self: Sized,
1608 {
1609 match self.inner {
1610 OneOrManyWithParensIntoIterInner::One(one) => one.count(),
1611 OneOrManyWithParensIntoIterInner::Many(many) => many.count(),
1612 }
1613 }
1614
1615 fn fold<B, F>(mut self, init: B, f: F) -> B
1616 where
1617 Self: Sized,
1618 F: FnMut(B, Self::Item) -> B,
1619 {
1620 match &mut self.inner {
1621 OneOrManyWithParensIntoIterInner::One(one) => one.fold(init, f),
1622 OneOrManyWithParensIntoIterInner::Many(many) => many.fold(init, f),
1623 }
1624 }
1625}
1626
1627impl<T> core::iter::DoubleEndedIterator for OneOrManyWithParensIntoIter<T> {
1628 fn next_back(&mut self) -> Option<Self::Item> {
1629 match &mut self.inner {
1630 OneOrManyWithParensIntoIterInner::One(one) => one.next_back(),
1631 OneOrManyWithParensIntoIterInner::Many(many) => many.next_back(),
1632 }
1633 }
1634}
1635
1636impl<T> IntoIterator for OneOrManyWithParens<T> {
1637 type Item = T;
1638
1639 type IntoIter = OneOrManyWithParensIntoIter<T>;
1640
1641 fn into_iter(self) -> Self::IntoIter {
1642 let inner = match self {
1643 OneOrManyWithParens::One(one) => {
1644 OneOrManyWithParensIntoIterInner::One(core::iter::once(one))
1645 }
1646 OneOrManyWithParens::Many(many) => {
1647 OneOrManyWithParensIntoIterInner::Many(many.into_iter())
1648 }
1649 };
1650
1651 OneOrManyWithParensIntoIter { inner }
1652 }
1653}
1654
1655impl<T> fmt::Display for OneOrManyWithParens<T>
1656where
1657 T: fmt::Display,
1658{
1659 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1660 match self {
1661 OneOrManyWithParens::One(value) => write!(f, "{value}"),
1662 OneOrManyWithParens::Many(values) => {
1663 write!(f, "({})", display_comma_separated(values))
1664 }
1665 }
1666 }
1667}
1668
1669impl fmt::Display for CastFormat {
1670 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1671 match self {
1672 CastFormat::Value(v) => write!(f, "{v}"),
1673 CastFormat::ValueAtTimeZone(v, tz) => write!(f, "{v} AT TIME ZONE {tz}"),
1674 }
1675 }
1676}
1677
1678impl fmt::Display for Expr {
1679 #[cfg_attr(feature = "recursive-protection", recursive::recursive)]
1680 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1681 match self {
1682 Expr::Identifier(s) => write!(f, "{s}"),
1683 Expr::Wildcard(_) => f.write_str("*"),
1684 Expr::QualifiedWildcard(prefix, _) => write!(f, "{prefix}.*"),
1685 Expr::CompoundIdentifier(s) => write!(f, "{}", display_separated(s, ".")),
1686 Expr::CompoundFieldAccess { root, access_chain } => {
1687 write!(f, "{root}")?;
1688 for field in access_chain {
1689 write!(f, "{field}")?;
1690 }
1691 Ok(())
1692 }
1693 Expr::IsTrue(ast) => write!(f, "{ast} IS TRUE"),
1694 Expr::IsNotTrue(ast) => write!(f, "{ast} IS NOT TRUE"),
1695 Expr::IsFalse(ast) => write!(f, "{ast} IS FALSE"),
1696 Expr::IsNotFalse(ast) => write!(f, "{ast} IS NOT FALSE"),
1697 Expr::IsNull(ast) => write!(f, "{ast} IS NULL"),
1698 Expr::IsNotNull(ast) => write!(f, "{ast} IS NOT NULL"),
1699 Expr::IsUnknown(ast) => write!(f, "{ast} IS UNKNOWN"),
1700 Expr::IsNotUnknown(ast) => write!(f, "{ast} IS NOT UNKNOWN"),
1701 Expr::InList {
1702 expr,
1703 list,
1704 negated,
1705 } => write!(
1706 f,
1707 "{} {}IN ({})",
1708 expr,
1709 if *negated { "NOT " } else { "" },
1710 display_comma_separated(list)
1711 ),
1712 Expr::InSubquery {
1713 expr,
1714 subquery,
1715 negated,
1716 } => write!(
1717 f,
1718 "{} {}IN ({})",
1719 expr,
1720 if *negated { "NOT " } else { "" },
1721 subquery
1722 ),
1723 Expr::InUnnest {
1724 expr,
1725 array_expr,
1726 negated,
1727 } => write!(
1728 f,
1729 "{} {}IN UNNEST({})",
1730 expr,
1731 if *negated { "NOT " } else { "" },
1732 array_expr
1733 ),
1734 Expr::Between {
1735 expr,
1736 negated,
1737 low,
1738 high,
1739 } => write!(
1740 f,
1741 "{} {}BETWEEN {} AND {}",
1742 expr,
1743 if *negated { "NOT " } else { "" },
1744 low,
1745 high
1746 ),
1747 Expr::BinaryOp { left, op, right } => write!(f, "{left} {op} {right}"),
1748 Expr::Like {
1749 negated,
1750 expr,
1751 pattern,
1752 escape_char,
1753 any,
1754 } => match escape_char {
1755 Some(ch) => write!(
1756 f,
1757 "{} {}LIKE {}{} ESCAPE {}",
1758 expr,
1759 if *negated { "NOT " } else { "" },
1760 if *any { "ANY " } else { "" },
1761 pattern,
1762 ch
1763 ),
1764 _ => write!(
1765 f,
1766 "{} {}LIKE {}{}",
1767 expr,
1768 if *negated { "NOT " } else { "" },
1769 if *any { "ANY " } else { "" },
1770 pattern
1771 ),
1772 },
1773 Expr::ILike {
1774 negated,
1775 expr,
1776 pattern,
1777 escape_char,
1778 any,
1779 } => match escape_char {
1780 Some(ch) => write!(
1781 f,
1782 "{} {}ILIKE {}{} ESCAPE {}",
1783 expr,
1784 if *negated { "NOT " } else { "" },
1785 if *any { "ANY" } else { "" },
1786 pattern,
1787 ch
1788 ),
1789 _ => write!(
1790 f,
1791 "{} {}ILIKE {}{}",
1792 expr,
1793 if *negated { "NOT " } else { "" },
1794 if *any { "ANY " } else { "" },
1795 pattern
1796 ),
1797 },
1798 Expr::RLike {
1799 negated,
1800 expr,
1801 pattern,
1802 regexp,
1803 } => write!(
1804 f,
1805 "{} {}{} {}",
1806 expr,
1807 if *negated { "NOT " } else { "" },
1808 if *regexp { "REGEXP" } else { "RLIKE" },
1809 pattern
1810 ),
1811 Expr::IsNormalized {
1812 expr,
1813 form,
1814 negated,
1815 } => {
1816 let not_ = if *negated { "NOT " } else { "" };
1817 if form.is_none() {
1818 write!(f, "{expr} IS {not_}NORMALIZED")
1819 } else {
1820 write!(
1821 f,
1822 "{} IS {}{} NORMALIZED",
1823 expr,
1824 not_,
1825 form.as_ref().unwrap()
1826 )
1827 }
1828 }
1829 Expr::SimilarTo {
1830 negated,
1831 expr,
1832 pattern,
1833 escape_char,
1834 } => match escape_char {
1835 Some(ch) => write!(
1836 f,
1837 "{} {}SIMILAR TO {} ESCAPE {}",
1838 expr,
1839 if *negated { "NOT " } else { "" },
1840 pattern,
1841 ch
1842 ),
1843 _ => write!(
1844 f,
1845 "{} {}SIMILAR TO {}",
1846 expr,
1847 if *negated { "NOT " } else { "" },
1848 pattern
1849 ),
1850 },
1851 Expr::AnyOp {
1852 left,
1853 compare_op,
1854 right,
1855 is_some,
1856 } => {
1857 let add_parens = !matches!(right.as_ref(), Expr::Subquery(_));
1858 write!(
1859 f,
1860 "{left} {compare_op} {}{}{right}{}",
1861 if *is_some { "SOME" } else { "ANY" },
1862 if add_parens { "(" } else { "" },
1863 if add_parens { ")" } else { "" },
1864 )
1865 }
1866 Expr::AllOp {
1867 left,
1868 compare_op,
1869 right,
1870 } => {
1871 let add_parens = !matches!(right.as_ref(), Expr::Subquery(_));
1872 write!(
1873 f,
1874 "{left} {compare_op} ALL{}{right}{}",
1875 if add_parens { "(" } else { "" },
1876 if add_parens { ")" } else { "" },
1877 )
1878 }
1879 Expr::UnaryOp { op, expr } => {
1880 if op == &UnaryOperator::PGPostfixFactorial {
1881 write!(f, "{expr}{op}")
1882 } else if matches!(
1883 op,
1884 UnaryOperator::Not
1885 | UnaryOperator::Hash
1886 | UnaryOperator::AtDashAt
1887 | UnaryOperator::DoubleAt
1888 | UnaryOperator::QuestionDash
1889 | UnaryOperator::QuestionPipe
1890 ) {
1891 write!(f, "{op} {expr}")
1892 } else {
1893 write!(f, "{op}{expr}")
1894 }
1895 }
1896 Expr::Convert {
1897 is_try,
1898 expr,
1899 target_before_value,
1900 data_type,
1901 charset,
1902 styles,
1903 } => {
1904 write!(f, "{}CONVERT(", if *is_try { "TRY_" } else { "" })?;
1905 if let Some(data_type) = data_type {
1906 if let Some(charset) = charset {
1907 write!(f, "{expr}, {data_type} CHARACTER SET {charset}")
1908 } else if *target_before_value {
1909 write!(f, "{data_type}, {expr}")
1910 } else {
1911 write!(f, "{expr}, {data_type}")
1912 }
1913 } else if let Some(charset) = charset {
1914 write!(f, "{expr} USING {charset}")
1915 } else {
1916 write!(f, "{expr}") }?;
1918 if !styles.is_empty() {
1919 write!(f, ", {}", display_comma_separated(styles))?;
1920 }
1921 write!(f, ")")
1922 }
1923 Expr::Cast {
1924 kind,
1925 expr,
1926 data_type,
1927 array,
1928 format,
1929 } => match kind {
1930 CastKind::Cast => {
1931 write!(f, "CAST({expr} AS {data_type}")?;
1932 if *array {
1933 write!(f, " ARRAY")?;
1934 }
1935 if let Some(format) = format {
1936 write!(f, " FORMAT {format}")?;
1937 }
1938 write!(f, ")")
1939 }
1940 CastKind::TryCast => {
1941 if let Some(format) = format {
1942 write!(f, "TRY_CAST({expr} AS {data_type} FORMAT {format})")
1943 } else {
1944 write!(f, "TRY_CAST({expr} AS {data_type})")
1945 }
1946 }
1947 CastKind::SafeCast => {
1948 if let Some(format) = format {
1949 write!(f, "SAFE_CAST({expr} AS {data_type} FORMAT {format})")
1950 } else {
1951 write!(f, "SAFE_CAST({expr} AS {data_type})")
1952 }
1953 }
1954 CastKind::DoubleColon => {
1955 write!(f, "{expr}::{data_type}")
1956 }
1957 },
1958 Expr::Extract {
1959 field,
1960 syntax,
1961 expr,
1962 } => match syntax {
1963 ExtractSyntax::From => write!(f, "EXTRACT({field} FROM {expr})"),
1964 ExtractSyntax::Comma => write!(f, "EXTRACT({field}, {expr})"),
1965 },
1966 Expr::Ceil { expr, field } => match field {
1967 CeilFloorKind::DateTimeField(DateTimeField::NoDateTime) => {
1968 write!(f, "CEIL({expr})")
1969 }
1970 CeilFloorKind::DateTimeField(dt_field) => write!(f, "CEIL({expr} TO {dt_field})"),
1971 CeilFloorKind::Scale(s) => write!(f, "CEIL({expr}, {s})"),
1972 },
1973 Expr::Floor { expr, field } => match field {
1974 CeilFloorKind::DateTimeField(DateTimeField::NoDateTime) => {
1975 write!(f, "FLOOR({expr})")
1976 }
1977 CeilFloorKind::DateTimeField(dt_field) => write!(f, "FLOOR({expr} TO {dt_field})"),
1978 CeilFloorKind::Scale(s) => write!(f, "FLOOR({expr}, {s})"),
1979 },
1980 Expr::Position { expr, r#in } => write!(f, "POSITION({expr} IN {in})"),
1981 Expr::Collate { expr, collation } => write!(f, "{expr} COLLATE {collation}"),
1982 Expr::Nested(ast) => write!(f, "({ast})"),
1983 Expr::Value(v) => write!(f, "{v}"),
1984 Expr::Prefixed { prefix, value } => write!(f, "{prefix} {value}"),
1985 Expr::TypedString(ts) => ts.fmt(f),
1986 Expr::Function(fun) => fun.fmt(f),
1987 Expr::Case {
1988 case_token: _,
1989 end_token: _,
1990 operand,
1991 conditions,
1992 else_result,
1993 } => {
1994 f.write_str("CASE")?;
1995 if let Some(operand) = operand {
1996 f.write_str(" ")?;
1997 operand.fmt(f)?;
1998 }
1999 for when in conditions {
2000 SpaceOrNewline.fmt(f)?;
2001 Indent(when).fmt(f)?;
2002 }
2003 if let Some(else_result) = else_result {
2004 SpaceOrNewline.fmt(f)?;
2005 Indent("ELSE").fmt(f)?;
2006 SpaceOrNewline.fmt(f)?;
2007 Indent(Indent(else_result)).fmt(f)?;
2008 }
2009 SpaceOrNewline.fmt(f)?;
2010 f.write_str("END")
2011 }
2012 Expr::Exists { subquery, negated } => write!(
2013 f,
2014 "{}EXISTS ({})",
2015 if *negated { "NOT " } else { "" },
2016 subquery
2017 ),
2018 Expr::Subquery(s) => write!(f, "({s})"),
2019 Expr::GroupingSets(sets) => {
2020 write!(f, "GROUPING SETS (")?;
2021 let mut sep = "";
2022 for set in sets {
2023 write!(f, "{sep}")?;
2024 sep = ", ";
2025 write!(f, "({})", display_comma_separated(set))?;
2026 }
2027 write!(f, ")")
2028 }
2029 Expr::Cube(sets) => {
2030 write!(f, "CUBE (")?;
2031 let mut sep = "";
2032 for set in sets {
2033 write!(f, "{sep}")?;
2034 sep = ", ";
2035 if set.len() == 1 {
2036 write!(f, "{}", set[0])?;
2037 } else {
2038 write!(f, "({})", display_comma_separated(set))?;
2039 }
2040 }
2041 write!(f, ")")
2042 }
2043 Expr::Rollup(sets) => {
2044 write!(f, "ROLLUP (")?;
2045 let mut sep = "";
2046 for set in sets {
2047 write!(f, "{sep}")?;
2048 sep = ", ";
2049 if set.len() == 1 {
2050 write!(f, "{}", set[0])?;
2051 } else {
2052 write!(f, "({})", display_comma_separated(set))?;
2053 }
2054 }
2055 write!(f, ")")
2056 }
2057 Expr::Substring {
2058 expr,
2059 substring_from,
2060 substring_for,
2061 special,
2062 shorthand,
2063 } => {
2064 f.write_str("SUBSTR")?;
2065 if !*shorthand {
2066 f.write_str("ING")?;
2067 }
2068 write!(f, "({expr}")?;
2069 if let Some(from_part) = substring_from {
2070 if *special {
2071 write!(f, ", {from_part}")?;
2072 } else {
2073 write!(f, " FROM {from_part}")?;
2074 }
2075 }
2076 if let Some(for_part) = substring_for {
2077 if *special {
2078 write!(f, ", {for_part}")?;
2079 } else {
2080 write!(f, " FOR {for_part}")?;
2081 }
2082 }
2083
2084 write!(f, ")")
2085 }
2086 Expr::Overlay {
2087 expr,
2088 overlay_what,
2089 overlay_from,
2090 overlay_for,
2091 } => {
2092 write!(
2093 f,
2094 "OVERLAY({expr} PLACING {overlay_what} FROM {overlay_from}"
2095 )?;
2096 if let Some(for_part) = overlay_for {
2097 write!(f, " FOR {for_part}")?;
2098 }
2099
2100 write!(f, ")")
2101 }
2102 Expr::IsDistinctFrom(a, b) => write!(f, "{a} IS DISTINCT FROM {b}"),
2103 Expr::IsNotDistinctFrom(a, b) => write!(f, "{a} IS NOT DISTINCT FROM {b}"),
2104 Expr::Trim {
2105 expr,
2106 trim_where,
2107 trim_what,
2108 trim_characters,
2109 } => {
2110 write!(f, "TRIM(")?;
2111 if let Some(ident) = trim_where {
2112 write!(f, "{ident} ")?;
2113 }
2114 if let Some(trim_char) = trim_what {
2115 write!(f, "{trim_char} FROM {expr}")?;
2116 } else {
2117 write!(f, "{expr}")?;
2118 }
2119 if let Some(characters) = trim_characters {
2120 write!(f, ", {}", display_comma_separated(characters))?;
2121 }
2122
2123 write!(f, ")")
2124 }
2125 Expr::Tuple(exprs) => {
2126 write!(f, "({})", display_comma_separated(exprs))
2127 }
2128 Expr::Struct { values, fields } => {
2129 if !fields.is_empty() {
2130 write!(
2131 f,
2132 "STRUCT<{}>({})",
2133 display_comma_separated(fields),
2134 display_comma_separated(values)
2135 )
2136 } else {
2137 write!(f, "STRUCT({})", display_comma_separated(values))
2138 }
2139 }
2140 Expr::Named { expr, name } => {
2141 write!(f, "{expr} AS {name}")
2142 }
2143 Expr::Dictionary(fields) => {
2144 write!(f, "{{{}}}", display_comma_separated(fields))
2145 }
2146 Expr::Map(map) => {
2147 write!(f, "{map}")
2148 }
2149 Expr::Array(set) => {
2150 write!(f, "{set}")
2151 }
2152 Expr::JsonAccess { value, path } => {
2153 write!(f, "{value}{path}")
2154 }
2155 Expr::AtTimeZone {
2156 timestamp,
2157 time_zone,
2158 } => {
2159 write!(f, "{timestamp} AT TIME ZONE {time_zone}")
2160 }
2161 Expr::Interval(interval) => {
2162 write!(f, "{interval}")
2163 }
2164 Expr::MatchAgainst {
2165 columns,
2166 match_value: match_expr,
2167 opt_search_modifier,
2168 } => {
2169 write!(f, "MATCH ({}) AGAINST ", display_comma_separated(columns),)?;
2170
2171 if let Some(search_modifier) = opt_search_modifier {
2172 write!(f, "({match_expr} {search_modifier})")?;
2173 } else {
2174 write!(f, "({match_expr})")?;
2175 }
2176
2177 Ok(())
2178 }
2179 Expr::OuterJoin(expr) => {
2180 write!(f, "{expr} (+)")
2181 }
2182 Expr::Prior(expr) => write!(f, "PRIOR {expr}"),
2183 Expr::Lambda(lambda) => write!(f, "{lambda}"),
2184 Expr::MemberOf(member_of) => write!(f, "{member_of}"),
2185 }
2186 }
2187}
2188
2189#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2198#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2199#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2200pub enum WindowType {
2201 WindowSpec(WindowSpec),
2203 NamedWindow(Ident),
2205}
2206
2207impl Display for WindowType {
2208 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2209 match self {
2210 WindowType::WindowSpec(spec) => {
2211 f.write_str("(")?;
2212 NewLine.fmt(f)?;
2213 Indent(spec).fmt(f)?;
2214 NewLine.fmt(f)?;
2215 f.write_str(")")
2216 }
2217 WindowType::NamedWindow(name) => name.fmt(f),
2218 }
2219 }
2220}
2221
2222#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2224#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2225#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2226pub struct WindowSpec {
2227 pub window_name: Option<Ident>,
2235 pub partition_by: Vec<Expr>,
2237 pub order_by: Vec<OrderByExpr>,
2239 pub window_frame: Option<WindowFrame>,
2241}
2242
2243impl fmt::Display for WindowSpec {
2244 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2245 let mut is_first = true;
2246 if let Some(window_name) = &self.window_name {
2247 if !is_first {
2248 SpaceOrNewline.fmt(f)?;
2249 }
2250 is_first = false;
2251 write!(f, "{window_name}")?;
2252 }
2253 if !self.partition_by.is_empty() {
2254 if !is_first {
2255 SpaceOrNewline.fmt(f)?;
2256 }
2257 is_first = false;
2258 write!(
2259 f,
2260 "PARTITION BY {}",
2261 display_comma_separated(&self.partition_by)
2262 )?;
2263 }
2264 if !self.order_by.is_empty() {
2265 if !is_first {
2266 SpaceOrNewline.fmt(f)?;
2267 }
2268 is_first = false;
2269 write!(f, "ORDER BY {}", display_comma_separated(&self.order_by))?;
2270 }
2271 if let Some(window_frame) = &self.window_frame {
2272 if !is_first {
2273 SpaceOrNewline.fmt(f)?;
2274 }
2275 if let Some(end_bound) = &window_frame.end_bound {
2276 write!(
2277 f,
2278 "{} BETWEEN {} AND {}",
2279 window_frame.units, window_frame.start_bound, end_bound
2280 )?;
2281 } else {
2282 write!(f, "{} {}", window_frame.units, window_frame.start_bound)?;
2283 }
2284 }
2285 Ok(())
2286 }
2287}
2288
2289#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2295#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2296#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2297pub struct WindowFrame {
2298 pub units: WindowFrameUnits,
2300 pub start_bound: WindowFrameBound,
2302 pub end_bound: Option<WindowFrameBound>,
2306 }
2308
2309impl Default for WindowFrame {
2310 fn default() -> Self {
2314 Self {
2315 units: WindowFrameUnits::Range,
2316 start_bound: WindowFrameBound::Preceding(None),
2317 end_bound: None,
2318 }
2319 }
2320}
2321
2322#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2323#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2324#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2325pub enum WindowFrameUnits {
2327 Rows,
2329 Range,
2331 Groups,
2333}
2334
2335impl fmt::Display for WindowFrameUnits {
2336 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2337 f.write_str(match self {
2338 WindowFrameUnits::Rows => "ROWS",
2339 WindowFrameUnits::Range => "RANGE",
2340 WindowFrameUnits::Groups => "GROUPS",
2341 })
2342 }
2343}
2344
2345#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2349#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2350#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2351pub enum NullTreatment {
2353 IgnoreNulls,
2355 RespectNulls,
2357}
2358
2359impl fmt::Display for NullTreatment {
2360 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2361 f.write_str(match self {
2362 NullTreatment::IgnoreNulls => "IGNORE NULLS",
2363 NullTreatment::RespectNulls => "RESPECT NULLS",
2364 })
2365 }
2366}
2367
2368#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2370#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2371#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2372pub enum WindowFrameBound {
2373 CurrentRow,
2375 Preceding(Option<Box<Expr>>),
2377 Following(Option<Box<Expr>>),
2379}
2380
2381impl fmt::Display for WindowFrameBound {
2382 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2383 match self {
2384 WindowFrameBound::CurrentRow => f.write_str("CURRENT ROW"),
2385 WindowFrameBound::Preceding(None) => f.write_str("UNBOUNDED PRECEDING"),
2386 WindowFrameBound::Following(None) => f.write_str("UNBOUNDED FOLLOWING"),
2387 WindowFrameBound::Preceding(Some(n)) => write!(f, "{n} PRECEDING"),
2388 WindowFrameBound::Following(Some(n)) => write!(f, "{n} FOLLOWING"),
2389 }
2390 }
2391}
2392
2393#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2394#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2395#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2396pub enum AddDropSync {
2398 ADD,
2400 DROP,
2402 SYNC,
2404}
2405
2406impl fmt::Display for AddDropSync {
2407 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2408 match self {
2409 AddDropSync::SYNC => f.write_str("SYNC PARTITIONS"),
2410 AddDropSync::DROP => f.write_str("DROP PARTITIONS"),
2411 AddDropSync::ADD => f.write_str("ADD PARTITIONS"),
2412 }
2413 }
2414}
2415
2416#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2417#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2418#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2419pub enum ShowCreateObject {
2421 Event,
2423 Function,
2425 Procedure,
2427 Table,
2429 Trigger,
2431 View,
2433}
2434
2435impl fmt::Display for ShowCreateObject {
2436 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2437 match self {
2438 ShowCreateObject::Event => f.write_str("EVENT"),
2439 ShowCreateObject::Function => f.write_str("FUNCTION"),
2440 ShowCreateObject::Procedure => f.write_str("PROCEDURE"),
2441 ShowCreateObject::Table => f.write_str("TABLE"),
2442 ShowCreateObject::Trigger => f.write_str("TRIGGER"),
2443 ShowCreateObject::View => f.write_str("VIEW"),
2444 }
2445 }
2446}
2447
2448#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2449#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2450#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2451pub enum CommentObject {
2453 Collation,
2455 Column,
2457 Database,
2459 Domain,
2461 Extension,
2463 Function,
2465 Index,
2467 MaterializedView,
2469 Procedure,
2471 Role,
2473 Schema,
2475 Sequence,
2477 Table,
2479 Type,
2481 User,
2483 View,
2485}
2486
2487impl fmt::Display for CommentObject {
2488 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2489 match self {
2490 CommentObject::Collation => f.write_str("COLLATION"),
2491 CommentObject::Column => f.write_str("COLUMN"),
2492 CommentObject::Database => f.write_str("DATABASE"),
2493 CommentObject::Domain => f.write_str("DOMAIN"),
2494 CommentObject::Extension => f.write_str("EXTENSION"),
2495 CommentObject::Function => f.write_str("FUNCTION"),
2496 CommentObject::Index => f.write_str("INDEX"),
2497 CommentObject::MaterializedView => f.write_str("MATERIALIZED VIEW"),
2498 CommentObject::Procedure => f.write_str("PROCEDURE"),
2499 CommentObject::Role => f.write_str("ROLE"),
2500 CommentObject::Schema => f.write_str("SCHEMA"),
2501 CommentObject::Sequence => f.write_str("SEQUENCE"),
2502 CommentObject::Table => f.write_str("TABLE"),
2503 CommentObject::Type => f.write_str("TYPE"),
2504 CommentObject::User => f.write_str("USER"),
2505 CommentObject::View => f.write_str("VIEW"),
2506 }
2507 }
2508}
2509
2510#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2511#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2512#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2513pub enum Password {
2515 Password(Expr),
2517 NullPassword,
2519}
2520
2521#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2538#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2539#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2540pub struct CaseStatement {
2541 pub case_token: AttachedToken,
2543 pub match_expr: Option<Expr>,
2545 pub when_blocks: Vec<ConditionalStatementBlock>,
2547 pub else_block: Option<ConditionalStatementBlock>,
2549 pub end_case_token: AttachedToken,
2551}
2552
2553impl fmt::Display for CaseStatement {
2554 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2555 let CaseStatement {
2556 case_token: _,
2557 match_expr,
2558 when_blocks,
2559 else_block,
2560 end_case_token: AttachedToken(end),
2561 } = self;
2562
2563 write!(f, "CASE")?;
2564
2565 if let Some(expr) = match_expr {
2566 write!(f, " {expr}")?;
2567 }
2568
2569 if !when_blocks.is_empty() {
2570 write!(f, " {}", display_separated(when_blocks, " "))?;
2571 }
2572
2573 if let Some(else_block) = else_block {
2574 write!(f, " {else_block}")?;
2575 }
2576
2577 write!(f, " END")?;
2578
2579 if let Token::Word(w) = &end.token {
2580 if w.keyword == Keyword::CASE {
2581 write!(f, " CASE")?;
2582 }
2583 }
2584
2585 Ok(())
2586 }
2587}
2588
2589#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2611#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2612#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2613pub struct IfStatement {
2614 pub if_block: ConditionalStatementBlock,
2616 pub elseif_blocks: Vec<ConditionalStatementBlock>,
2618 pub else_block: Option<ConditionalStatementBlock>,
2620 pub end_token: Option<AttachedToken>,
2622}
2623
2624impl fmt::Display for IfStatement {
2625 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2626 let IfStatement {
2627 if_block,
2628 elseif_blocks,
2629 else_block,
2630 end_token,
2631 } = self;
2632
2633 write!(f, "{if_block}")?;
2634
2635 for elseif_block in elseif_blocks {
2636 write!(f, " {elseif_block}")?;
2637 }
2638
2639 if let Some(else_block) = else_block {
2640 write!(f, " {else_block}")?;
2641 }
2642
2643 if let Some(AttachedToken(end_token)) = end_token {
2644 write!(f, " END {end_token}")?;
2645 }
2646
2647 Ok(())
2648 }
2649}
2650
2651#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2663#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2664#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2665pub struct WhileStatement {
2666 pub while_block: ConditionalStatementBlock,
2668}
2669
2670impl fmt::Display for WhileStatement {
2671 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2672 let WhileStatement { while_block } = self;
2673 write!(f, "{while_block}")?;
2674 Ok(())
2675 }
2676}
2677
2678#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2703#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2704#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2705pub struct ConditionalStatementBlock {
2706 pub start_token: AttachedToken,
2708 pub condition: Option<Expr>,
2710 pub then_token: Option<AttachedToken>,
2712 pub conditional_statements: ConditionalStatements,
2714}
2715
2716impl ConditionalStatementBlock {
2717 pub fn statements(&self) -> &Vec<Statement> {
2719 self.conditional_statements.statements()
2720 }
2721}
2722
2723impl fmt::Display for ConditionalStatementBlock {
2724 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2725 let ConditionalStatementBlock {
2726 start_token: AttachedToken(start_token),
2727 condition,
2728 then_token,
2729 conditional_statements,
2730 } = self;
2731
2732 write!(f, "{start_token}")?;
2733
2734 if let Some(condition) = condition {
2735 write!(f, " {condition}")?;
2736 }
2737
2738 if then_token.is_some() {
2739 write!(f, " THEN")?;
2740 }
2741
2742 if !conditional_statements.statements().is_empty() {
2743 write!(f, " {conditional_statements}")?;
2744 }
2745
2746 Ok(())
2747 }
2748}
2749
2750#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2752#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2753#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2754pub enum ConditionalStatements {
2756 Sequence {
2758 statements: Vec<Statement>,
2760 },
2761 BeginEnd(BeginEndStatements),
2763}
2764
2765impl ConditionalStatements {
2766 pub fn statements(&self) -> &Vec<Statement> {
2768 match self {
2769 ConditionalStatements::Sequence { statements } => statements,
2770 ConditionalStatements::BeginEnd(bes) => &bes.statements,
2771 }
2772 }
2773}
2774
2775impl fmt::Display for ConditionalStatements {
2776 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2777 match self {
2778 ConditionalStatements::Sequence { statements } => {
2779 if !statements.is_empty() {
2780 format_statement_list(f, statements)?;
2781 }
2782 Ok(())
2783 }
2784 ConditionalStatements::BeginEnd(bes) => write!(f, "{bes}"),
2785 }
2786 }
2787}
2788
2789#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2798#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2799#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2800pub struct BeginEndStatements {
2801 pub begin_token: AttachedToken,
2803 pub statements: Vec<Statement>,
2805 pub end_token: AttachedToken,
2807}
2808
2809impl fmt::Display for BeginEndStatements {
2810 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2811 let BeginEndStatements {
2812 begin_token: AttachedToken(begin_token),
2813 statements,
2814 end_token: AttachedToken(end_token),
2815 } = self;
2816
2817 if begin_token.token != Token::EOF {
2818 write!(f, "{begin_token} ")?;
2819 }
2820 if !statements.is_empty() {
2821 format_statement_list(f, statements)?;
2822 }
2823 if end_token.token != Token::EOF {
2824 write!(f, " {end_token}")?;
2825 }
2826 Ok(())
2827 }
2828}
2829
2830#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2842#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2843#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2844pub struct RaiseStatement {
2845 pub value: Option<RaiseStatementValue>,
2847}
2848
2849impl fmt::Display for RaiseStatement {
2850 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2851 let RaiseStatement { value } = self;
2852
2853 write!(f, "RAISE")?;
2854 if let Some(value) = value {
2855 write!(f, " {value}")?;
2856 }
2857
2858 Ok(())
2859 }
2860}
2861
2862#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2864#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2865#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2866pub enum RaiseStatementValue {
2867 UsingMessage(Expr),
2869 Expr(Expr),
2871}
2872
2873impl fmt::Display for RaiseStatementValue {
2874 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2875 match self {
2876 RaiseStatementValue::Expr(expr) => write!(f, "{expr}"),
2877 RaiseStatementValue::UsingMessage(expr) => write!(f, "USING MESSAGE = {expr}"),
2878 }
2879 }
2880}
2881
2882#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2890#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2891#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2892pub struct ThrowStatement {
2893 pub error_number: Option<Box<Expr>>,
2895 pub message: Option<Box<Expr>>,
2897 pub state: Option<Box<Expr>>,
2899}
2900
2901impl fmt::Display for ThrowStatement {
2902 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2903 let ThrowStatement {
2904 error_number,
2905 message,
2906 state,
2907 } = self;
2908
2909 write!(f, "THROW")?;
2910 if let (Some(error_number), Some(message), Some(state)) = (error_number, message, state) {
2911 write!(f, " {error_number}, {message}, {state}")?;
2912 }
2913 Ok(())
2914 }
2915}
2916
2917#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2925#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2926#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2927pub enum DeclareAssignment {
2928 Expr(Box<Expr>),
2930
2931 Default(Box<Expr>),
2933
2934 DuckAssignment(Box<Expr>),
2941
2942 For(Box<Expr>),
2949
2950 MsSqlAssignment(Box<Expr>),
2957}
2958
2959impl fmt::Display for DeclareAssignment {
2960 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2961 match self {
2962 DeclareAssignment::Expr(expr) => {
2963 write!(f, "{expr}")
2964 }
2965 DeclareAssignment::Default(expr) => {
2966 write!(f, "DEFAULT {expr}")
2967 }
2968 DeclareAssignment::DuckAssignment(expr) => {
2969 write!(f, ":= {expr}")
2970 }
2971 DeclareAssignment::MsSqlAssignment(expr) => {
2972 write!(f, "= {expr}")
2973 }
2974 DeclareAssignment::For(expr) => {
2975 write!(f, "FOR {expr}")
2976 }
2977 }
2978 }
2979}
2980
2981#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2983#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2984#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2985pub enum DeclareType {
2986 Cursor,
2992
2993 ResultSet,
3001
3002 Exception,
3010}
3011
3012impl fmt::Display for DeclareType {
3013 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3014 match self {
3015 DeclareType::Cursor => {
3016 write!(f, "CURSOR")
3017 }
3018 DeclareType::ResultSet => {
3019 write!(f, "RESULTSET")
3020 }
3021 DeclareType::Exception => {
3022 write!(f, "EXCEPTION")
3023 }
3024 }
3025 }
3026}
3027
3028#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3041#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3042#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3043pub struct Declare {
3044 pub names: Vec<Ident>,
3047 pub data_type: Option<DataType>,
3050 pub assignment: Option<DeclareAssignment>,
3052 pub declare_type: Option<DeclareType>,
3054 pub binary: Option<bool>,
3056 pub sensitive: Option<bool>,
3060 pub scroll: Option<bool>,
3064 pub hold: Option<bool>,
3068 pub for_query: Option<Box<Query>>,
3070}
3071
3072impl fmt::Display for Declare {
3073 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3074 let Declare {
3075 names,
3076 data_type,
3077 assignment,
3078 declare_type,
3079 binary,
3080 sensitive,
3081 scroll,
3082 hold,
3083 for_query,
3084 } = self;
3085 write!(f, "{}", display_comma_separated(names))?;
3086
3087 if let Some(true) = binary {
3088 write!(f, " BINARY")?;
3089 }
3090
3091 if let Some(sensitive) = sensitive {
3092 if *sensitive {
3093 write!(f, " INSENSITIVE")?;
3094 } else {
3095 write!(f, " ASENSITIVE")?;
3096 }
3097 }
3098
3099 if let Some(scroll) = scroll {
3100 if *scroll {
3101 write!(f, " SCROLL")?;
3102 } else {
3103 write!(f, " NO SCROLL")?;
3104 }
3105 }
3106
3107 if let Some(declare_type) = declare_type {
3108 write!(f, " {declare_type}")?;
3109 }
3110
3111 if let Some(hold) = hold {
3112 if *hold {
3113 write!(f, " WITH HOLD")?;
3114 } else {
3115 write!(f, " WITHOUT HOLD")?;
3116 }
3117 }
3118
3119 if let Some(query) = for_query {
3120 write!(f, " FOR {query}")?;
3121 }
3122
3123 if let Some(data_type) = data_type {
3124 write!(f, " {data_type}")?;
3125 }
3126
3127 if let Some(expr) = assignment {
3128 write!(f, " {expr}")?;
3129 }
3130 Ok(())
3131 }
3132}
3133
3134#[derive(Debug, Default, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3136#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3137#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3138pub enum CreateTableOptions {
3140 #[default]
3142 None,
3143 With(Vec<SqlOption>),
3145 Options(Vec<SqlOption>),
3147 Plain(Vec<SqlOption>),
3149 TableProperties(Vec<SqlOption>),
3151}
3152
3153impl fmt::Display for CreateTableOptions {
3154 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3155 match self {
3156 CreateTableOptions::With(with_options) => {
3157 write!(f, "WITH ({})", display_comma_separated(with_options))
3158 }
3159 CreateTableOptions::Options(options) => {
3160 write!(f, "OPTIONS({})", display_comma_separated(options))
3161 }
3162 CreateTableOptions::TableProperties(options) => {
3163 write!(f, "TBLPROPERTIES ({})", display_comma_separated(options))
3164 }
3165 CreateTableOptions::Plain(options) => {
3166 write!(f, "{}", display_separated(options, " "))
3167 }
3168 CreateTableOptions::None => Ok(()),
3169 }
3170 }
3171}
3172
3173#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3180#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3181#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3182pub enum FromTable {
3183 WithFromKeyword(Vec<TableWithJoins>),
3185 WithoutKeyword(Vec<TableWithJoins>),
3188}
3189impl Display for FromTable {
3190 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3191 match self {
3192 FromTable::WithFromKeyword(tables) => {
3193 write!(f, "FROM {}", display_comma_separated(tables))
3194 }
3195 FromTable::WithoutKeyword(tables) => {
3196 write!(f, "{}", display_comma_separated(tables))
3197 }
3198 }
3199 }
3200}
3201
3202#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3203#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3204#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3205pub enum Set {
3207 SingleAssignment {
3211 scope: Option<ContextModifier>,
3213 hivevar: bool,
3215 variable: ObjectName,
3217 values: Vec<Expr>,
3219 },
3220 ParenthesizedAssignments {
3224 variables: Vec<ObjectName>,
3226 values: Vec<Expr>,
3228 },
3229 MultipleAssignments {
3233 assignments: Vec<SetAssignment>,
3235 },
3236 SetSessionAuthorization(SetSessionAuthorizationParam),
3245 SetSessionParam(SetSessionParamKind),
3249 SetRole {
3260 context_modifier: Option<ContextModifier>,
3262 role_name: Option<Ident>,
3264 },
3265 SetTimeZone {
3275 local: bool,
3277 value: Expr,
3279 },
3280 SetNames {
3284 charset_name: Ident,
3286 collation_name: Option<String>,
3288 },
3289 SetNamesDefault {},
3295 SetTransaction {
3299 modes: Vec<TransactionMode>,
3301 snapshot: Option<ValueWithSpan>,
3303 session: bool,
3305 },
3306}
3307
3308impl Display for Set {
3309 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3310 match self {
3311 Self::ParenthesizedAssignments { variables, values } => write!(
3312 f,
3313 "SET ({}) = ({})",
3314 display_comma_separated(variables),
3315 display_comma_separated(values)
3316 ),
3317 Self::MultipleAssignments { assignments } => {
3318 write!(f, "SET {}", display_comma_separated(assignments))
3319 }
3320 Self::SetRole {
3321 context_modifier,
3322 role_name,
3323 } => {
3324 let role_name = role_name.clone().unwrap_or_else(|| Ident::new("NONE"));
3325 write!(
3326 f,
3327 "SET {modifier}ROLE {role_name}",
3328 modifier = context_modifier.map(|m| format!("{m}")).unwrap_or_default()
3329 )
3330 }
3331 Self::SetSessionAuthorization(kind) => write!(f, "SET SESSION AUTHORIZATION {kind}"),
3332 Self::SetSessionParam(kind) => write!(f, "SET {kind}"),
3333 Self::SetTransaction {
3334 modes,
3335 snapshot,
3336 session,
3337 } => {
3338 if *session {
3339 write!(f, "SET SESSION CHARACTERISTICS AS TRANSACTION")?;
3340 } else {
3341 write!(f, "SET TRANSACTION")?;
3342 }
3343 if !modes.is_empty() {
3344 write!(f, " {}", display_comma_separated(modes))?;
3345 }
3346 if let Some(snapshot_id) = snapshot {
3347 write!(f, " SNAPSHOT {snapshot_id}")?;
3348 }
3349 Ok(())
3350 }
3351 Self::SetTimeZone { local, value } => {
3352 f.write_str("SET ")?;
3353 if *local {
3354 f.write_str("LOCAL ")?;
3355 }
3356 write!(f, "TIME ZONE {value}")
3357 }
3358 Self::SetNames {
3359 charset_name,
3360 collation_name,
3361 } => {
3362 write!(f, "SET NAMES {charset_name}")?;
3363
3364 if let Some(collation) = collation_name {
3365 f.write_str(" COLLATE ")?;
3366 f.write_str(collation)?;
3367 };
3368
3369 Ok(())
3370 }
3371 Self::SetNamesDefault {} => {
3372 f.write_str("SET NAMES DEFAULT")?;
3373
3374 Ok(())
3375 }
3376 Set::SingleAssignment {
3377 scope,
3378 hivevar,
3379 variable,
3380 values,
3381 } => {
3382 write!(
3383 f,
3384 "SET {}{}{} = {}",
3385 scope.map(|s| format!("{s}")).unwrap_or_default(),
3386 if *hivevar { "HIVEVAR:" } else { "" },
3387 variable,
3388 display_comma_separated(values)
3389 )
3390 }
3391 }
3392 }
3393}
3394
3395#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3401#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3402#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3403pub struct ExceptionWhen {
3404 pub idents: Vec<Ident>,
3406 pub statements: Vec<Statement>,
3408}
3409
3410impl Display for ExceptionWhen {
3411 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3412 write!(
3413 f,
3414 "WHEN {idents} THEN",
3415 idents = display_separated(&self.idents, " OR ")
3416 )?;
3417
3418 if !self.statements.is_empty() {
3419 write!(f, " ")?;
3420 format_statement_list(f, &self.statements)?;
3421 }
3422
3423 Ok(())
3424 }
3425}
3426
3427#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3434#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3435#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3436pub struct Analyze {
3437 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3438 pub table_name: Option<ObjectName>,
3440 pub partitions: Option<Vec<Expr>>,
3442 pub for_columns: bool,
3444 pub columns: Vec<Ident>,
3446 pub cache_metadata: bool,
3448 pub noscan: bool,
3450 pub compute_statistics: bool,
3452 pub has_table_keyword: bool,
3454}
3455
3456impl fmt::Display for Analyze {
3457 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3458 write!(f, "ANALYZE")?;
3459 if let Some(ref table_name) = self.table_name {
3460 if self.has_table_keyword {
3461 write!(f, " TABLE")?;
3462 }
3463 write!(f, " {table_name}")?;
3464 }
3465 if !self.for_columns && !self.columns.is_empty() {
3466 write!(f, " ({})", display_comma_separated(&self.columns))?;
3467 }
3468 if let Some(ref parts) = self.partitions {
3469 if !parts.is_empty() {
3470 write!(f, " PARTITION ({})", display_comma_separated(parts))?;
3471 }
3472 }
3473 if self.compute_statistics {
3474 write!(f, " COMPUTE STATISTICS")?;
3475 }
3476 if self.noscan {
3477 write!(f, " NOSCAN")?;
3478 }
3479 if self.cache_metadata {
3480 write!(f, " CACHE METADATA")?;
3481 }
3482 if self.for_columns {
3483 write!(f, " FOR COLUMNS")?;
3484 if !self.columns.is_empty() {
3485 write!(f, " {}", display_comma_separated(&self.columns))?;
3486 }
3487 }
3488 Ok(())
3489 }
3490}
3491
3492#[allow(clippy::large_enum_variant)]
3494#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3495#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3496#[cfg_attr(
3497 feature = "visitor",
3498 derive(Visit, VisitMut),
3499 visit(with = "visit_statement")
3500)]
3501pub enum Statement {
3502 Analyze(Analyze),
3507 Set(Set),
3509 Truncate(Truncate),
3514 Msck(Msck),
3519 Query(Box<Query>),
3523 Insert(Insert),
3527 Install {
3531 extension_name: Ident,
3533 },
3534 Load {
3538 extension_name: Ident,
3540 },
3541 Directory {
3544 overwrite: bool,
3546 local: bool,
3548 path: String,
3550 file_format: Option<FileFormat>,
3552 source: Box<Query>,
3554 },
3555 Case(CaseStatement),
3557 If(IfStatement),
3559 While(WhileStatement),
3561 Raise(RaiseStatement),
3563 Call(Function),
3567 Copy {
3571 source: CopySource,
3573 to: bool,
3575 target: CopyTarget,
3577 options: Vec<CopyOption>,
3579 legacy_options: Vec<CopyLegacyOption>,
3581 values: Vec<Option<String>>,
3583 },
3584 CopyIntoSnowflake {
3596 kind: CopyIntoSnowflakeKind,
3598 into: ObjectName,
3600 into_columns: Option<Vec<Ident>>,
3602 from_obj: Option<ObjectName>,
3604 from_obj_alias: Option<Ident>,
3606 stage_params: StageParamsObject,
3608 from_transformations: Option<Vec<StageLoadSelectItemKind>>,
3610 from_query: Option<Box<Query>>,
3612 files: Option<Vec<String>>,
3614 pattern: Option<String>,
3616 file_format: KeyValueOptions,
3618 copy_options: KeyValueOptions,
3620 validation_mode: Option<String>,
3622 partition: Option<Box<Expr>>,
3624 },
3625 Open(OpenStatement),
3630 Close {
3635 cursor: CloseCursor,
3637 },
3638 Update(Update),
3642 Delete(Delete),
3646 CreateView(CreateView),
3650 CreateTable(CreateTable),
3654 CreateVirtualTable {
3659 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3660 name: ObjectName,
3662 if_not_exists: bool,
3664 module_name: Ident,
3666 module_args: Vec<Ident>,
3668 },
3669 CreateIndex(CreateIndex),
3673 CreateRole(CreateRole),
3678 CreateSecret {
3683 or_replace: bool,
3685 temporary: Option<bool>,
3687 if_not_exists: bool,
3689 name: Option<Ident>,
3691 storage_specifier: Option<Ident>,
3693 secret_type: Ident,
3695 options: Vec<SecretOption>,
3697 },
3698 CreateServer(CreateServerStatement),
3700 CreatePolicy(CreatePolicy),
3705 CreateConnector(CreateConnector),
3710 CreateOperator(CreateOperator),
3715 CreateOperatorFamily(CreateOperatorFamily),
3720 CreateOperatorClass(CreateOperatorClass),
3725 AlterTable(AlterTable),
3729 AlterSchema(AlterSchema),
3734 AlterIndex {
3738 name: ObjectName,
3740 operation: AlterIndexOperation,
3742 },
3743 AlterView {
3747 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3749 name: ObjectName,
3750 columns: Vec<Ident>,
3752 query: Box<Query>,
3754 with_options: Vec<SqlOption>,
3756 },
3757 AlterFunction(AlterFunction),
3764 AlterType(AlterType),
3769 AlterCollation(AlterCollation),
3774 AlterOperator(AlterOperator),
3779 AlterOperatorFamily(AlterOperatorFamily),
3784 AlterOperatorClass(AlterOperatorClass),
3789 AlterRole {
3793 name: Ident,
3795 operation: AlterRoleOperation,
3797 },
3798 AlterPolicy(AlterPolicy),
3803 AlterConnector {
3812 name: Ident,
3814 properties: Option<Vec<SqlOption>>,
3816 url: Option<String>,
3818 owner: Option<ddl::AlterConnectorOwner>,
3820 },
3821 AlterSession {
3827 set: bool,
3829 session_params: KeyValueOptions,
3831 },
3832 AttachDatabase {
3837 schema_name: Ident,
3839 database_file_name: Expr,
3841 database: bool,
3843 },
3844 AttachDuckDBDatabase {
3850 if_not_exists: bool,
3852 database: bool,
3854 database_path: Ident,
3856 database_alias: Option<Ident>,
3858 attach_options: Vec<AttachDuckDBDatabaseOption>,
3860 },
3861 DetachDuckDBDatabase {
3867 if_exists: bool,
3869 database: bool,
3871 database_alias: Ident,
3873 },
3874 Drop {
3878 object_type: ObjectType,
3880 if_exists: bool,
3882 names: Vec<ObjectName>,
3884 cascade: bool,
3887 restrict: bool,
3890 purge: bool,
3893 temporary: bool,
3895 table: Option<ObjectName>,
3898 },
3899 DropFunction(DropFunction),
3903 DropDomain(DropDomain),
3911 DropProcedure {
3915 if_exists: bool,
3917 proc_desc: Vec<FunctionDesc>,
3919 drop_behavior: Option<DropBehavior>,
3921 },
3922 DropSecret {
3926 if_exists: bool,
3928 temporary: Option<bool>,
3930 name: Ident,
3932 storage_specifier: Option<Ident>,
3934 },
3935 DropPolicy(DropPolicy),
3940 DropConnector {
3945 if_exists: bool,
3947 name: Ident,
3949 },
3950 Declare {
3958 stmts: Vec<Declare>,
3960 },
3961 CreateExtension(CreateExtension),
3970 CreateCollation(CreateCollation),
3976 DropExtension(DropExtension),
3982 DropOperator(DropOperator),
3988 DropOperatorFamily(DropOperatorFamily),
3994 DropOperatorClass(DropOperatorClass),
4000 Fetch {
4008 name: Ident,
4010 direction: FetchDirection,
4012 position: FetchPosition,
4014 into: Option<ObjectName>,
4016 },
4017 Flush {
4024 object_type: FlushType,
4026 location: Option<FlushLocation>,
4028 channel: Option<String>,
4030 read_lock: bool,
4032 export: bool,
4034 tables: Vec<ObjectName>,
4036 },
4037 Discard {
4044 object_type: DiscardObject,
4046 },
4047 ShowFunctions {
4051 filter: Option<ShowStatementFilter>,
4053 },
4054 ShowVariable {
4060 variable: Vec<Ident>,
4062 },
4063 ShowStatus {
4069 filter: Option<ShowStatementFilter>,
4071 global: bool,
4073 session: bool,
4075 },
4076 ShowVariables {
4082 filter: Option<ShowStatementFilter>,
4084 global: bool,
4086 session: bool,
4088 },
4089 ShowCreate {
4095 obj_type: ShowCreateObject,
4097 obj_name: ObjectName,
4099 },
4100 ShowColumns {
4104 extended: bool,
4106 full: bool,
4108 show_options: ShowStatementOptions,
4110 },
4111 ShowDatabases {
4115 terse: bool,
4117 history: bool,
4119 show_options: ShowStatementOptions,
4121 },
4122 ShowProcessList {
4128 full: bool,
4130 },
4131 ShowSchemas {
4135 terse: bool,
4137 history: bool,
4139 show_options: ShowStatementOptions,
4141 },
4142 ShowCharset(ShowCharset),
4149 ShowObjects(ShowObjects),
4155 ShowTables {
4159 terse: bool,
4161 history: bool,
4163 extended: bool,
4165 full: bool,
4167 external: bool,
4169 show_options: ShowStatementOptions,
4171 },
4172 ShowViews {
4176 terse: bool,
4178 materialized: bool,
4180 show_options: ShowStatementOptions,
4182 },
4183 ShowCollation {
4189 filter: Option<ShowStatementFilter>,
4191 },
4192 Use(Use),
4196 StartTransaction {
4206 modes: Vec<TransactionMode>,
4208 begin: bool,
4210 transaction: Option<BeginTransactionKind>,
4212 modifier: Option<TransactionModifier>,
4214 statements: Vec<Statement>,
4223 exception: Option<Vec<ExceptionWhen>>,
4237 has_end_keyword: bool,
4239 },
4240 Comment {
4246 object_type: CommentObject,
4248 object_name: ObjectName,
4250 comment: Option<String>,
4252 if_exists: bool,
4255 },
4256 Commit {
4266 chain: bool,
4268 end: bool,
4270 modifier: Option<TransactionModifier>,
4272 },
4273 Rollback {
4277 chain: bool,
4279 savepoint: Option<Ident>,
4281 },
4282 CreateSchema {
4286 schema_name: SchemaName,
4288 if_not_exists: bool,
4290 with: Option<Vec<SqlOption>>,
4298 options: Option<Vec<SqlOption>>,
4306 default_collate_spec: Option<Expr>,
4314 clone: Option<ObjectName>,
4322 },
4323 CreateDatabase {
4329 db_name: ObjectName,
4331 if_not_exists: bool,
4333 location: Option<String>,
4335 managed_location: Option<String>,
4337 or_replace: bool,
4339 transient: bool,
4341 clone: Option<ObjectName>,
4343 data_retention_time_in_days: Option<u64>,
4345 max_data_extension_time_in_days: Option<u64>,
4347 external_volume: Option<String>,
4349 catalog: Option<String>,
4351 replace_invalid_characters: Option<bool>,
4353 default_ddl_collation: Option<String>,
4355 storage_serialization_policy: Option<StorageSerializationPolicy>,
4357 comment: Option<String>,
4359 default_charset: Option<String>,
4361 default_collation: Option<String>,
4363 catalog_sync: Option<String>,
4365 catalog_sync_namespace_mode: Option<CatalogSyncNamespaceMode>,
4367 catalog_sync_namespace_flatten_delimiter: Option<String>,
4369 with_tags: Option<Vec<Tag>>,
4371 with_contacts: Option<Vec<ContactEntry>>,
4373 },
4374 CreateFunction(CreateFunction),
4384 CreateTrigger(CreateTrigger),
4386 DropTrigger(DropTrigger),
4388 CreateProcedure {
4392 or_alter: bool,
4394 name: ObjectName,
4396 params: Option<Vec<ProcedureParam>>,
4398 language: Option<Ident>,
4400 body: ConditionalStatements,
4402 },
4403 CreateMacro {
4410 or_replace: bool,
4412 temporary: bool,
4414 name: ObjectName,
4416 args: Option<Vec<MacroArg>>,
4418 definition: MacroDefinition,
4420 },
4421 CreateStage {
4426 or_replace: bool,
4428 temporary: bool,
4430 if_not_exists: bool,
4432 name: ObjectName,
4434 stage_params: StageParamsObject,
4436 directory_table_params: KeyValueOptions,
4438 file_format: KeyValueOptions,
4440 copy_options: KeyValueOptions,
4442 comment: Option<String>,
4444 },
4445 Assert {
4449 condition: Expr,
4451 message: Option<Expr>,
4453 },
4454 Grant(Grant),
4458 Deny(DenyStatement),
4462 Revoke(Revoke),
4466 Deallocate {
4472 name: Ident,
4474 prepare: bool,
4476 },
4477 Execute {
4486 name: Option<ObjectName>,
4488 parameters: Vec<Expr>,
4490 has_parentheses: bool,
4492 immediate: bool,
4494 into: Vec<Ident>,
4496 using: Vec<ExprWithAlias>,
4498 output: bool,
4501 default: bool,
4504 },
4505 Prepare {
4511 name: Ident,
4513 data_types: Vec<DataType>,
4515 statement: Box<Statement>,
4517 },
4518 Kill {
4525 modifier: Option<KillType>,
4527 id: u64,
4530 },
4531 ExplainTable {
4536 describe_alias: DescribeAlias,
4538 hive_format: Option<HiveDescribeFormat>,
4540 has_table_keyword: bool,
4545 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4547 table_name: ObjectName,
4548 },
4549 Explain {
4553 describe_alias: DescribeAlias,
4555 analyze: bool,
4557 verbose: bool,
4559 query_plan: bool,
4564 estimate: bool,
4567 statement: Box<Statement>,
4569 format: Option<AnalyzeFormatKind>,
4571 options: Option<Vec<UtilityOption>>,
4573 },
4574 Savepoint {
4579 name: Ident,
4581 },
4582 ReleaseSavepoint {
4586 name: Ident,
4588 },
4589 Merge(Merge),
4598 Cache {
4606 table_flag: Option<ObjectName>,
4608 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4610 table_name: ObjectName,
4611 has_as: bool,
4613 options: Vec<SqlOption>,
4615 query: Option<Box<Query>>,
4617 },
4618 UNCache {
4622 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4624 table_name: ObjectName,
4625 if_exists: bool,
4627 },
4628 CreateSequence {
4633 temporary: bool,
4635 if_not_exists: bool,
4637 name: ObjectName,
4639 data_type: Option<DataType>,
4641 sequence_options: Vec<SequenceOptions>,
4643 owned_by: Option<ObjectName>,
4645 },
4646 CreateDomain(CreateDomain),
4648 CreateType {
4652 name: ObjectName,
4654 representation: Option<UserDefinedTypeRepresentation>,
4656 },
4657 Pragma {
4661 name: ObjectName,
4663 value: Option<ValueWithSpan>,
4665 is_eq: bool,
4667 },
4668 Lock(Lock),
4674 LockTables {
4679 tables: Vec<LockTable>,
4681 },
4682 UnlockTables,
4687 Unload {
4699 query: Option<Box<Query>>,
4701 query_text: Option<String>,
4703 to: Ident,
4705 auth: Option<IamRoleKind>,
4707 with: Vec<SqlOption>,
4709 options: Vec<CopyLegacyOption>,
4711 },
4712 OptimizeTable {
4724 name: ObjectName,
4726 has_table_keyword: bool,
4728 on_cluster: Option<Ident>,
4731 partition: Option<Partition>,
4734 include_final: bool,
4737 deduplicate: Option<Deduplicate>,
4740 predicate: Option<Expr>,
4743 zorder: Option<Vec<Expr>>,
4746 },
4747 LISTEN {
4754 channel: Ident,
4756 },
4757 UNLISTEN {
4764 channel: Ident,
4766 },
4767 NOTIFY {
4774 channel: Ident,
4776 payload: Option<String>,
4778 },
4779 LoadData {
4788 local: bool,
4790 inpath: String,
4792 overwrite: bool,
4794 table_name: ObjectName,
4796 partitioned: Option<Vec<Expr>>,
4798 table_format: Option<HiveLoadDataFormat>,
4800 },
4801 RenameTable(Vec<RenameTable>),
4808 List(FileStagingCommand),
4811 Remove(FileStagingCommand),
4814 RaisError {
4821 message: Box<Expr>,
4823 severity: Box<Expr>,
4825 state: Box<Expr>,
4827 arguments: Vec<Expr>,
4829 options: Vec<RaisErrorOption>,
4831 },
4832 Throw(ThrowStatement),
4834 Print(PrintStatement),
4840 WaitFor(WaitForStatement),
4844 Return(ReturnStatement),
4850 ExportData(ExportData),
4859 CreateUser(CreateUser),
4864 AlterUser(AlterUser),
4869 Vacuum(VacuumStatement),
4876 Reset(ResetStatement),
4884}
4885
4886impl From<Analyze> for Statement {
4887 fn from(analyze: Analyze) -> Self {
4888 Statement::Analyze(analyze)
4889 }
4890}
4891
4892impl From<ddl::Truncate> for Statement {
4893 fn from(truncate: ddl::Truncate) -> Self {
4894 Statement::Truncate(truncate)
4895 }
4896}
4897
4898impl From<Lock> for Statement {
4899 fn from(lock: Lock) -> Self {
4900 Statement::Lock(lock)
4901 }
4902}
4903
4904impl From<ddl::Msck> for Statement {
4905 fn from(msck: ddl::Msck) -> Self {
4906 Statement::Msck(msck)
4907 }
4908}
4909
4910#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4916#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4917#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4918pub enum CurrentGrantsKind {
4919 CopyCurrentGrants,
4921 RevokeCurrentGrants,
4923}
4924
4925impl fmt::Display for CurrentGrantsKind {
4926 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4927 match self {
4928 CurrentGrantsKind::CopyCurrentGrants => write!(f, "COPY CURRENT GRANTS"),
4929 CurrentGrantsKind::RevokeCurrentGrants => write!(f, "REVOKE CURRENT GRANTS"),
4930 }
4931 }
4932}
4933
4934#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4935#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4936#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4937pub enum RaisErrorOption {
4940 Log,
4942 NoWait,
4944 SetError,
4946}
4947
4948impl fmt::Display for RaisErrorOption {
4949 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4950 match self {
4951 RaisErrorOption::Log => write!(f, "LOG"),
4952 RaisErrorOption::NoWait => write!(f, "NOWAIT"),
4953 RaisErrorOption::SetError => write!(f, "SETERROR"),
4954 }
4955 }
4956}
4957
4958impl fmt::Display for Statement {
4959 #[allow(clippy::cognitive_complexity)]
4984 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4985 match self {
4986 Statement::Flush {
4987 object_type,
4988 location,
4989 channel,
4990 read_lock,
4991 export,
4992 tables,
4993 } => {
4994 write!(f, "FLUSH")?;
4995 if let Some(location) = location {
4996 f.write_str(" ")?;
4997 location.fmt(f)?;
4998 }
4999 write!(f, " {object_type}")?;
5000
5001 if let Some(channel) = channel {
5002 write!(f, " FOR CHANNEL {channel}")?;
5003 }
5004
5005 write!(
5006 f,
5007 "{tables}{read}{export}",
5008 tables = if !tables.is_empty() {
5009 format!(" {}", display_comma_separated(tables))
5010 } else {
5011 String::new()
5012 },
5013 export = if *export { " FOR EXPORT" } else { "" },
5014 read = if *read_lock { " WITH READ LOCK" } else { "" }
5015 )
5016 }
5017 Statement::Kill { modifier, id } => {
5018 write!(f, "KILL ")?;
5019
5020 if let Some(m) = modifier {
5021 write!(f, "{m} ")?;
5022 }
5023
5024 write!(f, "{id}")
5025 }
5026 Statement::ExplainTable {
5027 describe_alias,
5028 hive_format,
5029 has_table_keyword,
5030 table_name,
5031 } => {
5032 write!(f, "{describe_alias} ")?;
5033
5034 if let Some(format) = hive_format {
5035 write!(f, "{format} ")?;
5036 }
5037 if *has_table_keyword {
5038 write!(f, "TABLE ")?;
5039 }
5040
5041 write!(f, "{table_name}")
5042 }
5043 Statement::Explain {
5044 describe_alias,
5045 verbose,
5046 analyze,
5047 query_plan,
5048 estimate,
5049 statement,
5050 format,
5051 options,
5052 } => {
5053 write!(f, "{describe_alias} ")?;
5054
5055 if *query_plan {
5056 write!(f, "QUERY PLAN ")?;
5057 }
5058 if *analyze {
5059 write!(f, "ANALYZE ")?;
5060 }
5061 if *estimate {
5062 write!(f, "ESTIMATE ")?;
5063 }
5064
5065 if *verbose {
5066 write!(f, "VERBOSE ")?;
5067 }
5068
5069 if let Some(format) = format {
5070 write!(f, "{format} ")?;
5071 }
5072
5073 if let Some(options) = options {
5074 write!(f, "({}) ", display_comma_separated(options))?;
5075 }
5076
5077 write!(f, "{statement}")
5078 }
5079 Statement::Query(s) => s.fmt(f),
5080 Statement::Declare { stmts } => {
5081 write!(f, "DECLARE ")?;
5082 write!(f, "{}", display_separated(stmts, "; "))
5083 }
5084 Statement::Fetch {
5085 name,
5086 direction,
5087 position,
5088 into,
5089 } => {
5090 write!(f, "FETCH {direction} {position} {name}")?;
5091
5092 if let Some(into) = into {
5093 write!(f, " INTO {into}")?;
5094 }
5095
5096 Ok(())
5097 }
5098 Statement::Directory {
5099 overwrite,
5100 local,
5101 path,
5102 file_format,
5103 source,
5104 } => {
5105 write!(
5106 f,
5107 "INSERT{overwrite}{local} DIRECTORY '{path}'",
5108 overwrite = if *overwrite { " OVERWRITE" } else { "" },
5109 local = if *local { " LOCAL" } else { "" },
5110 path = path
5111 )?;
5112 if let Some(ref ff) = file_format {
5113 write!(f, " STORED AS {ff}")?
5114 }
5115 write!(f, " {source}")
5116 }
5117 Statement::Msck(msck) => msck.fmt(f),
5118 Statement::Truncate(truncate) => truncate.fmt(f),
5119 Statement::Case(stmt) => {
5120 write!(f, "{stmt}")
5121 }
5122 Statement::If(stmt) => {
5123 write!(f, "{stmt}")
5124 }
5125 Statement::While(stmt) => {
5126 write!(f, "{stmt}")
5127 }
5128 Statement::Raise(stmt) => {
5129 write!(f, "{stmt}")
5130 }
5131 Statement::AttachDatabase {
5132 schema_name,
5133 database_file_name,
5134 database,
5135 } => {
5136 let keyword = if *database { "DATABASE " } else { "" };
5137 write!(f, "ATTACH {keyword}{database_file_name} AS {schema_name}")
5138 }
5139 Statement::AttachDuckDBDatabase {
5140 if_not_exists,
5141 database,
5142 database_path,
5143 database_alias,
5144 attach_options,
5145 } => {
5146 write!(
5147 f,
5148 "ATTACH{database}{if_not_exists} {database_path}",
5149 database = if *database { " DATABASE" } else { "" },
5150 if_not_exists = if *if_not_exists { " IF NOT EXISTS" } else { "" },
5151 )?;
5152 if let Some(alias) = database_alias {
5153 write!(f, " AS {alias}")?;
5154 }
5155 if !attach_options.is_empty() {
5156 write!(f, " ({})", display_comma_separated(attach_options))?;
5157 }
5158 Ok(())
5159 }
5160 Statement::DetachDuckDBDatabase {
5161 if_exists,
5162 database,
5163 database_alias,
5164 } => {
5165 write!(
5166 f,
5167 "DETACH{database}{if_exists} {database_alias}",
5168 database = if *database { " DATABASE" } else { "" },
5169 if_exists = if *if_exists { " IF EXISTS" } else { "" },
5170 )?;
5171 Ok(())
5172 }
5173 Statement::Analyze(analyze) => analyze.fmt(f),
5174 Statement::Insert(insert) => insert.fmt(f),
5175 Statement::Install {
5176 extension_name: name,
5177 } => write!(f, "INSTALL {name}"),
5178
5179 Statement::Load {
5180 extension_name: name,
5181 } => write!(f, "LOAD {name}"),
5182
5183 Statement::Call(function) => write!(f, "CALL {function}"),
5184
5185 Statement::Copy {
5186 source,
5187 to,
5188 target,
5189 options,
5190 legacy_options,
5191 values,
5192 } => {
5193 write!(f, "COPY")?;
5194 match source {
5195 CopySource::Query(query) => write!(f, " ({query})")?,
5196 CopySource::Table {
5197 table_name,
5198 columns,
5199 } => {
5200 write!(f, " {table_name}")?;
5201 if !columns.is_empty() {
5202 write!(f, " ({})", display_comma_separated(columns))?;
5203 }
5204 }
5205 }
5206 write!(f, " {} {}", if *to { "TO" } else { "FROM" }, target)?;
5207 if !options.is_empty() {
5208 write!(f, " ({})", display_comma_separated(options))?;
5209 }
5210 if !legacy_options.is_empty() {
5211 write!(f, " {}", display_separated(legacy_options, " "))?;
5212 }
5213 if !values.is_empty() {
5214 writeln!(f, ";")?;
5215 let mut delim = "";
5216 for v in values {
5217 write!(f, "{delim}")?;
5218 delim = "\t";
5219 if let Some(v) = v {
5220 write!(f, "{v}")?;
5221 } else {
5222 write!(f, "\\N")?;
5223 }
5224 }
5225 write!(f, "\n\\.")?;
5226 }
5227 Ok(())
5228 }
5229 Statement::Update(update) => update.fmt(f),
5230 Statement::Delete(delete) => delete.fmt(f),
5231 Statement::Open(open) => open.fmt(f),
5232 Statement::Close { cursor } => {
5233 write!(f, "CLOSE {cursor}")?;
5234
5235 Ok(())
5236 }
5237 Statement::CreateDatabase {
5238 db_name,
5239 if_not_exists,
5240 location,
5241 managed_location,
5242 or_replace,
5243 transient,
5244 clone,
5245 data_retention_time_in_days,
5246 max_data_extension_time_in_days,
5247 external_volume,
5248 catalog,
5249 replace_invalid_characters,
5250 default_ddl_collation,
5251 storage_serialization_policy,
5252 comment,
5253 default_charset,
5254 default_collation,
5255 catalog_sync,
5256 catalog_sync_namespace_mode,
5257 catalog_sync_namespace_flatten_delimiter,
5258 with_tags,
5259 with_contacts,
5260 } => {
5261 write!(
5262 f,
5263 "CREATE {or_replace}{transient}DATABASE {if_not_exists}{name}",
5264 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5265 transient = if *transient { "TRANSIENT " } else { "" },
5266 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5267 name = db_name,
5268 )?;
5269
5270 if let Some(l) = location {
5271 write!(f, " LOCATION '{l}'")?;
5272 }
5273 if let Some(ml) = managed_location {
5274 write!(f, " MANAGEDLOCATION '{ml}'")?;
5275 }
5276 if let Some(clone) = clone {
5277 write!(f, " CLONE {clone}")?;
5278 }
5279
5280 if let Some(value) = data_retention_time_in_days {
5281 write!(f, " DATA_RETENTION_TIME_IN_DAYS = {value}")?;
5282 }
5283
5284 if let Some(value) = max_data_extension_time_in_days {
5285 write!(f, " MAX_DATA_EXTENSION_TIME_IN_DAYS = {value}")?;
5286 }
5287
5288 if let Some(vol) = external_volume {
5289 write!(f, " EXTERNAL_VOLUME = '{vol}'")?;
5290 }
5291
5292 if let Some(cat) = catalog {
5293 write!(f, " CATALOG = '{cat}'")?;
5294 }
5295
5296 if let Some(true) = replace_invalid_characters {
5297 write!(f, " REPLACE_INVALID_CHARACTERS = TRUE")?;
5298 } else if let Some(false) = replace_invalid_characters {
5299 write!(f, " REPLACE_INVALID_CHARACTERS = FALSE")?;
5300 }
5301
5302 if let Some(collation) = default_ddl_collation {
5303 write!(f, " DEFAULT_DDL_COLLATION = '{collation}'")?;
5304 }
5305
5306 if let Some(policy) = storage_serialization_policy {
5307 write!(f, " STORAGE_SERIALIZATION_POLICY = {policy}")?;
5308 }
5309
5310 if let Some(comment) = comment {
5311 write!(f, " COMMENT = '{comment}'")?;
5312 }
5313
5314 if let Some(charset) = default_charset {
5315 write!(f, " DEFAULT CHARACTER SET {charset}")?;
5316 }
5317
5318 if let Some(collation) = default_collation {
5319 write!(f, " DEFAULT COLLATE {collation}")?;
5320 }
5321
5322 if let Some(sync) = catalog_sync {
5323 write!(f, " CATALOG_SYNC = '{sync}'")?;
5324 }
5325
5326 if let Some(mode) = catalog_sync_namespace_mode {
5327 write!(f, " CATALOG_SYNC_NAMESPACE_MODE = {mode}")?;
5328 }
5329
5330 if let Some(delim) = catalog_sync_namespace_flatten_delimiter {
5331 write!(f, " CATALOG_SYNC_NAMESPACE_FLATTEN_DELIMITER = '{delim}'")?;
5332 }
5333
5334 if let Some(tags) = with_tags {
5335 write!(f, " WITH TAG ({})", display_comma_separated(tags))?;
5336 }
5337
5338 if let Some(contacts) = with_contacts {
5339 write!(f, " WITH CONTACT ({})", display_comma_separated(contacts))?;
5340 }
5341 Ok(())
5342 }
5343 Statement::CreateFunction(create_function) => create_function.fmt(f),
5344 Statement::CreateDomain(create_domain) => create_domain.fmt(f),
5345 Statement::CreateTrigger(create_trigger) => create_trigger.fmt(f),
5346 Statement::DropTrigger(drop_trigger) => drop_trigger.fmt(f),
5347 Statement::CreateProcedure {
5348 name,
5349 or_alter,
5350 params,
5351 language,
5352 body,
5353 } => {
5354 write!(
5355 f,
5356 "CREATE {or_alter}PROCEDURE {name}",
5357 or_alter = if *or_alter { "OR ALTER " } else { "" },
5358 name = name
5359 )?;
5360
5361 if let Some(p) = params {
5362 if !p.is_empty() {
5363 write!(f, " ({})", display_comma_separated(p))?;
5364 }
5365 }
5366
5367 if let Some(language) = language {
5368 write!(f, " LANGUAGE {language}")?;
5369 }
5370
5371 write!(f, " AS {body}")
5372 }
5373 Statement::CreateMacro {
5374 or_replace,
5375 temporary,
5376 name,
5377 args,
5378 definition,
5379 } => {
5380 write!(
5381 f,
5382 "CREATE {or_replace}{temp}MACRO {name}",
5383 temp = if *temporary { "TEMPORARY " } else { "" },
5384 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5385 )?;
5386 if let Some(args) = args {
5387 write!(f, "({})", display_comma_separated(args))?;
5388 }
5389 match definition {
5390 MacroDefinition::Expr(expr) => write!(f, " AS {expr}")?,
5391 MacroDefinition::Table(query) => write!(f, " AS TABLE {query}")?,
5392 }
5393 Ok(())
5394 }
5395 Statement::CreateView(create_view) => create_view.fmt(f),
5396 Statement::CreateTable(create_table) => create_table.fmt(f),
5397 Statement::LoadData {
5398 local,
5399 inpath,
5400 overwrite,
5401 table_name,
5402 partitioned,
5403 table_format,
5404 } => {
5405 write!(
5406 f,
5407 "LOAD DATA {local}INPATH '{inpath}' {overwrite}INTO TABLE {table_name}",
5408 local = if *local { "LOCAL " } else { "" },
5409 inpath = inpath,
5410 overwrite = if *overwrite { "OVERWRITE " } else { "" },
5411 table_name = table_name,
5412 )?;
5413 if let Some(ref parts) = &partitioned {
5414 if !parts.is_empty() {
5415 write!(f, " PARTITION ({})", display_comma_separated(parts))?;
5416 }
5417 }
5418 if let Some(HiveLoadDataFormat {
5419 serde,
5420 input_format,
5421 }) = &table_format
5422 {
5423 write!(f, " INPUTFORMAT {input_format} SERDE {serde}")?;
5424 }
5425 Ok(())
5426 }
5427 Statement::CreateVirtualTable {
5428 name,
5429 if_not_exists,
5430 module_name,
5431 module_args,
5432 } => {
5433 write!(
5434 f,
5435 "CREATE VIRTUAL TABLE {if_not_exists}{name} USING {module_name}",
5436 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5437 name = name,
5438 module_name = module_name
5439 )?;
5440 if !module_args.is_empty() {
5441 write!(f, " ({})", display_comma_separated(module_args))?;
5442 }
5443 Ok(())
5444 }
5445 Statement::CreateIndex(create_index) => create_index.fmt(f),
5446 Statement::CreateExtension(create_extension) => write!(f, "{create_extension}"),
5447 Statement::CreateCollation(create_collation) => write!(f, "{create_collation}"),
5448 Statement::DropExtension(drop_extension) => write!(f, "{drop_extension}"),
5449 Statement::DropOperator(drop_operator) => write!(f, "{drop_operator}"),
5450 Statement::DropOperatorFamily(drop_operator_family) => {
5451 write!(f, "{drop_operator_family}")
5452 }
5453 Statement::DropOperatorClass(drop_operator_class) => {
5454 write!(f, "{drop_operator_class}")
5455 }
5456 Statement::CreateRole(create_role) => write!(f, "{create_role}"),
5457 Statement::CreateSecret {
5458 or_replace,
5459 temporary,
5460 if_not_exists,
5461 name,
5462 storage_specifier,
5463 secret_type,
5464 options,
5465 } => {
5466 write!(
5467 f,
5468 "CREATE {or_replace}",
5469 or_replace = if *or_replace { "OR REPLACE " } else { "" },
5470 )?;
5471 if let Some(t) = temporary {
5472 write!(f, "{}", if *t { "TEMPORARY " } else { "PERSISTENT " })?;
5473 }
5474 write!(
5475 f,
5476 "SECRET {if_not_exists}",
5477 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5478 )?;
5479 if let Some(n) = name {
5480 write!(f, "{n} ")?;
5481 };
5482 if let Some(s) = storage_specifier {
5483 write!(f, "IN {s} ")?;
5484 }
5485 write!(f, "( TYPE {secret_type}",)?;
5486 if !options.is_empty() {
5487 write!(f, ", {o}", o = display_comma_separated(options))?;
5488 }
5489 write!(f, " )")?;
5490 Ok(())
5491 }
5492 Statement::CreateServer(stmt) => {
5493 write!(f, "{stmt}")
5494 }
5495 Statement::CreatePolicy(policy) => write!(f, "{policy}"),
5496 Statement::CreateConnector(create_connector) => create_connector.fmt(f),
5497 Statement::CreateOperator(create_operator) => create_operator.fmt(f),
5498 Statement::CreateOperatorFamily(create_operator_family) => {
5499 create_operator_family.fmt(f)
5500 }
5501 Statement::CreateOperatorClass(create_operator_class) => create_operator_class.fmt(f),
5502 Statement::AlterTable(alter_table) => write!(f, "{alter_table}"),
5503 Statement::AlterIndex { name, operation } => {
5504 write!(f, "ALTER INDEX {name} {operation}")
5505 }
5506 Statement::AlterView {
5507 name,
5508 columns,
5509 query,
5510 with_options,
5511 } => {
5512 write!(f, "ALTER VIEW {name}")?;
5513 if !with_options.is_empty() {
5514 write!(f, " WITH ({})", display_comma_separated(with_options))?;
5515 }
5516 if !columns.is_empty() {
5517 write!(f, " ({})", display_comma_separated(columns))?;
5518 }
5519 write!(f, " AS {query}")
5520 }
5521 Statement::AlterFunction(alter_function) => write!(f, "{alter_function}"),
5522 Statement::AlterType(AlterType { name, operation }) => {
5523 write!(f, "ALTER TYPE {name} {operation}")
5524 }
5525 Statement::AlterCollation(alter_collation) => write!(f, "{alter_collation}"),
5526 Statement::AlterOperator(alter_operator) => write!(f, "{alter_operator}"),
5527 Statement::AlterOperatorFamily(alter_operator_family) => {
5528 write!(f, "{alter_operator_family}")
5529 }
5530 Statement::AlterOperatorClass(alter_operator_class) => {
5531 write!(f, "{alter_operator_class}")
5532 }
5533 Statement::AlterRole { name, operation } => {
5534 write!(f, "ALTER ROLE {name} {operation}")
5535 }
5536 Statement::AlterPolicy(alter_policy) => write!(f, "{alter_policy}"),
5537 Statement::AlterConnector {
5538 name,
5539 properties,
5540 url,
5541 owner,
5542 } => {
5543 write!(f, "ALTER CONNECTOR {name}")?;
5544 if let Some(properties) = properties {
5545 write!(
5546 f,
5547 " SET DCPROPERTIES({})",
5548 display_comma_separated(properties)
5549 )?;
5550 }
5551 if let Some(url) = url {
5552 write!(f, " SET URL '{url}'")?;
5553 }
5554 if let Some(owner) = owner {
5555 write!(f, " SET OWNER {owner}")?;
5556 }
5557 Ok(())
5558 }
5559 Statement::AlterSession {
5560 set,
5561 session_params,
5562 } => {
5563 write!(
5564 f,
5565 "ALTER SESSION {set}",
5566 set = if *set { "SET" } else { "UNSET" }
5567 )?;
5568 if !session_params.options.is_empty() {
5569 if *set {
5570 write!(f, " {session_params}")?;
5571 } else {
5572 let options = session_params
5573 .options
5574 .iter()
5575 .map(|p| p.option_name.clone())
5576 .collect::<Vec<_>>();
5577 write!(f, " {}", display_separated(&options, ", "))?;
5578 }
5579 }
5580 Ok(())
5581 }
5582 Statement::Drop {
5583 object_type,
5584 if_exists,
5585 names,
5586 cascade,
5587 restrict,
5588 purge,
5589 temporary,
5590 table,
5591 } => {
5592 write!(
5593 f,
5594 "DROP {}{}{} {}{}{}{}",
5595 if *temporary { "TEMPORARY " } else { "" },
5596 object_type,
5597 if *if_exists { " IF EXISTS" } else { "" },
5598 display_comma_separated(names),
5599 if *cascade { " CASCADE" } else { "" },
5600 if *restrict { " RESTRICT" } else { "" },
5601 if *purge { " PURGE" } else { "" },
5602 )?;
5603 if let Some(table_name) = table.as_ref() {
5604 write!(f, " ON {table_name}")?;
5605 };
5606 Ok(())
5607 }
5608 Statement::DropFunction(drop_function) => write!(f, "{drop_function}"),
5609 Statement::DropDomain(DropDomain {
5610 if_exists,
5611 name,
5612 drop_behavior,
5613 }) => {
5614 write!(
5615 f,
5616 "DROP DOMAIN{} {name}",
5617 if *if_exists { " IF EXISTS" } else { "" },
5618 )?;
5619 if let Some(op) = drop_behavior {
5620 write!(f, " {op}")?;
5621 }
5622 Ok(())
5623 }
5624 Statement::DropProcedure {
5625 if_exists,
5626 proc_desc,
5627 drop_behavior,
5628 } => {
5629 write!(
5630 f,
5631 "DROP PROCEDURE{} {}",
5632 if *if_exists { " IF EXISTS" } else { "" },
5633 display_comma_separated(proc_desc),
5634 )?;
5635 if let Some(op) = drop_behavior {
5636 write!(f, " {op}")?;
5637 }
5638 Ok(())
5639 }
5640 Statement::DropSecret {
5641 if_exists,
5642 temporary,
5643 name,
5644 storage_specifier,
5645 } => {
5646 write!(f, "DROP ")?;
5647 if let Some(t) = temporary {
5648 write!(f, "{}", if *t { "TEMPORARY " } else { "PERSISTENT " })?;
5649 }
5650 write!(
5651 f,
5652 "SECRET {if_exists}{name}",
5653 if_exists = if *if_exists { "IF EXISTS " } else { "" },
5654 )?;
5655 if let Some(s) = storage_specifier {
5656 write!(f, " FROM {s}")?;
5657 }
5658 Ok(())
5659 }
5660 Statement::DropPolicy(policy) => write!(f, "{policy}"),
5661 Statement::DropConnector { if_exists, name } => {
5662 write!(
5663 f,
5664 "DROP CONNECTOR {if_exists}{name}",
5665 if_exists = if *if_exists { "IF EXISTS " } else { "" }
5666 )?;
5667 Ok(())
5668 }
5669 Statement::Discard { object_type } => {
5670 write!(f, "DISCARD {object_type}")?;
5671 Ok(())
5672 }
5673 Self::Set(set) => write!(f, "{set}"),
5674 Statement::ShowVariable { variable } => {
5675 write!(f, "SHOW")?;
5676 if !variable.is_empty() {
5677 write!(f, " {}", display_separated(variable, " "))?;
5678 }
5679 Ok(())
5680 }
5681 Statement::ShowStatus {
5682 filter,
5683 global,
5684 session,
5685 } => {
5686 write!(f, "SHOW")?;
5687 if *global {
5688 write!(f, " GLOBAL")?;
5689 }
5690 if *session {
5691 write!(f, " SESSION")?;
5692 }
5693 write!(f, " STATUS")?;
5694 if filter.is_some() {
5695 write!(f, " {}", filter.as_ref().unwrap())?;
5696 }
5697 Ok(())
5698 }
5699 Statement::ShowVariables {
5700 filter,
5701 global,
5702 session,
5703 } => {
5704 write!(f, "SHOW")?;
5705 if *global {
5706 write!(f, " GLOBAL")?;
5707 }
5708 if *session {
5709 write!(f, " SESSION")?;
5710 }
5711 write!(f, " VARIABLES")?;
5712 if filter.is_some() {
5713 write!(f, " {}", filter.as_ref().unwrap())?;
5714 }
5715 Ok(())
5716 }
5717 Statement::ShowCreate { obj_type, obj_name } => {
5718 write!(f, "SHOW CREATE {obj_type} {obj_name}",)?;
5719 Ok(())
5720 }
5721 Statement::ShowColumns {
5722 extended,
5723 full,
5724 show_options,
5725 } => {
5726 write!(
5727 f,
5728 "SHOW {extended}{full}COLUMNS{show_options}",
5729 extended = if *extended { "EXTENDED " } else { "" },
5730 full = if *full { "FULL " } else { "" },
5731 )?;
5732 Ok(())
5733 }
5734 Statement::ShowDatabases {
5735 terse,
5736 history,
5737 show_options,
5738 } => {
5739 write!(
5740 f,
5741 "SHOW {terse}DATABASES{history}{show_options}",
5742 terse = if *terse { "TERSE " } else { "" },
5743 history = if *history { " HISTORY" } else { "" },
5744 )?;
5745 Ok(())
5746 }
5747 Statement::ShowProcessList { full } => {
5748 write!(
5749 f,
5750 "SHOW {full}PROCESSLIST",
5751 full = if *full { "FULL " } else { "" },
5752 )?;
5753 Ok(())
5754 }
5755 Statement::ShowSchemas {
5756 terse,
5757 history,
5758 show_options,
5759 } => {
5760 write!(
5761 f,
5762 "SHOW {terse}SCHEMAS{history}{show_options}",
5763 terse = if *terse { "TERSE " } else { "" },
5764 history = if *history { " HISTORY" } else { "" },
5765 )?;
5766 Ok(())
5767 }
5768 Statement::ShowObjects(ShowObjects {
5769 terse,
5770 show_options,
5771 }) => {
5772 write!(
5773 f,
5774 "SHOW {terse}OBJECTS{show_options}",
5775 terse = if *terse { "TERSE " } else { "" },
5776 )?;
5777 Ok(())
5778 }
5779 Statement::ShowTables {
5780 terse,
5781 history,
5782 extended,
5783 full,
5784 external,
5785 show_options,
5786 } => {
5787 write!(
5788 f,
5789 "SHOW {terse}{extended}{full}{external}TABLES{history}{show_options}",
5790 terse = if *terse { "TERSE " } else { "" },
5791 extended = if *extended { "EXTENDED " } else { "" },
5792 full = if *full { "FULL " } else { "" },
5793 external = if *external { "EXTERNAL " } else { "" },
5794 history = if *history { " HISTORY" } else { "" },
5795 )?;
5796 Ok(())
5797 }
5798 Statement::ShowViews {
5799 terse,
5800 materialized,
5801 show_options,
5802 } => {
5803 write!(
5804 f,
5805 "SHOW {terse}{materialized}VIEWS{show_options}",
5806 terse = if *terse { "TERSE " } else { "" },
5807 materialized = if *materialized { "MATERIALIZED " } else { "" }
5808 )?;
5809 Ok(())
5810 }
5811 Statement::ShowFunctions { filter } => {
5812 write!(f, "SHOW FUNCTIONS")?;
5813 if let Some(filter) = filter {
5814 write!(f, " {filter}")?;
5815 }
5816 Ok(())
5817 }
5818 Statement::Use(use_expr) => use_expr.fmt(f),
5819 Statement::ShowCollation { filter } => {
5820 write!(f, "SHOW COLLATION")?;
5821 if let Some(filter) = filter {
5822 write!(f, " {filter}")?;
5823 }
5824 Ok(())
5825 }
5826 Statement::ShowCharset(show_stm) => show_stm.fmt(f),
5827 Statement::StartTransaction {
5828 modes,
5829 begin: syntax_begin,
5830 transaction,
5831 modifier,
5832 statements,
5833 exception,
5834 has_end_keyword,
5835 } => {
5836 if *syntax_begin {
5837 if let Some(modifier) = *modifier {
5838 write!(f, "BEGIN {modifier}")?;
5839 } else {
5840 write!(f, "BEGIN")?;
5841 }
5842 } else {
5843 write!(f, "START")?;
5844 }
5845 if let Some(transaction) = transaction {
5846 write!(f, " {transaction}")?;
5847 }
5848 if !modes.is_empty() {
5849 write!(f, " {}", display_comma_separated(modes))?;
5850 }
5851 if !statements.is_empty() {
5852 write!(f, " ")?;
5853 format_statement_list(f, statements)?;
5854 }
5855 if let Some(exception_when) = exception {
5856 write!(f, " EXCEPTION")?;
5857 for when in exception_when {
5858 write!(f, " {when}")?;
5859 }
5860 }
5861 if *has_end_keyword {
5862 write!(f, " END")?;
5863 }
5864 Ok(())
5865 }
5866 Statement::Commit {
5867 chain,
5868 end: end_syntax,
5869 modifier,
5870 } => {
5871 if *end_syntax {
5872 write!(f, "END")?;
5873 if let Some(modifier) = *modifier {
5874 write!(f, " {modifier}")?;
5875 }
5876 if *chain {
5877 write!(f, " AND CHAIN")?;
5878 }
5879 } else {
5880 write!(f, "COMMIT{}", if *chain { " AND CHAIN" } else { "" })?;
5881 }
5882 Ok(())
5883 }
5884 Statement::Rollback { chain, savepoint } => {
5885 write!(f, "ROLLBACK")?;
5886
5887 if *chain {
5888 write!(f, " AND CHAIN")?;
5889 }
5890
5891 if let Some(savepoint) = savepoint {
5892 write!(f, " TO SAVEPOINT {savepoint}")?;
5893 }
5894
5895 Ok(())
5896 }
5897 Statement::CreateSchema {
5898 schema_name,
5899 if_not_exists,
5900 with,
5901 options,
5902 default_collate_spec,
5903 clone,
5904 } => {
5905 write!(
5906 f,
5907 "CREATE SCHEMA {if_not_exists}{name}",
5908 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
5909 name = schema_name
5910 )?;
5911
5912 if let Some(collate) = default_collate_spec {
5913 write!(f, " DEFAULT COLLATE {collate}")?;
5914 }
5915
5916 if let Some(with) = with {
5917 write!(f, " WITH ({})", display_comma_separated(with))?;
5918 }
5919
5920 if let Some(options) = options {
5921 write!(f, " OPTIONS({})", display_comma_separated(options))?;
5922 }
5923
5924 if let Some(clone) = clone {
5925 write!(f, " CLONE {clone}")?;
5926 }
5927 Ok(())
5928 }
5929 Statement::Assert { condition, message } => {
5930 write!(f, "ASSERT {condition}")?;
5931 if let Some(m) = message {
5932 write!(f, " AS {m}")?;
5933 }
5934 Ok(())
5935 }
5936 Statement::Grant(grant) => write!(f, "{grant}"),
5937 Statement::Deny(s) => write!(f, "{s}"),
5938 Statement::Revoke(revoke) => write!(f, "{revoke}"),
5939 Statement::Deallocate { name, prepare } => write!(
5940 f,
5941 "DEALLOCATE {prepare}{name}",
5942 prepare = if *prepare { "PREPARE " } else { "" },
5943 name = name,
5944 ),
5945 Statement::Execute {
5946 name,
5947 parameters,
5948 has_parentheses,
5949 immediate,
5950 into,
5951 using,
5952 output,
5953 default,
5954 } => {
5955 let (open, close) = if *has_parentheses {
5956 (if name.is_some() { "(" } else { " (" }, ")")
5958 } else {
5959 (if parameters.is_empty() { "" } else { " " }, "")
5960 };
5961 write!(f, "EXECUTE")?;
5962 if *immediate {
5963 write!(f, " IMMEDIATE")?;
5964 }
5965 if let Some(name) = name {
5966 write!(f, " {name}")?;
5967 }
5968 write!(f, "{open}{}{close}", display_comma_separated(parameters),)?;
5969 if !into.is_empty() {
5970 write!(f, " INTO {}", display_comma_separated(into))?;
5971 }
5972 if !using.is_empty() {
5973 write!(f, " USING {}", display_comma_separated(using))?;
5974 };
5975 if *output {
5976 write!(f, " OUTPUT")?;
5977 }
5978 if *default {
5979 write!(f, " DEFAULT")?;
5980 }
5981 Ok(())
5982 }
5983 Statement::Prepare {
5984 name,
5985 data_types,
5986 statement,
5987 } => {
5988 write!(f, "PREPARE {name} ")?;
5989 if !data_types.is_empty() {
5990 write!(f, "({}) ", display_comma_separated(data_types))?;
5991 }
5992 write!(f, "AS {statement}")
5993 }
5994 Statement::Comment {
5995 object_type,
5996 object_name,
5997 comment,
5998 if_exists,
5999 } => {
6000 write!(f, "COMMENT ")?;
6001 if *if_exists {
6002 write!(f, "IF EXISTS ")?
6003 };
6004 write!(f, "ON {object_type} {object_name} IS ")?;
6005 if let Some(c) = comment {
6006 write!(f, "'{c}'")
6007 } else {
6008 write!(f, "NULL")
6009 }
6010 }
6011 Statement::Savepoint { name } => {
6012 write!(f, "SAVEPOINT ")?;
6013 write!(f, "{name}")
6014 }
6015 Statement::ReleaseSavepoint { name } => {
6016 write!(f, "RELEASE SAVEPOINT {name}")
6017 }
6018 Statement::Merge(merge) => merge.fmt(f),
6019 Statement::Cache {
6020 table_name,
6021 table_flag,
6022 has_as,
6023 options,
6024 query,
6025 } => {
6026 if let Some(table_flag) = table_flag {
6027 write!(f, "CACHE {table_flag} TABLE {table_name}")?;
6028 } else {
6029 write!(f, "CACHE TABLE {table_name}")?;
6030 }
6031
6032 if !options.is_empty() {
6033 write!(f, " OPTIONS({})", display_comma_separated(options))?;
6034 }
6035
6036 match (*has_as, query) {
6037 (true, Some(query)) => write!(f, " AS {query}"),
6038 (true, None) => f.write_str(" AS"),
6039 (false, Some(query)) => write!(f, " {query}"),
6040 (false, None) => Ok(()),
6041 }
6042 }
6043 Statement::UNCache {
6044 table_name,
6045 if_exists,
6046 } => {
6047 if *if_exists {
6048 write!(f, "UNCACHE TABLE IF EXISTS {table_name}")
6049 } else {
6050 write!(f, "UNCACHE TABLE {table_name}")
6051 }
6052 }
6053 Statement::CreateSequence {
6054 temporary,
6055 if_not_exists,
6056 name,
6057 data_type,
6058 sequence_options,
6059 owned_by,
6060 } => {
6061 let as_type: String = if let Some(dt) = data_type.as_ref() {
6062 [" AS ", &dt.to_string()].concat()
6065 } else {
6066 "".to_string()
6067 };
6068 write!(
6069 f,
6070 "CREATE {temporary}SEQUENCE {if_not_exists}{name}{as_type}",
6071 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
6072 temporary = if *temporary { "TEMPORARY " } else { "" },
6073 name = name,
6074 as_type = as_type
6075 )?;
6076 for sequence_option in sequence_options {
6077 write!(f, "{sequence_option}")?;
6078 }
6079 if let Some(ob) = owned_by.as_ref() {
6080 write!(f, " OWNED BY {ob}")?;
6081 }
6082 write!(f, "")
6083 }
6084 Statement::CreateStage {
6085 or_replace,
6086 temporary,
6087 if_not_exists,
6088 name,
6089 stage_params,
6090 directory_table_params,
6091 file_format,
6092 copy_options,
6093 comment,
6094 ..
6095 } => {
6096 write!(
6097 f,
6098 "CREATE {or_replace}{temp}STAGE {if_not_exists}{name}{stage_params}",
6099 temp = if *temporary { "TEMPORARY " } else { "" },
6100 or_replace = if *or_replace { "OR REPLACE " } else { "" },
6101 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
6102 )?;
6103 if !directory_table_params.options.is_empty() {
6104 write!(f, " DIRECTORY=({directory_table_params})")?;
6105 }
6106 if !file_format.options.is_empty() {
6107 write!(f, " FILE_FORMAT=({file_format})")?;
6108 }
6109 if !copy_options.options.is_empty() {
6110 write!(f, " COPY_OPTIONS=({copy_options})")?;
6111 }
6112 if comment.is_some() {
6113 write!(f, " COMMENT='{}'", comment.as_ref().unwrap())?;
6114 }
6115 Ok(())
6116 }
6117 Statement::CopyIntoSnowflake {
6118 kind,
6119 into,
6120 into_columns,
6121 from_obj,
6122 from_obj_alias,
6123 stage_params,
6124 from_transformations,
6125 from_query,
6126 files,
6127 pattern,
6128 file_format,
6129 copy_options,
6130 validation_mode,
6131 partition,
6132 } => {
6133 write!(f, "COPY INTO {into}")?;
6134 if let Some(into_columns) = into_columns {
6135 write!(f, " ({})", display_comma_separated(into_columns))?;
6136 }
6137 if let Some(from_transformations) = from_transformations {
6138 if let Some(from_stage) = from_obj {
6140 write!(
6141 f,
6142 " FROM (SELECT {} FROM {}{}",
6143 display_separated(from_transformations, ", "),
6144 from_stage,
6145 stage_params
6146 )?;
6147 }
6148 if let Some(from_obj_alias) = from_obj_alias {
6149 write!(f, " AS {from_obj_alias}")?;
6150 }
6151 write!(f, ")")?;
6152 } else if let Some(from_obj) = from_obj {
6153 write!(f, " FROM {from_obj}{stage_params}")?;
6155 if let Some(from_obj_alias) = from_obj_alias {
6156 write!(f, " AS {from_obj_alias}")?;
6157 }
6158 } else if let Some(from_query) = from_query {
6159 write!(f, " FROM ({from_query})")?;
6161 }
6162
6163 if let Some(files) = files {
6164 write!(f, " FILES = ('{}')", display_separated(files, "', '"))?;
6165 }
6166 if let Some(pattern) = pattern {
6167 write!(f, " PATTERN = '{pattern}'")?;
6168 }
6169 if let Some(partition) = partition {
6170 write!(f, " PARTITION BY {partition}")?;
6171 }
6172 if !file_format.options.is_empty() {
6173 write!(f, " FILE_FORMAT=({file_format})")?;
6174 }
6175 if !copy_options.options.is_empty() {
6176 match kind {
6177 CopyIntoSnowflakeKind::Table => {
6178 write!(f, " COPY_OPTIONS=({copy_options})")?
6179 }
6180 CopyIntoSnowflakeKind::Location => write!(f, " {copy_options}")?,
6181 }
6182 }
6183 if let Some(validation_mode) = validation_mode {
6184 write!(f, " VALIDATION_MODE = {validation_mode}")?;
6185 }
6186 Ok(())
6187 }
6188 Statement::CreateType {
6189 name,
6190 representation,
6191 } => {
6192 write!(f, "CREATE TYPE {name}")?;
6193 if let Some(repr) = representation {
6194 write!(f, " {repr}")?;
6195 }
6196 Ok(())
6197 }
6198 Statement::Pragma { name, value, is_eq } => {
6199 write!(f, "PRAGMA {name}")?;
6200 if value.is_some() {
6201 let val = value.as_ref().unwrap();
6202 if *is_eq {
6203 write!(f, " = {val}")?;
6204 } else {
6205 write!(f, "({val})")?;
6206 }
6207 }
6208 Ok(())
6209 }
6210 Statement::Lock(lock) => lock.fmt(f),
6211 Statement::LockTables { tables } => {
6212 write!(f, "LOCK TABLES {}", display_comma_separated(tables))
6213 }
6214 Statement::UnlockTables => {
6215 write!(f, "UNLOCK TABLES")
6216 }
6217 Statement::Unload {
6218 query,
6219 query_text,
6220 to,
6221 auth,
6222 with,
6223 options,
6224 } => {
6225 write!(f, "UNLOAD(")?;
6226 if let Some(query) = query {
6227 write!(f, "{query}")?;
6228 }
6229 if let Some(query_text) = query_text {
6230 write!(f, "'{query_text}'")?;
6231 }
6232 write!(f, ") TO {to}")?;
6233 if let Some(auth) = auth {
6234 write!(f, " IAM_ROLE {auth}")?;
6235 }
6236 if !with.is_empty() {
6237 write!(f, " WITH ({})", display_comma_separated(with))?;
6238 }
6239 if !options.is_empty() {
6240 write!(f, " {}", display_separated(options, " "))?;
6241 }
6242 Ok(())
6243 }
6244 Statement::OptimizeTable {
6245 name,
6246 has_table_keyword,
6247 on_cluster,
6248 partition,
6249 include_final,
6250 deduplicate,
6251 predicate,
6252 zorder,
6253 } => {
6254 write!(f, "OPTIMIZE")?;
6255 if *has_table_keyword {
6256 write!(f, " TABLE")?;
6257 }
6258 write!(f, " {name}")?;
6259 if let Some(on_cluster) = on_cluster {
6260 write!(f, " ON CLUSTER {on_cluster}")?;
6261 }
6262 if let Some(partition) = partition {
6263 write!(f, " {partition}")?;
6264 }
6265 if *include_final {
6266 write!(f, " FINAL")?;
6267 }
6268 if let Some(deduplicate) = deduplicate {
6269 write!(f, " {deduplicate}")?;
6270 }
6271 if let Some(predicate) = predicate {
6272 write!(f, " WHERE {predicate}")?;
6273 }
6274 if let Some(zorder) = zorder {
6275 write!(f, " ZORDER BY ({})", display_comma_separated(zorder))?;
6276 }
6277 Ok(())
6278 }
6279 Statement::LISTEN { channel } => {
6280 write!(f, "LISTEN {channel}")?;
6281 Ok(())
6282 }
6283 Statement::UNLISTEN { channel } => {
6284 write!(f, "UNLISTEN {channel}")?;
6285 Ok(())
6286 }
6287 Statement::NOTIFY { channel, payload } => {
6288 write!(f, "NOTIFY {channel}")?;
6289 if let Some(payload) = payload {
6290 write!(f, ", '{payload}'")?;
6291 }
6292 Ok(())
6293 }
6294 Statement::RenameTable(rename_tables) => {
6295 write!(f, "RENAME TABLE {}", display_comma_separated(rename_tables))
6296 }
6297 Statement::RaisError {
6298 message,
6299 severity,
6300 state,
6301 arguments,
6302 options,
6303 } => {
6304 write!(f, "RAISERROR({message}, {severity}, {state}")?;
6305 if !arguments.is_empty() {
6306 write!(f, ", {}", display_comma_separated(arguments))?;
6307 }
6308 write!(f, ")")?;
6309 if !options.is_empty() {
6310 write!(f, " WITH {}", display_comma_separated(options))?;
6311 }
6312 Ok(())
6313 }
6314 Statement::Throw(s) => write!(f, "{s}"),
6315 Statement::Print(s) => write!(f, "{s}"),
6316 Statement::WaitFor(s) => write!(f, "{s}"),
6317 Statement::Return(r) => write!(f, "{r}"),
6318 Statement::List(command) => write!(f, "LIST {command}"),
6319 Statement::Remove(command) => write!(f, "REMOVE {command}"),
6320 Statement::ExportData(e) => write!(f, "{e}"),
6321 Statement::CreateUser(s) => write!(f, "{s}"),
6322 Statement::AlterSchema(s) => write!(f, "{s}"),
6323 Statement::Vacuum(s) => write!(f, "{s}"),
6324 Statement::AlterUser(s) => write!(f, "{s}"),
6325 Statement::Reset(s) => write!(f, "{s}"),
6326 }
6327 }
6328}
6329
6330#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6337#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6338#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6339pub enum SequenceOptions {
6340 IncrementBy(Expr, bool),
6342 MinValue(Option<Expr>),
6344 MaxValue(Option<Expr>),
6346 StartWith(Expr, bool),
6348 Cache(Expr),
6350 Cycle(bool),
6352}
6353
6354impl fmt::Display for SequenceOptions {
6355 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6356 match self {
6357 SequenceOptions::IncrementBy(increment, by) => {
6358 write!(
6359 f,
6360 " INCREMENT{by} {increment}",
6361 by = if *by { " BY" } else { "" },
6362 increment = increment
6363 )
6364 }
6365 SequenceOptions::MinValue(Some(expr)) => {
6366 write!(f, " MINVALUE {expr}")
6367 }
6368 SequenceOptions::MinValue(None) => {
6369 write!(f, " NO MINVALUE")
6370 }
6371 SequenceOptions::MaxValue(Some(expr)) => {
6372 write!(f, " MAXVALUE {expr}")
6373 }
6374 SequenceOptions::MaxValue(None) => {
6375 write!(f, " NO MAXVALUE")
6376 }
6377 SequenceOptions::StartWith(start, with) => {
6378 write!(
6379 f,
6380 " START{with} {start}",
6381 with = if *with { " WITH" } else { "" },
6382 start = start
6383 )
6384 }
6385 SequenceOptions::Cache(cache) => {
6386 write!(f, " CACHE {}", *cache)
6387 }
6388 SequenceOptions::Cycle(no) => {
6389 write!(f, " {}CYCLE", if *no { "NO " } else { "" })
6390 }
6391 }
6392 }
6393}
6394
6395#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6397#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6398#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6399pub struct SetAssignment {
6400 pub scope: Option<ContextModifier>,
6402 pub name: ObjectName,
6404 pub value: Expr,
6406}
6407
6408impl fmt::Display for SetAssignment {
6409 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6410 write!(
6411 f,
6412 "{}{} = {}",
6413 self.scope.map(|s| format!("{s}")).unwrap_or_default(),
6414 self.name,
6415 self.value
6416 )
6417 }
6418}
6419
6420#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6424#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6425#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6426pub struct TruncateTableTarget {
6427 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
6429 pub name: ObjectName,
6430 pub only: bool,
6436 pub has_asterisk: bool,
6442}
6443
6444impl fmt::Display for TruncateTableTarget {
6445 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6446 if self.only {
6447 write!(f, "ONLY ")?;
6448 };
6449 write!(f, "{}", self.name)?;
6450 if self.has_asterisk {
6451 write!(f, " *")?;
6452 };
6453 Ok(())
6454 }
6455}
6456
6457#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6461#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6462#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6463pub struct Lock {
6464 pub tables: Vec<LockTableTarget>,
6466 pub lock_mode: Option<LockTableMode>,
6468 pub nowait: bool,
6470}
6471
6472impl fmt::Display for Lock {
6473 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6474 write!(f, "LOCK TABLE {}", display_comma_separated(&self.tables))?;
6475 if let Some(lock_mode) = &self.lock_mode {
6476 write!(f, " IN {lock_mode} MODE")?;
6477 }
6478 if self.nowait {
6479 write!(f, " NOWAIT")?;
6480 }
6481 Ok(())
6482 }
6483}
6484
6485#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6489#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6490#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6491pub struct LockTableTarget {
6492 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
6494 pub name: ObjectName,
6495 pub only: bool,
6497 pub has_asterisk: bool,
6499}
6500
6501impl fmt::Display for LockTableTarget {
6502 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6503 if self.only {
6504 write!(f, "ONLY ")?;
6505 }
6506 write!(f, "{}", self.name)?;
6507 if self.has_asterisk {
6508 write!(f, " *")?;
6509 }
6510 Ok(())
6511 }
6512}
6513
6514#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6518#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6519#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6520pub enum LockTableMode {
6521 AccessShare,
6523 RowShare,
6525 RowExclusive,
6527 ShareUpdateExclusive,
6529 Share,
6531 ShareRowExclusive,
6533 Exclusive,
6535 AccessExclusive,
6537}
6538
6539impl fmt::Display for LockTableMode {
6540 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6541 let text = match self {
6542 Self::AccessShare => "ACCESS SHARE",
6543 Self::RowShare => "ROW SHARE",
6544 Self::RowExclusive => "ROW EXCLUSIVE",
6545 Self::ShareUpdateExclusive => "SHARE UPDATE EXCLUSIVE",
6546 Self::Share => "SHARE",
6547 Self::ShareRowExclusive => "SHARE ROW EXCLUSIVE",
6548 Self::Exclusive => "EXCLUSIVE",
6549 Self::AccessExclusive => "ACCESS EXCLUSIVE",
6550 };
6551 write!(f, "{text}")
6552 }
6553}
6554
6555#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6558#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6559#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6560pub enum TruncateIdentityOption {
6561 Restart,
6563 Continue,
6565}
6566
6567#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6570#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6571#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6572pub enum CascadeOption {
6573 Cascade,
6575 Restrict,
6577}
6578
6579impl Display for CascadeOption {
6580 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6581 match self {
6582 CascadeOption::Cascade => write!(f, "CASCADE"),
6583 CascadeOption::Restrict => write!(f, "RESTRICT"),
6584 }
6585 }
6586}
6587
6588#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6590#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6591#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6592pub enum BeginTransactionKind {
6593 Transaction,
6595 Work,
6597 Tran,
6600}
6601
6602impl Display for BeginTransactionKind {
6603 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6604 match self {
6605 BeginTransactionKind::Transaction => write!(f, "TRANSACTION"),
6606 BeginTransactionKind::Work => write!(f, "WORK"),
6607 BeginTransactionKind::Tran => write!(f, "TRAN"),
6608 }
6609 }
6610}
6611
6612#[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 MinMaxValue {
6618 Empty,
6620 None,
6622 Some(Expr),
6624}
6625
6626#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6627#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6628#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6629#[non_exhaustive]
6630pub enum OnInsert {
6632 DuplicateKeyUpdate(Vec<Assignment>),
6634 OnConflict(OnConflict),
6636}
6637
6638#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6639#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6640#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6641pub struct InsertAliases {
6643 pub row_alias: ObjectName,
6645 pub col_aliases: Option<Vec<Ident>>,
6647}
6648
6649#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6650#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6651#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6652pub struct TableAliasWithoutColumns {
6654 pub explicit: bool,
6656 pub alias: Ident,
6658}
6659
6660#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6661#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6662#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6663pub struct OnConflict {
6665 pub conflict_target: Option<ConflictTarget>,
6667 pub action: OnConflictAction,
6669}
6670#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6671#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6672#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6673pub enum ConflictTarget {
6675 Columns(Vec<Ident>),
6677 OnConstraint(ObjectName),
6679}
6680#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6681#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6682#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6683pub enum OnConflictAction {
6685 DoNothing,
6687 DoUpdate(DoUpdate),
6689}
6690
6691#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6692#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6693#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6694pub struct DoUpdate {
6696 pub assignments: Vec<Assignment>,
6698 pub selection: Option<Expr>,
6700}
6701
6702impl fmt::Display for OnInsert {
6703 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6704 match self {
6705 Self::DuplicateKeyUpdate(expr) => write!(
6706 f,
6707 " ON DUPLICATE KEY UPDATE {}",
6708 display_comma_separated(expr)
6709 ),
6710 Self::OnConflict(o) => write!(f, "{o}"),
6711 }
6712 }
6713}
6714impl fmt::Display for OnConflict {
6715 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6716 write!(f, " ON CONFLICT")?;
6717 if let Some(target) = &self.conflict_target {
6718 write!(f, "{target}")?;
6719 }
6720 write!(f, " {}", self.action)
6721 }
6722}
6723impl fmt::Display for ConflictTarget {
6724 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6725 match self {
6726 ConflictTarget::Columns(cols) => write!(f, "({})", display_comma_separated(cols)),
6727 ConflictTarget::OnConstraint(name) => write!(f, " ON CONSTRAINT {name}"),
6728 }
6729 }
6730}
6731impl fmt::Display for OnConflictAction {
6732 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6733 match self {
6734 Self::DoNothing => write!(f, "DO NOTHING"),
6735 Self::DoUpdate(do_update) => {
6736 write!(f, "DO UPDATE")?;
6737 if !do_update.assignments.is_empty() {
6738 write!(
6739 f,
6740 " SET {}",
6741 display_comma_separated(&do_update.assignments)
6742 )?;
6743 }
6744 if let Some(selection) = &do_update.selection {
6745 write!(f, " WHERE {selection}")?;
6746 }
6747 Ok(())
6748 }
6749 }
6750 }
6751}
6752
6753#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6755#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6756#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6757pub enum Privileges {
6758 All {
6760 with_privileges_keyword: bool,
6762 },
6763 Actions(Vec<Action>),
6765}
6766
6767impl fmt::Display for Privileges {
6768 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6769 match self {
6770 Privileges::All {
6771 with_privileges_keyword,
6772 } => {
6773 write!(
6774 f,
6775 "ALL{}",
6776 if *with_privileges_keyword {
6777 " PRIVILEGES"
6778 } else {
6779 ""
6780 }
6781 )
6782 }
6783 Privileges::Actions(actions) => {
6784 write!(f, "{}", display_comma_separated(actions))
6785 }
6786 }
6787 }
6788}
6789
6790#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6792#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6793#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6794pub enum FetchDirection {
6795 Count {
6797 limit: ValueWithSpan,
6799 },
6800 Next,
6802 Prior,
6804 First,
6806 Last,
6808 Absolute {
6810 limit: ValueWithSpan,
6812 },
6813 Relative {
6815 limit: ValueWithSpan,
6817 },
6818 All,
6820 Forward {
6824 limit: Option<ValueWithSpan>,
6826 },
6827 ForwardAll,
6829 Backward {
6833 limit: Option<ValueWithSpan>,
6835 },
6836 BackwardAll,
6838}
6839
6840impl fmt::Display for FetchDirection {
6841 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6842 match self {
6843 FetchDirection::Count { limit } => f.write_str(&limit.to_string())?,
6844 FetchDirection::Next => f.write_str("NEXT")?,
6845 FetchDirection::Prior => f.write_str("PRIOR")?,
6846 FetchDirection::First => f.write_str("FIRST")?,
6847 FetchDirection::Last => f.write_str("LAST")?,
6848 FetchDirection::Absolute { limit } => {
6849 f.write_str("ABSOLUTE ")?;
6850 f.write_str(&limit.to_string())?;
6851 }
6852 FetchDirection::Relative { limit } => {
6853 f.write_str("RELATIVE ")?;
6854 f.write_str(&limit.to_string())?;
6855 }
6856 FetchDirection::All => f.write_str("ALL")?,
6857 FetchDirection::Forward { limit } => {
6858 f.write_str("FORWARD")?;
6859
6860 if let Some(l) = limit {
6861 f.write_str(" ")?;
6862 f.write_str(&l.to_string())?;
6863 }
6864 }
6865 FetchDirection::ForwardAll => f.write_str("FORWARD ALL")?,
6866 FetchDirection::Backward { limit } => {
6867 f.write_str("BACKWARD")?;
6868
6869 if let Some(l) = limit {
6870 f.write_str(" ")?;
6871 f.write_str(&l.to_string())?;
6872 }
6873 }
6874 FetchDirection::BackwardAll => f.write_str("BACKWARD ALL")?,
6875 };
6876
6877 Ok(())
6878 }
6879}
6880
6881#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6885#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6886#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6887pub enum FetchPosition {
6888 From,
6890 In,
6892}
6893
6894impl fmt::Display for FetchPosition {
6895 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6896 match self {
6897 FetchPosition::From => f.write_str("FROM")?,
6898 FetchPosition::In => f.write_str("IN")?,
6899 };
6900
6901 Ok(())
6902 }
6903}
6904
6905#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6907#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6908#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6909pub enum Action {
6910 AddSearchOptimization,
6912 Apply {
6914 apply_type: ActionApplyType,
6916 },
6917 ApplyBudget,
6919 AttachListing,
6921 AttachPolicy,
6923 Audit,
6925 BindServiceEndpoint,
6927 Connect,
6929 Create {
6931 obj_type: Option<ActionCreateObjectType>,
6933 },
6934 DatabaseRole {
6936 role: ObjectName,
6938 },
6939 Delete,
6941 Drop,
6943 EvolveSchema,
6945 Exec {
6947 obj_type: Option<ActionExecuteObjectType>,
6949 },
6950 Execute {
6952 obj_type: Option<ActionExecuteObjectType>,
6954 },
6955 Failover,
6957 ImportedPrivileges,
6959 ImportShare,
6961 Insert {
6963 columns: Option<Vec<Ident>>,
6965 },
6966 Manage {
6968 manage_type: ActionManageType,
6970 },
6971 ManageReleases,
6973 ManageVersions,
6975 Modify {
6977 modify_type: Option<ActionModifyType>,
6979 },
6980 Monitor {
6982 monitor_type: Option<ActionMonitorType>,
6984 },
6985 Operate,
6987 OverrideShareRestrictions,
6989 Ownership,
6991 PurchaseDataExchangeListing,
6993
6994 Read,
6996 ReadSession,
6998 References {
7000 columns: Option<Vec<Ident>>,
7002 },
7003 Replicate,
7005 ResolveAll,
7007 Role {
7009 role: ObjectName,
7011 },
7012 Select {
7014 columns: Option<Vec<Ident>>,
7016 },
7017 Temporary,
7019 Trigger,
7021 Truncate,
7023 Update {
7025 columns: Option<Vec<Ident>>,
7027 },
7028 Usage,
7030}
7031
7032impl fmt::Display for Action {
7033 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7034 match self {
7035 Action::AddSearchOptimization => f.write_str("ADD SEARCH OPTIMIZATION")?,
7036 Action::Apply { apply_type } => write!(f, "APPLY {apply_type}")?,
7037 Action::ApplyBudget => f.write_str("APPLYBUDGET")?,
7038 Action::AttachListing => f.write_str("ATTACH LISTING")?,
7039 Action::AttachPolicy => f.write_str("ATTACH POLICY")?,
7040 Action::Audit => f.write_str("AUDIT")?,
7041 Action::BindServiceEndpoint => f.write_str("BIND SERVICE ENDPOINT")?,
7042 Action::Connect => f.write_str("CONNECT")?,
7043 Action::Create { obj_type } => {
7044 f.write_str("CREATE")?;
7045 if let Some(obj_type) = obj_type {
7046 write!(f, " {obj_type}")?
7047 }
7048 }
7049 Action::DatabaseRole { role } => write!(f, "DATABASE ROLE {role}")?,
7050 Action::Delete => f.write_str("DELETE")?,
7051 Action::Drop => f.write_str("DROP")?,
7052 Action::EvolveSchema => f.write_str("EVOLVE SCHEMA")?,
7053 Action::Exec { obj_type } => {
7054 f.write_str("EXEC")?;
7055 if let Some(obj_type) = obj_type {
7056 write!(f, " {obj_type}")?
7057 }
7058 }
7059 Action::Execute { obj_type } => {
7060 f.write_str("EXECUTE")?;
7061 if let Some(obj_type) = obj_type {
7062 write!(f, " {obj_type}")?
7063 }
7064 }
7065 Action::Failover => f.write_str("FAILOVER")?,
7066 Action::ImportedPrivileges => f.write_str("IMPORTED PRIVILEGES")?,
7067 Action::ImportShare => f.write_str("IMPORT SHARE")?,
7068 Action::Insert { .. } => f.write_str("INSERT")?,
7069 Action::Manage { manage_type } => write!(f, "MANAGE {manage_type}")?,
7070 Action::ManageReleases => f.write_str("MANAGE RELEASES")?,
7071 Action::ManageVersions => f.write_str("MANAGE VERSIONS")?,
7072 Action::Modify { modify_type } => {
7073 write!(f, "MODIFY")?;
7074 if let Some(modify_type) = modify_type {
7075 write!(f, " {modify_type}")?;
7076 }
7077 }
7078 Action::Monitor { monitor_type } => {
7079 write!(f, "MONITOR")?;
7080 if let Some(monitor_type) = monitor_type {
7081 write!(f, " {monitor_type}")?
7082 }
7083 }
7084 Action::Operate => f.write_str("OPERATE")?,
7085 Action::OverrideShareRestrictions => f.write_str("OVERRIDE SHARE RESTRICTIONS")?,
7086 Action::Ownership => f.write_str("OWNERSHIP")?,
7087 Action::PurchaseDataExchangeListing => f.write_str("PURCHASE DATA EXCHANGE LISTING")?,
7088 Action::Read => f.write_str("READ")?,
7089 Action::ReadSession => f.write_str("READ SESSION")?,
7090 Action::References { .. } => f.write_str("REFERENCES")?,
7091 Action::Replicate => f.write_str("REPLICATE")?,
7092 Action::ResolveAll => f.write_str("RESOLVE ALL")?,
7093 Action::Role { role } => write!(f, "ROLE {role}")?,
7094 Action::Select { .. } => f.write_str("SELECT")?,
7095 Action::Temporary => f.write_str("TEMPORARY")?,
7096 Action::Trigger => f.write_str("TRIGGER")?,
7097 Action::Truncate => f.write_str("TRUNCATE")?,
7098 Action::Update { .. } => f.write_str("UPDATE")?,
7099 Action::Usage => f.write_str("USAGE")?,
7100 };
7101 match self {
7102 Action::Insert { columns }
7103 | Action::References { columns }
7104 | Action::Select { columns }
7105 | Action::Update { columns } => {
7106 if let Some(columns) = columns {
7107 write!(f, " ({})", display_comma_separated(columns))?;
7108 }
7109 }
7110 _ => (),
7111 };
7112 Ok(())
7113 }
7114}
7115
7116#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7117#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7118#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7119pub enum ActionCreateObjectType {
7122 Account,
7124 Application,
7126 ApplicationPackage,
7128 ComputePool,
7130 DataExchangeListing,
7132 Database,
7134 ExternalVolume,
7136 FailoverGroup,
7138 Integration,
7140 NetworkPolicy,
7142 OrganiationListing,
7144 ReplicationGroup,
7146 Role,
7148 Schema,
7150 Share,
7152 User,
7154 Warehouse,
7156}
7157
7158impl fmt::Display for ActionCreateObjectType {
7159 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7160 match self {
7161 ActionCreateObjectType::Account => write!(f, "ACCOUNT"),
7162 ActionCreateObjectType::Application => write!(f, "APPLICATION"),
7163 ActionCreateObjectType::ApplicationPackage => write!(f, "APPLICATION PACKAGE"),
7164 ActionCreateObjectType::ComputePool => write!(f, "COMPUTE POOL"),
7165 ActionCreateObjectType::DataExchangeListing => write!(f, "DATA EXCHANGE LISTING"),
7166 ActionCreateObjectType::Database => write!(f, "DATABASE"),
7167 ActionCreateObjectType::ExternalVolume => write!(f, "EXTERNAL VOLUME"),
7168 ActionCreateObjectType::FailoverGroup => write!(f, "FAILOVER GROUP"),
7169 ActionCreateObjectType::Integration => write!(f, "INTEGRATION"),
7170 ActionCreateObjectType::NetworkPolicy => write!(f, "NETWORK POLICY"),
7171 ActionCreateObjectType::OrganiationListing => write!(f, "ORGANIZATION LISTING"),
7172 ActionCreateObjectType::ReplicationGroup => write!(f, "REPLICATION GROUP"),
7173 ActionCreateObjectType::Role => write!(f, "ROLE"),
7174 ActionCreateObjectType::Schema => write!(f, "SCHEMA"),
7175 ActionCreateObjectType::Share => write!(f, "SHARE"),
7176 ActionCreateObjectType::User => write!(f, "USER"),
7177 ActionCreateObjectType::Warehouse => write!(f, "WAREHOUSE"),
7178 }
7179 }
7180}
7181
7182#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7183#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7184#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7185pub enum ActionApplyType {
7188 AggregationPolicy,
7190 AuthenticationPolicy,
7192 JoinPolicy,
7194 MaskingPolicy,
7196 PackagesPolicy,
7198 PasswordPolicy,
7200 ProjectionPolicy,
7202 RowAccessPolicy,
7204 SessionPolicy,
7206 Tag,
7208}
7209
7210impl fmt::Display for ActionApplyType {
7211 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7212 match self {
7213 ActionApplyType::AggregationPolicy => write!(f, "AGGREGATION POLICY"),
7214 ActionApplyType::AuthenticationPolicy => write!(f, "AUTHENTICATION POLICY"),
7215 ActionApplyType::JoinPolicy => write!(f, "JOIN POLICY"),
7216 ActionApplyType::MaskingPolicy => write!(f, "MASKING POLICY"),
7217 ActionApplyType::PackagesPolicy => write!(f, "PACKAGES POLICY"),
7218 ActionApplyType::PasswordPolicy => write!(f, "PASSWORD POLICY"),
7219 ActionApplyType::ProjectionPolicy => write!(f, "PROJECTION POLICY"),
7220 ActionApplyType::RowAccessPolicy => write!(f, "ROW ACCESS POLICY"),
7221 ActionApplyType::SessionPolicy => write!(f, "SESSION POLICY"),
7222 ActionApplyType::Tag => write!(f, "TAG"),
7223 }
7224 }
7225}
7226
7227#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7228#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7229#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7230pub enum ActionExecuteObjectType {
7233 Alert,
7235 DataMetricFunction,
7237 ManagedAlert,
7239 ManagedTask,
7241 Task,
7243}
7244
7245impl fmt::Display for ActionExecuteObjectType {
7246 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7247 match self {
7248 ActionExecuteObjectType::Alert => write!(f, "ALERT"),
7249 ActionExecuteObjectType::DataMetricFunction => write!(f, "DATA METRIC FUNCTION"),
7250 ActionExecuteObjectType::ManagedAlert => write!(f, "MANAGED ALERT"),
7251 ActionExecuteObjectType::ManagedTask => write!(f, "MANAGED TASK"),
7252 ActionExecuteObjectType::Task => write!(f, "TASK"),
7253 }
7254 }
7255}
7256
7257#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7258#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7259#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7260pub enum ActionManageType {
7263 AccountSupportCases,
7265 EventSharing,
7267 Grants,
7269 ListingAutoFulfillment,
7271 OrganizationSupportCases,
7273 UserSupportCases,
7275 Warehouses,
7277}
7278
7279impl fmt::Display for ActionManageType {
7280 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7281 match self {
7282 ActionManageType::AccountSupportCases => write!(f, "ACCOUNT SUPPORT CASES"),
7283 ActionManageType::EventSharing => write!(f, "EVENT SHARING"),
7284 ActionManageType::Grants => write!(f, "GRANTS"),
7285 ActionManageType::ListingAutoFulfillment => write!(f, "LISTING AUTO FULFILLMENT"),
7286 ActionManageType::OrganizationSupportCases => write!(f, "ORGANIZATION SUPPORT CASES"),
7287 ActionManageType::UserSupportCases => write!(f, "USER SUPPORT CASES"),
7288 ActionManageType::Warehouses => write!(f, "WAREHOUSES"),
7289 }
7290 }
7291}
7292
7293#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7294#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7295#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7296pub enum ActionModifyType {
7299 LogLevel,
7301 TraceLevel,
7303 SessionLogLevel,
7305 SessionTraceLevel,
7307}
7308
7309impl fmt::Display for ActionModifyType {
7310 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7311 match self {
7312 ActionModifyType::LogLevel => write!(f, "LOG LEVEL"),
7313 ActionModifyType::TraceLevel => write!(f, "TRACE LEVEL"),
7314 ActionModifyType::SessionLogLevel => write!(f, "SESSION LOG LEVEL"),
7315 ActionModifyType::SessionTraceLevel => write!(f, "SESSION TRACE LEVEL"),
7316 }
7317 }
7318}
7319
7320#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7321#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7322#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7323pub enum ActionMonitorType {
7326 Execution,
7328 Security,
7330 Usage,
7332}
7333
7334impl fmt::Display for ActionMonitorType {
7335 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7336 match self {
7337 ActionMonitorType::Execution => write!(f, "EXECUTION"),
7338 ActionMonitorType::Security => write!(f, "SECURITY"),
7339 ActionMonitorType::Usage => write!(f, "USAGE"),
7340 }
7341 }
7342}
7343
7344#[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 struct Grantee {
7349 pub grantee_type: GranteesType,
7351 pub name: Option<GranteeName>,
7353}
7354
7355impl fmt::Display for Grantee {
7356 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7357 match self.grantee_type {
7358 GranteesType::Role => {
7359 write!(f, "ROLE ")?;
7360 }
7361 GranteesType::Share => {
7362 write!(f, "SHARE ")?;
7363 }
7364 GranteesType::User => {
7365 write!(f, "USER ")?;
7366 }
7367 GranteesType::Group => {
7368 write!(f, "GROUP ")?;
7369 }
7370 GranteesType::Public => {
7371 write!(f, "PUBLIC ")?;
7372 }
7373 GranteesType::DatabaseRole => {
7374 write!(f, "DATABASE ROLE ")?;
7375 }
7376 GranteesType::Application => {
7377 write!(f, "APPLICATION ")?;
7378 }
7379 GranteesType::ApplicationRole => {
7380 write!(f, "APPLICATION ROLE ")?;
7381 }
7382 GranteesType::None => (),
7383 }
7384 if let Some(ref name) = self.name {
7385 name.fmt(f)?;
7386 }
7387 Ok(())
7388 }
7389}
7390
7391#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7392#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7393#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7394pub enum GranteesType {
7396 Role,
7398 Share,
7400 User,
7402 Group,
7404 Public,
7406 DatabaseRole,
7408 Application,
7410 ApplicationRole,
7412 None,
7414}
7415
7416#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7418#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7419#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7420pub enum GranteeName {
7421 ObjectName(ObjectName),
7423 UserHost {
7425 user: Ident,
7427 host: Ident,
7429 },
7430}
7431
7432impl fmt::Display for GranteeName {
7433 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7434 match self {
7435 GranteeName::ObjectName(name) => name.fmt(f),
7436 GranteeName::UserHost { user, host } => {
7437 write!(f, "{user}@{host}")
7438 }
7439 }
7440 }
7441}
7442
7443#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7445#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7446#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7447pub enum GrantObjects {
7448 AllSequencesInSchema {
7450 schemas: Vec<ObjectName>,
7452 },
7453 AllTablesInSchema {
7455 schemas: Vec<ObjectName>,
7457 },
7458 AllViewsInSchema {
7460 schemas: Vec<ObjectName>,
7462 },
7463 AllMaterializedViewsInSchema {
7465 schemas: Vec<ObjectName>,
7467 },
7468 AllExternalTablesInSchema {
7470 schemas: Vec<ObjectName>,
7472 },
7473 AllFunctionsInSchema {
7475 schemas: Vec<ObjectName>,
7477 },
7478 FutureSchemasInDatabase {
7480 databases: Vec<ObjectName>,
7482 },
7483 FutureTablesInSchema {
7485 schemas: Vec<ObjectName>,
7487 },
7488 FutureViewsInSchema {
7490 schemas: Vec<ObjectName>,
7492 },
7493 FutureExternalTablesInSchema {
7495 schemas: Vec<ObjectName>,
7497 },
7498 FutureMaterializedViewsInSchema {
7500 schemas: Vec<ObjectName>,
7502 },
7503 FutureSequencesInSchema {
7505 schemas: Vec<ObjectName>,
7507 },
7508 Databases(Vec<ObjectName>),
7510 Schemas(Vec<ObjectName>),
7512 Sequences(Vec<ObjectName>),
7514 Tables(Vec<ObjectName>),
7516 Views(Vec<ObjectName>),
7518 Warehouses(Vec<ObjectName>),
7520 Integrations(Vec<ObjectName>),
7522 ResourceMonitors(Vec<ObjectName>),
7524 Users(Vec<ObjectName>),
7526 ComputePools(Vec<ObjectName>),
7528 Connections(Vec<ObjectName>),
7530 FailoverGroup(Vec<ObjectName>),
7532 ReplicationGroup(Vec<ObjectName>),
7534 ExternalVolumes(Vec<ObjectName>),
7536 Procedure {
7542 name: ObjectName,
7544 arg_types: Vec<DataType>,
7546 },
7547
7548 Function {
7554 name: ObjectName,
7556 arg_types: Vec<DataType>,
7558 },
7559}
7560
7561impl fmt::Display for GrantObjects {
7562 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7563 match self {
7564 GrantObjects::Sequences(sequences) => {
7565 write!(f, "SEQUENCE {}", display_comma_separated(sequences))
7566 }
7567 GrantObjects::Databases(databases) => {
7568 write!(f, "DATABASE {}", display_comma_separated(databases))
7569 }
7570 GrantObjects::Schemas(schemas) => {
7571 write!(f, "SCHEMA {}", display_comma_separated(schemas))
7572 }
7573 GrantObjects::Tables(tables) => {
7574 write!(f, "{}", display_comma_separated(tables))
7575 }
7576 GrantObjects::Views(views) => {
7577 write!(f, "VIEW {}", display_comma_separated(views))
7578 }
7579 GrantObjects::Warehouses(warehouses) => {
7580 write!(f, "WAREHOUSE {}", display_comma_separated(warehouses))
7581 }
7582 GrantObjects::Integrations(integrations) => {
7583 write!(f, "INTEGRATION {}", display_comma_separated(integrations))
7584 }
7585 GrantObjects::AllSequencesInSchema { schemas } => {
7586 write!(
7587 f,
7588 "ALL SEQUENCES IN SCHEMA {}",
7589 display_comma_separated(schemas)
7590 )
7591 }
7592 GrantObjects::AllTablesInSchema { schemas } => {
7593 write!(
7594 f,
7595 "ALL TABLES IN SCHEMA {}",
7596 display_comma_separated(schemas)
7597 )
7598 }
7599 GrantObjects::AllExternalTablesInSchema { schemas } => {
7600 write!(
7601 f,
7602 "ALL EXTERNAL TABLES IN SCHEMA {}",
7603 display_comma_separated(schemas)
7604 )
7605 }
7606 GrantObjects::AllViewsInSchema { schemas } => {
7607 write!(
7608 f,
7609 "ALL VIEWS IN SCHEMA {}",
7610 display_comma_separated(schemas)
7611 )
7612 }
7613 GrantObjects::AllMaterializedViewsInSchema { schemas } => {
7614 write!(
7615 f,
7616 "ALL MATERIALIZED VIEWS IN SCHEMA {}",
7617 display_comma_separated(schemas)
7618 )
7619 }
7620 GrantObjects::AllFunctionsInSchema { schemas } => {
7621 write!(
7622 f,
7623 "ALL FUNCTIONS IN SCHEMA {}",
7624 display_comma_separated(schemas)
7625 )
7626 }
7627 GrantObjects::FutureSchemasInDatabase { databases } => {
7628 write!(
7629 f,
7630 "FUTURE SCHEMAS IN DATABASE {}",
7631 display_comma_separated(databases)
7632 )
7633 }
7634 GrantObjects::FutureTablesInSchema { schemas } => {
7635 write!(
7636 f,
7637 "FUTURE TABLES IN SCHEMA {}",
7638 display_comma_separated(schemas)
7639 )
7640 }
7641 GrantObjects::FutureExternalTablesInSchema { schemas } => {
7642 write!(
7643 f,
7644 "FUTURE EXTERNAL TABLES IN SCHEMA {}",
7645 display_comma_separated(schemas)
7646 )
7647 }
7648 GrantObjects::FutureViewsInSchema { schemas } => {
7649 write!(
7650 f,
7651 "FUTURE VIEWS IN SCHEMA {}",
7652 display_comma_separated(schemas)
7653 )
7654 }
7655 GrantObjects::FutureMaterializedViewsInSchema { schemas } => {
7656 write!(
7657 f,
7658 "FUTURE MATERIALIZED VIEWS IN SCHEMA {}",
7659 display_comma_separated(schemas)
7660 )
7661 }
7662 GrantObjects::FutureSequencesInSchema { schemas } => {
7663 write!(
7664 f,
7665 "FUTURE SEQUENCES IN SCHEMA {}",
7666 display_comma_separated(schemas)
7667 )
7668 }
7669 GrantObjects::ResourceMonitors(objects) => {
7670 write!(f, "RESOURCE MONITOR {}", display_comma_separated(objects))
7671 }
7672 GrantObjects::Users(objects) => {
7673 write!(f, "USER {}", display_comma_separated(objects))
7674 }
7675 GrantObjects::ComputePools(objects) => {
7676 write!(f, "COMPUTE POOL {}", display_comma_separated(objects))
7677 }
7678 GrantObjects::Connections(objects) => {
7679 write!(f, "CONNECTION {}", display_comma_separated(objects))
7680 }
7681 GrantObjects::FailoverGroup(objects) => {
7682 write!(f, "FAILOVER GROUP {}", display_comma_separated(objects))
7683 }
7684 GrantObjects::ReplicationGroup(objects) => {
7685 write!(f, "REPLICATION GROUP {}", display_comma_separated(objects))
7686 }
7687 GrantObjects::ExternalVolumes(objects) => {
7688 write!(f, "EXTERNAL VOLUME {}", display_comma_separated(objects))
7689 }
7690 GrantObjects::Procedure { name, arg_types } => {
7691 write!(f, "PROCEDURE {name}")?;
7692 if !arg_types.is_empty() {
7693 write!(f, "({})", display_comma_separated(arg_types))?;
7694 }
7695 Ok(())
7696 }
7697 GrantObjects::Function { name, arg_types } => {
7698 write!(f, "FUNCTION {name}")?;
7699 if !arg_types.is_empty() {
7700 write!(f, "({})", display_comma_separated(arg_types))?;
7701 }
7702 Ok(())
7703 }
7704 }
7705 }
7706}
7707
7708#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7712#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7713#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7714pub struct DenyStatement {
7715 pub privileges: Privileges,
7717 pub objects: GrantObjects,
7719 pub grantees: Vec<Grantee>,
7721 pub granted_by: Option<Ident>,
7723 pub cascade: Option<CascadeOption>,
7725}
7726
7727impl fmt::Display for DenyStatement {
7728 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7729 write!(f, "DENY {}", self.privileges)?;
7730 write!(f, " ON {}", self.objects)?;
7731 if !self.grantees.is_empty() {
7732 write!(f, " TO {}", display_comma_separated(&self.grantees))?;
7733 }
7734 if let Some(cascade) = &self.cascade {
7735 write!(f, " {cascade}")?;
7736 }
7737 if let Some(granted_by) = &self.granted_by {
7738 write!(f, " AS {granted_by}")?;
7739 }
7740 Ok(())
7741 }
7742}
7743
7744#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7746#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7747#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7748pub struct Assignment {
7749 pub target: AssignmentTarget,
7751 pub value: Expr,
7753}
7754
7755impl fmt::Display for Assignment {
7756 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7757 write!(f, "{} = {}", self.target, self.value)
7758 }
7759}
7760
7761#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7765#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7766#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7767pub enum AssignmentTarget {
7768 ColumnName(ObjectName),
7770 Tuple(Vec<ObjectName>),
7772}
7773
7774impl fmt::Display for AssignmentTarget {
7775 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7776 match self {
7777 AssignmentTarget::ColumnName(column) => write!(f, "{column}"),
7778 AssignmentTarget::Tuple(columns) => write!(f, "({})", display_comma_separated(columns)),
7779 }
7780 }
7781}
7782
7783#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7784#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7785#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7786pub enum FunctionArgExpr {
7788 Expr(Expr),
7790 QualifiedWildcard(ObjectName),
7792 Wildcard,
7794 WildcardWithOptions(WildcardAdditionalOptions),
7798}
7799
7800impl From<Expr> for FunctionArgExpr {
7801 fn from(wildcard_expr: Expr) -> Self {
7802 match wildcard_expr {
7803 Expr::QualifiedWildcard(prefix, _) => Self::QualifiedWildcard(prefix),
7804 Expr::Wildcard(_) => Self::Wildcard,
7805 expr => Self::Expr(expr),
7806 }
7807 }
7808}
7809
7810impl fmt::Display for FunctionArgExpr {
7811 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7812 match self {
7813 FunctionArgExpr::Expr(expr) => write!(f, "{expr}"),
7814 FunctionArgExpr::QualifiedWildcard(prefix) => write!(f, "{prefix}.*"),
7815 FunctionArgExpr::Wildcard => f.write_str("*"),
7816 FunctionArgExpr::WildcardWithOptions(opts) => write!(f, "*{opts}"),
7817 }
7818 }
7819}
7820
7821#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7822#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7823#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7824pub enum FunctionArgOperator {
7826 Equals,
7828 RightArrow,
7830 Assignment,
7832 Colon,
7834 Value,
7836}
7837
7838impl fmt::Display for FunctionArgOperator {
7839 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7840 match self {
7841 FunctionArgOperator::Equals => f.write_str("="),
7842 FunctionArgOperator::RightArrow => f.write_str("=>"),
7843 FunctionArgOperator::Assignment => f.write_str(":="),
7844 FunctionArgOperator::Colon => f.write_str(":"),
7845 FunctionArgOperator::Value => f.write_str("VALUE"),
7846 }
7847 }
7848}
7849
7850#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7851#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7852#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7853pub enum FunctionArg {
7855 Named {
7859 name: Ident,
7861 arg: FunctionArgExpr,
7863 operator: FunctionArgOperator,
7865 },
7866 ExprNamed {
7870 name: Expr,
7872 arg: FunctionArgExpr,
7874 operator: FunctionArgOperator,
7876 },
7877 Unnamed(FunctionArgExpr),
7879}
7880
7881impl fmt::Display for FunctionArg {
7882 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7883 match self {
7884 FunctionArg::Named {
7885 name,
7886 arg,
7887 operator,
7888 } => write!(f, "{name} {operator} {arg}"),
7889 FunctionArg::ExprNamed {
7890 name,
7891 arg,
7892 operator,
7893 } => write!(f, "{name} {operator} {arg}"),
7894 FunctionArg::Unnamed(unnamed_arg) => write!(f, "{unnamed_arg}"),
7895 }
7896 }
7897}
7898
7899#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7900#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7901#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7902pub enum CloseCursor {
7904 All,
7906 Specific {
7908 name: Ident,
7910 },
7911}
7912
7913impl fmt::Display for CloseCursor {
7914 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7915 match self {
7916 CloseCursor::All => write!(f, "ALL"),
7917 CloseCursor::Specific { name } => write!(f, "{name}"),
7918 }
7919 }
7920}
7921
7922#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7924#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7925#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7926pub struct DropDomain {
7927 pub if_exists: bool,
7929 pub name: ObjectName,
7931 pub drop_behavior: Option<DropBehavior>,
7933}
7934
7935#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7939#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7940#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7941pub struct TypedString {
7942 pub data_type: DataType,
7944 pub value: ValueWithSpan,
7947 pub uses_odbc_syntax: bool,
7958}
7959
7960impl fmt::Display for TypedString {
7961 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7962 let data_type = &self.data_type;
7963 let value = &self.value;
7964 match self.uses_odbc_syntax {
7965 false => {
7966 write!(f, "{data_type}")?;
7967 write!(f, " {value}")
7968 }
7969 true => {
7970 let prefix = match data_type {
7971 DataType::Date => "d",
7972 DataType::Time(..) => "t",
7973 DataType::Timestamp(..) => "ts",
7974 _ => "?",
7975 };
7976 write!(f, "{{{prefix} {value}}}")
7977 }
7978 }
7979 }
7980}
7981
7982#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7984#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7985#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7986pub struct Function {
7987 pub name: ObjectName,
7989 pub uses_odbc_syntax: bool,
7998 pub parameters: FunctionArguments,
8008 pub args: FunctionArguments,
8011 pub filter: Option<Box<Expr>>,
8013 pub null_treatment: Option<NullTreatment>,
8022 pub over: Option<WindowType>,
8024 pub within_group: Vec<OrderByExpr>,
8032}
8033
8034impl fmt::Display for Function {
8035 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8036 if self.uses_odbc_syntax {
8037 write!(f, "{{fn ")?;
8038 }
8039
8040 write!(f, "{}{}{}", self.name, self.parameters, self.args)?;
8041
8042 if !self.within_group.is_empty() {
8043 write!(
8044 f,
8045 " WITHIN GROUP (ORDER BY {})",
8046 display_comma_separated(&self.within_group)
8047 )?;
8048 }
8049
8050 if let Some(filter_cond) = &self.filter {
8051 write!(f, " FILTER (WHERE {filter_cond})")?;
8052 }
8053
8054 if let Some(null_treatment) = &self.null_treatment {
8055 write!(f, " {null_treatment}")?;
8056 }
8057
8058 if let Some(o) = &self.over {
8059 f.write_str(" OVER ")?;
8060 o.fmt(f)?;
8061 }
8062
8063 if self.uses_odbc_syntax {
8064 write!(f, "}}")?;
8065 }
8066
8067 Ok(())
8068 }
8069}
8070
8071#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8073#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8074#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8075pub enum FunctionArguments {
8076 None,
8079 Subquery(Box<Query>),
8082 List(FunctionArgumentList),
8085}
8086
8087impl fmt::Display for FunctionArguments {
8088 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8089 match self {
8090 FunctionArguments::None => Ok(()),
8091 FunctionArguments::Subquery(query) => write!(f, "({query})"),
8092 FunctionArguments::List(args) => write!(f, "({args})"),
8093 }
8094 }
8095}
8096
8097#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8099#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8100#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8101pub struct FunctionArgumentList {
8102 pub duplicate_treatment: Option<DuplicateTreatment>,
8104 pub args: Vec<FunctionArg>,
8106 pub clauses: Vec<FunctionArgumentClause>,
8108}
8109
8110impl fmt::Display for FunctionArgumentList {
8111 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8112 if let Some(duplicate_treatment) = self.duplicate_treatment {
8113 write!(f, "{duplicate_treatment} ")?;
8114 }
8115 write!(f, "{}", display_comma_separated(&self.args))?;
8116 if !self.clauses.is_empty() {
8117 if !self.args.is_empty() {
8118 write!(f, " ")?;
8119 }
8120 write!(f, "{}", display_separated(&self.clauses, " "))?;
8121 }
8122 Ok(())
8123 }
8124}
8125
8126#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8127#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8128#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8129pub enum FunctionArgumentClause {
8131 IgnoreOrRespectNulls(NullTreatment),
8140 OrderBy(Vec<OrderByExpr>),
8144 Limit(Expr),
8146 OnOverflow(ListAggOnOverflow),
8150 Having(HavingBound),
8159 Separator(ValueWithSpan),
8163 JsonNullClause(JsonNullClause),
8169 JsonReturningClause(JsonReturningClause),
8173}
8174
8175impl fmt::Display for FunctionArgumentClause {
8176 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8177 match self {
8178 FunctionArgumentClause::IgnoreOrRespectNulls(null_treatment) => {
8179 write!(f, "{null_treatment}")
8180 }
8181 FunctionArgumentClause::OrderBy(order_by) => {
8182 write!(f, "ORDER BY {}", display_comma_separated(order_by))
8183 }
8184 FunctionArgumentClause::Limit(limit) => write!(f, "LIMIT {limit}"),
8185 FunctionArgumentClause::OnOverflow(on_overflow) => write!(f, "{on_overflow}"),
8186 FunctionArgumentClause::Having(bound) => write!(f, "{bound}"),
8187 FunctionArgumentClause::Separator(sep) => write!(f, "SEPARATOR {sep}"),
8188 FunctionArgumentClause::JsonNullClause(null_clause) => write!(f, "{null_clause}"),
8189 FunctionArgumentClause::JsonReturningClause(returning_clause) => {
8190 write!(f, "{returning_clause}")
8191 }
8192 }
8193 }
8194}
8195
8196#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8198#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8199#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8200pub struct Method {
8201 pub expr: Box<Expr>,
8203 pub method_chain: Vec<Function>,
8206}
8207
8208impl fmt::Display for Method {
8209 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8210 write!(
8211 f,
8212 "{}.{}",
8213 self.expr,
8214 display_separated(&self.method_chain, ".")
8215 )
8216 }
8217}
8218
8219#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8220#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8221#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8222pub enum DuplicateTreatment {
8224 Distinct,
8226 All,
8228}
8229
8230impl fmt::Display for DuplicateTreatment {
8231 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8232 match self {
8233 DuplicateTreatment::Distinct => write!(f, "DISTINCT"),
8234 DuplicateTreatment::All => write!(f, "ALL"),
8235 }
8236 }
8237}
8238
8239#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8240#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8241#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8242pub enum AnalyzeFormatKind {
8244 Keyword(AnalyzeFormat),
8246 Assignment(AnalyzeFormat),
8248}
8249
8250impl fmt::Display for AnalyzeFormatKind {
8251 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8252 match self {
8253 AnalyzeFormatKind::Keyword(format) => write!(f, "FORMAT {format}"),
8254 AnalyzeFormatKind::Assignment(format) => write!(f, "FORMAT={format}"),
8255 }
8256 }
8257}
8258
8259#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8260#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8261#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8262pub enum AnalyzeFormat {
8264 TEXT,
8266 GRAPHVIZ,
8268 JSON,
8270 TRADITIONAL,
8272 TREE,
8274}
8275
8276impl fmt::Display for AnalyzeFormat {
8277 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
8278 f.write_str(match self {
8279 AnalyzeFormat::TEXT => "TEXT",
8280 AnalyzeFormat::GRAPHVIZ => "GRAPHVIZ",
8281 AnalyzeFormat::JSON => "JSON",
8282 AnalyzeFormat::TRADITIONAL => "TRADITIONAL",
8283 AnalyzeFormat::TREE => "TREE",
8284 })
8285 }
8286}
8287
8288#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8290#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8291#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8292pub enum FileFormat {
8293 TEXTFILE,
8295 SEQUENCEFILE,
8297 ORC,
8299 PARQUET,
8301 AVRO,
8303 RCFILE,
8305 JSONFILE,
8307}
8308
8309impl fmt::Display for FileFormat {
8310 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8311 use self::FileFormat::*;
8312 f.write_str(match self {
8313 TEXTFILE => "TEXTFILE",
8314 SEQUENCEFILE => "SEQUENCEFILE",
8315 ORC => "ORC",
8316 PARQUET => "PARQUET",
8317 AVRO => "AVRO",
8318 RCFILE => "RCFILE",
8319 JSONFILE => "JSONFILE",
8320 })
8321 }
8322}
8323
8324#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8326#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8327#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8328pub enum ListAggOnOverflow {
8329 Error,
8331
8332 Truncate {
8334 filler: Option<Box<Expr>>,
8336 with_count: bool,
8338 },
8339}
8340
8341impl fmt::Display for ListAggOnOverflow {
8342 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8343 write!(f, "ON OVERFLOW")?;
8344 match self {
8345 ListAggOnOverflow::Error => write!(f, " ERROR"),
8346 ListAggOnOverflow::Truncate { filler, with_count } => {
8347 write!(f, " TRUNCATE")?;
8348 if let Some(filler) = filler {
8349 write!(f, " {filler}")?;
8350 }
8351 if *with_count {
8352 write!(f, " WITH")?;
8353 } else {
8354 write!(f, " WITHOUT")?;
8355 }
8356 write!(f, " COUNT")
8357 }
8358 }
8359 }
8360}
8361
8362#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8364#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8365#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8366pub struct HavingBound(pub HavingBoundKind, pub Expr);
8367
8368impl fmt::Display for HavingBound {
8369 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8370 write!(f, "HAVING {} {}", self.0, self.1)
8371 }
8372}
8373
8374#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8375#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8376#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8377pub enum HavingBoundKind {
8379 Min,
8381 Max,
8383}
8384
8385impl fmt::Display for HavingBoundKind {
8386 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8387 match self {
8388 HavingBoundKind::Min => write!(f, "MIN"),
8389 HavingBoundKind::Max => write!(f, "MAX"),
8390 }
8391 }
8392}
8393
8394#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8395#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8396#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8397pub enum ObjectType {
8399 Collation,
8401 Table,
8403 View,
8405 MaterializedView,
8407 Index,
8409 Schema,
8411 Database,
8413 Role,
8415 Sequence,
8417 Stage,
8419 Type,
8421 User,
8423 Stream,
8425}
8426
8427impl fmt::Display for ObjectType {
8428 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8429 f.write_str(match self {
8430 ObjectType::Collation => "COLLATION",
8431 ObjectType::Table => "TABLE",
8432 ObjectType::View => "VIEW",
8433 ObjectType::MaterializedView => "MATERIALIZED VIEW",
8434 ObjectType::Index => "INDEX",
8435 ObjectType::Schema => "SCHEMA",
8436 ObjectType::Database => "DATABASE",
8437 ObjectType::Role => "ROLE",
8438 ObjectType::Sequence => "SEQUENCE",
8439 ObjectType::Stage => "STAGE",
8440 ObjectType::Type => "TYPE",
8441 ObjectType::User => "USER",
8442 ObjectType::Stream => "STREAM",
8443 })
8444 }
8445}
8446
8447#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8448#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8449#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8450pub enum KillType {
8452 Connection,
8454 Query,
8456 Mutation,
8458}
8459
8460impl fmt::Display for KillType {
8461 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8462 f.write_str(match self {
8463 KillType::Connection => "CONNECTION",
8465 KillType::Query => "QUERY",
8466 KillType::Mutation => "MUTATION",
8468 })
8469 }
8470}
8471
8472#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8473#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8474#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8475pub enum HiveDistributionStyle {
8477 PARTITIONED {
8479 columns: Vec<ColumnDef>,
8481 },
8482 SKEWED {
8484 columns: Vec<ColumnDef>,
8486 on: Vec<ColumnDef>,
8488 stored_as_directories: bool,
8490 },
8491 NONE,
8493}
8494
8495#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8496#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8497#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8498pub enum HiveRowFormat {
8500 SERDE {
8502 class: String,
8504 },
8505 DELIMITED {
8507 delimiters: Vec<HiveRowDelimiter>,
8509 },
8510}
8511
8512#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8513#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8514#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8515pub struct HiveLoadDataFormat {
8517 pub serde: Expr,
8519 pub input_format: Expr,
8521}
8522
8523#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8524#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8525#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8526pub struct HiveRowDelimiter {
8528 pub delimiter: HiveDelimiter,
8530 pub char: Ident,
8532}
8533
8534impl fmt::Display for HiveRowDelimiter {
8535 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8536 write!(f, "{} ", self.delimiter)?;
8537 write!(f, "{}", self.char)
8538 }
8539}
8540
8541#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8542#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8543#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8544pub enum HiveDelimiter {
8546 FieldsTerminatedBy,
8548 FieldsEscapedBy,
8550 CollectionItemsTerminatedBy,
8552 MapKeysTerminatedBy,
8554 LinesTerminatedBy,
8556 NullDefinedAs,
8558}
8559
8560impl fmt::Display for HiveDelimiter {
8561 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8562 use HiveDelimiter::*;
8563 f.write_str(match self {
8564 FieldsTerminatedBy => "FIELDS TERMINATED BY",
8565 FieldsEscapedBy => "ESCAPED BY",
8566 CollectionItemsTerminatedBy => "COLLECTION ITEMS TERMINATED BY",
8567 MapKeysTerminatedBy => "MAP KEYS TERMINATED BY",
8568 LinesTerminatedBy => "LINES TERMINATED BY",
8569 NullDefinedAs => "NULL DEFINED AS",
8570 })
8571 }
8572}
8573
8574#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8575#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8576#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8577pub enum HiveDescribeFormat {
8579 Extended,
8581 Formatted,
8583}
8584
8585impl fmt::Display for HiveDescribeFormat {
8586 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8587 use HiveDescribeFormat::*;
8588 f.write_str(match self {
8589 Extended => "EXTENDED",
8590 Formatted => "FORMATTED",
8591 })
8592 }
8593}
8594
8595#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8596#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8597#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8598pub enum DescribeAlias {
8600 Describe,
8602 Explain,
8604 Desc,
8606}
8607
8608impl fmt::Display for DescribeAlias {
8609 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8610 use DescribeAlias::*;
8611 f.write_str(match self {
8612 Describe => "DESCRIBE",
8613 Explain => "EXPLAIN",
8614 Desc => "DESC",
8615 })
8616 }
8617}
8618
8619#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8620#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8621#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8622#[allow(clippy::large_enum_variant)]
8623pub enum HiveIOFormat {
8625 IOF {
8627 input_format: Expr,
8629 output_format: Expr,
8631 },
8632 FileFormat {
8634 format: FileFormat,
8636 },
8637}
8638
8639#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Default)]
8640#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8641#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8642pub struct HiveFormat {
8644 pub row_format: Option<HiveRowFormat>,
8646 pub serde_properties: Option<Vec<SqlOption>>,
8648 pub storage: Option<HiveIOFormat>,
8650 pub location: Option<String>,
8652}
8653
8654#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8655#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8656#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8657pub struct ClusteredIndex {
8659 pub name: Ident,
8661 pub asc: Option<bool>,
8663}
8664
8665impl fmt::Display for ClusteredIndex {
8666 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8667 write!(f, "{}", self.name)?;
8668 match self.asc {
8669 Some(true) => write!(f, " ASC"),
8670 Some(false) => write!(f, " DESC"),
8671 _ => Ok(()),
8672 }
8673 }
8674}
8675
8676#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8677#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8678#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8679pub enum TableOptionsClustered {
8681 ColumnstoreIndex,
8683 ColumnstoreIndexOrder(Vec<Ident>),
8685 Index(Vec<ClusteredIndex>),
8687}
8688
8689impl fmt::Display for TableOptionsClustered {
8690 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8691 match self {
8692 TableOptionsClustered::ColumnstoreIndex => {
8693 write!(f, "CLUSTERED COLUMNSTORE INDEX")
8694 }
8695 TableOptionsClustered::ColumnstoreIndexOrder(values) => {
8696 write!(
8697 f,
8698 "CLUSTERED COLUMNSTORE INDEX ORDER ({})",
8699 display_comma_separated(values)
8700 )
8701 }
8702 TableOptionsClustered::Index(values) => {
8703 write!(f, "CLUSTERED INDEX ({})", display_comma_separated(values))
8704 }
8705 }
8706 }
8707}
8708
8709#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
8711#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8712#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8713pub enum PartitionRangeDirection {
8714 Left,
8716 Right,
8718}
8719
8720#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8721#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8722#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8723pub enum SqlOption {
8725 Clustered(TableOptionsClustered),
8729 Ident(Ident),
8733 KeyValue {
8737 key: Ident,
8739 value: Expr,
8741 },
8742 Partition {
8749 column_name: Ident,
8751 range_direction: Option<PartitionRangeDirection>,
8753 for_values: Vec<Expr>,
8755 },
8756 Comment(CommentDef),
8758 TableSpace(TablespaceOption),
8761 NamedParenthesizedList(NamedParenthesizedList),
8768}
8769
8770impl fmt::Display for SqlOption {
8771 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8772 match self {
8773 SqlOption::Clustered(c) => write!(f, "{c}"),
8774 SqlOption::Ident(ident) => {
8775 write!(f, "{ident}")
8776 }
8777 SqlOption::KeyValue { key: name, value } => {
8778 write!(f, "{name} = {value}")
8779 }
8780 SqlOption::Partition {
8781 column_name,
8782 range_direction,
8783 for_values,
8784 } => {
8785 let direction = match range_direction {
8786 Some(PartitionRangeDirection::Left) => " LEFT",
8787 Some(PartitionRangeDirection::Right) => " RIGHT",
8788 None => "",
8789 };
8790
8791 write!(
8792 f,
8793 "PARTITION ({} RANGE{} FOR VALUES ({}))",
8794 column_name,
8795 direction,
8796 display_comma_separated(for_values)
8797 )
8798 }
8799 SqlOption::TableSpace(tablespace_option) => {
8800 write!(f, "TABLESPACE {}", tablespace_option.name)?;
8801 match tablespace_option.storage {
8802 Some(StorageType::Disk) => write!(f, " STORAGE DISK"),
8803 Some(StorageType::Memory) => write!(f, " STORAGE MEMORY"),
8804 None => Ok(()),
8805 }
8806 }
8807 SqlOption::Comment(comment) => match comment {
8808 CommentDef::WithEq(comment) => {
8809 write!(f, "COMMENT = '{comment}'")
8810 }
8811 CommentDef::WithoutEq(comment) => {
8812 write!(f, "COMMENT '{comment}'")
8813 }
8814 },
8815 SqlOption::NamedParenthesizedList(value) => {
8816 write!(f, "{} = ", value.key)?;
8817 if let Some(key) = &value.name {
8818 write!(f, "{key}")?;
8819 }
8820 if !value.values.is_empty() {
8821 write!(f, "({})", display_comma_separated(&value.values))?
8822 }
8823 Ok(())
8824 }
8825 }
8826 }
8827}
8828
8829#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
8830#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8831#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8832pub enum StorageType {
8834 Disk,
8836 Memory,
8838}
8839
8840#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
8841#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8842#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8843pub struct TablespaceOption {
8846 pub name: String,
8848 pub storage: Option<StorageType>,
8850}
8851
8852#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8853#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8854#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8855pub struct SecretOption {
8857 pub key: Ident,
8859 pub value: Ident,
8861}
8862
8863impl fmt::Display for SecretOption {
8864 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8865 write!(f, "{} {}", self.key, self.value)
8866 }
8867}
8868
8869#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8873#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8874#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8875pub struct CreateServerStatement {
8876 pub name: ObjectName,
8878 pub if_not_exists: bool,
8880 pub server_type: Option<Ident>,
8882 pub version: Option<Ident>,
8884 pub foreign_data_wrapper: ObjectName,
8886 pub options: Option<Vec<CreateServerOption>>,
8888}
8889
8890impl fmt::Display for CreateServerStatement {
8891 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8892 let CreateServerStatement {
8893 name,
8894 if_not_exists,
8895 server_type,
8896 version,
8897 foreign_data_wrapper,
8898 options,
8899 } = self;
8900
8901 write!(
8902 f,
8903 "CREATE SERVER {if_not_exists}{name} ",
8904 if_not_exists = if *if_not_exists { "IF NOT EXISTS " } else { "" },
8905 )?;
8906
8907 if let Some(st) = server_type {
8908 write!(f, "TYPE {st} ")?;
8909 }
8910
8911 if let Some(v) = version {
8912 write!(f, "VERSION {v} ")?;
8913 }
8914
8915 write!(f, "FOREIGN DATA WRAPPER {foreign_data_wrapper}")?;
8916
8917 if let Some(o) = options {
8918 write!(f, " OPTIONS ({o})", o = display_comma_separated(o))?;
8919 }
8920
8921 Ok(())
8922 }
8923}
8924
8925#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8927#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8928#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8929pub struct CreateServerOption {
8930 pub key: Ident,
8932 pub value: Ident,
8934}
8935
8936impl fmt::Display for CreateServerOption {
8937 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8938 write!(f, "{} {}", self.key, self.value)
8939 }
8940}
8941
8942#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8943#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8944#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8945pub enum AttachDuckDBDatabaseOption {
8947 ReadOnly(Option<bool>),
8949 Type(Ident),
8951}
8952
8953impl fmt::Display for AttachDuckDBDatabaseOption {
8954 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8955 match self {
8956 AttachDuckDBDatabaseOption::ReadOnly(Some(true)) => write!(f, "READ_ONLY true"),
8957 AttachDuckDBDatabaseOption::ReadOnly(Some(false)) => write!(f, "READ_ONLY false"),
8958 AttachDuckDBDatabaseOption::ReadOnly(None) => write!(f, "READ_ONLY"),
8959 AttachDuckDBDatabaseOption::Type(t) => write!(f, "TYPE {t}"),
8960 }
8961 }
8962}
8963
8964#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8965#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8966#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8967pub enum TransactionMode {
8969 AccessMode(TransactionAccessMode),
8971 IsolationLevel(TransactionIsolationLevel),
8973}
8974
8975impl fmt::Display for TransactionMode {
8976 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8977 use TransactionMode::*;
8978 match self {
8979 AccessMode(access_mode) => write!(f, "{access_mode}"),
8980 IsolationLevel(iso_level) => write!(f, "ISOLATION LEVEL {iso_level}"),
8981 }
8982 }
8983}
8984
8985#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
8986#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8987#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
8988pub enum TransactionAccessMode {
8990 ReadOnly,
8992 ReadWrite,
8994}
8995
8996impl fmt::Display for TransactionAccessMode {
8997 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8998 use TransactionAccessMode::*;
8999 f.write_str(match self {
9000 ReadOnly => "READ ONLY",
9001 ReadWrite => "READ WRITE",
9002 })
9003 }
9004}
9005
9006#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9007#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9008#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9009pub enum TransactionIsolationLevel {
9011 ReadUncommitted,
9013 ReadCommitted,
9015 RepeatableRead,
9017 Serializable,
9019 Snapshot,
9021}
9022
9023impl fmt::Display for TransactionIsolationLevel {
9024 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9025 use TransactionIsolationLevel::*;
9026 f.write_str(match self {
9027 ReadUncommitted => "READ UNCOMMITTED",
9028 ReadCommitted => "READ COMMITTED",
9029 RepeatableRead => "REPEATABLE READ",
9030 Serializable => "SERIALIZABLE",
9031 Snapshot => "SNAPSHOT",
9032 })
9033 }
9034}
9035
9036#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9041#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9042#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9043pub enum TransactionModifier {
9044 Deferred,
9046 Immediate,
9048 Exclusive,
9050 Try,
9052 Catch,
9054}
9055
9056impl fmt::Display for TransactionModifier {
9057 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9058 use TransactionModifier::*;
9059 f.write_str(match self {
9060 Deferred => "DEFERRED",
9061 Immediate => "IMMEDIATE",
9062 Exclusive => "EXCLUSIVE",
9063 Try => "TRY",
9064 Catch => "CATCH",
9065 })
9066 }
9067}
9068
9069#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9070#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9071#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9072pub enum ShowStatementFilter {
9074 Like(String),
9076 ILike(String),
9078 Where(Expr),
9080 NoKeyword(String),
9082}
9083
9084impl fmt::Display for ShowStatementFilter {
9085 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9086 use ShowStatementFilter::*;
9087 match self {
9088 Like(pattern) => write!(f, "LIKE '{}'", value::escape_single_quote_string(pattern)),
9089 ILike(pattern) => write!(f, "ILIKE {}", value::escape_single_quote_string(pattern)),
9090 Where(expr) => write!(f, "WHERE {expr}"),
9091 NoKeyword(pattern) => write!(f, "'{}'", value::escape_single_quote_string(pattern)),
9092 }
9093 }
9094}
9095
9096#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9097#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9098#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9099pub enum ShowStatementInClause {
9101 IN,
9103 FROM,
9105}
9106
9107impl fmt::Display for ShowStatementInClause {
9108 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9109 use ShowStatementInClause::*;
9110 match self {
9111 FROM => write!(f, "FROM"),
9112 IN => write!(f, "IN"),
9113 }
9114 }
9115}
9116
9117#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9122#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9123#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9124pub enum SqliteOnConflict {
9125 Rollback,
9127 Abort,
9129 Fail,
9131 Ignore,
9133 Replace,
9135}
9136
9137impl fmt::Display for SqliteOnConflict {
9138 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9139 use SqliteOnConflict::*;
9140 match self {
9141 Rollback => write!(f, "OR ROLLBACK"),
9142 Abort => write!(f, "OR ABORT"),
9143 Fail => write!(f, "OR FAIL"),
9144 Ignore => write!(f, "OR IGNORE"),
9145 Replace => write!(f, "OR REPLACE"),
9146 }
9147 }
9148}
9149
9150#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9156#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9157#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9158pub enum MysqlInsertPriority {
9159 LowPriority,
9161 Delayed,
9163 HighPriority,
9165}
9166
9167impl fmt::Display for crate::ast::MysqlInsertPriority {
9168 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9169 use MysqlInsertPriority::*;
9170 match self {
9171 LowPriority => write!(f, "LOW_PRIORITY"),
9172 Delayed => write!(f, "DELAYED"),
9173 HighPriority => write!(f, "HIGH_PRIORITY"),
9174 }
9175 }
9176}
9177
9178#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9179#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9180#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9181pub enum CopySource {
9183 Table {
9185 table_name: ObjectName,
9187 columns: Vec<Ident>,
9190 },
9191 Query(Box<Query>),
9193}
9194
9195#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9196#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9197#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9198pub enum CopyTarget {
9200 Stdin,
9202 Stdout,
9204 File {
9206 filename: String,
9208 },
9209 Program {
9211 command: String,
9213 },
9214}
9215
9216impl fmt::Display for CopyTarget {
9217 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9218 use CopyTarget::*;
9219 match self {
9220 Stdin => write!(f, "STDIN"),
9221 Stdout => write!(f, "STDOUT"),
9222 File { filename } => write!(f, "'{}'", value::escape_single_quote_string(filename)),
9223 Program { command } => write!(
9224 f,
9225 "PROGRAM '{}'",
9226 value::escape_single_quote_string(command)
9227 ),
9228 }
9229 }
9230}
9231
9232#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9233#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9234#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9235pub enum OnCommit {
9237 DeleteRows,
9239 PreserveRows,
9241 Drop,
9243}
9244
9245#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9249#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9250#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9251pub enum CopyOption {
9252 Format(Ident),
9254 Freeze(bool),
9256 Delimiter(char),
9258 Null(String),
9260 Header(bool),
9262 Quote(char),
9264 Escape(char),
9266 ForceQuote(Vec<Ident>),
9268 ForceNotNull(Vec<Ident>),
9270 ForceNull(Vec<Ident>),
9272 Encoding(String),
9274}
9275
9276impl fmt::Display for CopyOption {
9277 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9278 use CopyOption::*;
9279 match self {
9280 Format(name) => write!(f, "FORMAT {name}"),
9281 Freeze(true) => write!(f, "FREEZE"),
9282 Freeze(false) => write!(f, "FREEZE FALSE"),
9283 Delimiter(char) => write!(f, "DELIMITER '{char}'"),
9284 Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)),
9285 Header(true) => write!(f, "HEADER"),
9286 Header(false) => write!(f, "HEADER FALSE"),
9287 Quote(char) => write!(f, "QUOTE '{char}'"),
9288 Escape(char) => write!(f, "ESCAPE '{char}'"),
9289 ForceQuote(columns) => write!(f, "FORCE_QUOTE ({})", display_comma_separated(columns)),
9290 ForceNotNull(columns) => {
9291 write!(f, "FORCE_NOT_NULL ({})", display_comma_separated(columns))
9292 }
9293 ForceNull(columns) => write!(f, "FORCE_NULL ({})", display_comma_separated(columns)),
9294 Encoding(name) => write!(f, "ENCODING '{}'", value::escape_single_quote_string(name)),
9295 }
9296 }
9297}
9298
9299#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9304#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9305#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9306pub enum CopyLegacyOption {
9307 AcceptAnyDate,
9309 AcceptInvChars(Option<String>),
9311 AddQuotes,
9313 AllowOverwrite,
9315 Binary,
9317 BlankAsNull,
9319 Bzip2,
9321 CleanPath,
9323 CompUpdate {
9325 preset: bool,
9327 enabled: Option<bool>,
9329 },
9330 Csv(Vec<CopyLegacyCsvOption>),
9332 DateFormat(Option<String>),
9334 Delimiter(char),
9336 EmptyAsNull,
9338 Encrypted {
9340 auto: bool,
9342 },
9343 Escape,
9345 Extension(String),
9347 FixedWidth(String),
9349 Gzip,
9351 Header,
9353 IamRole(IamRoleKind),
9355 IgnoreHeader(u64),
9357 Json(Option<String>),
9359 Manifest {
9361 verbose: bool,
9363 },
9364 MaxFileSize(FileSize),
9366 Null(String),
9368 Parallel(Option<bool>),
9370 Parquet,
9372 PartitionBy(UnloadPartitionBy),
9374 Region(String),
9376 RemoveQuotes,
9378 RowGroupSize(FileSize),
9380 StatUpdate(Option<bool>),
9382 TimeFormat(Option<String>),
9384 TruncateColumns,
9386 Zstd,
9388 Credentials(String),
9391}
9392
9393impl fmt::Display for CopyLegacyOption {
9394 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9395 use CopyLegacyOption::*;
9396 match self {
9397 AcceptAnyDate => write!(f, "ACCEPTANYDATE"),
9398 AcceptInvChars(ch) => {
9399 write!(f, "ACCEPTINVCHARS")?;
9400 if let Some(ch) = ch {
9401 write!(f, " '{}'", value::escape_single_quote_string(ch))?;
9402 }
9403 Ok(())
9404 }
9405 AddQuotes => write!(f, "ADDQUOTES"),
9406 AllowOverwrite => write!(f, "ALLOWOVERWRITE"),
9407 Binary => write!(f, "BINARY"),
9408 BlankAsNull => write!(f, "BLANKSASNULL"),
9409 Bzip2 => write!(f, "BZIP2"),
9410 CleanPath => write!(f, "CLEANPATH"),
9411 CompUpdate { preset, enabled } => {
9412 write!(f, "COMPUPDATE")?;
9413 if *preset {
9414 write!(f, " PRESET")?;
9415 } else if let Some(enabled) = enabled {
9416 write!(
9417 f,
9418 "{}",
9419 match enabled {
9420 true => " TRUE",
9421 false => " FALSE",
9422 }
9423 )?;
9424 }
9425 Ok(())
9426 }
9427 Csv(opts) => {
9428 write!(f, "CSV")?;
9429 if !opts.is_empty() {
9430 write!(f, " {}", display_separated(opts, " "))?;
9431 }
9432 Ok(())
9433 }
9434 DateFormat(fmt) => {
9435 write!(f, "DATEFORMAT")?;
9436 if let Some(fmt) = fmt {
9437 write!(f, " '{}'", value::escape_single_quote_string(fmt))?;
9438 }
9439 Ok(())
9440 }
9441 Delimiter(char) => write!(f, "DELIMITER '{char}'"),
9442 EmptyAsNull => write!(f, "EMPTYASNULL"),
9443 Encrypted { auto } => write!(f, "ENCRYPTED{}", if *auto { " AUTO" } else { "" }),
9444 Escape => write!(f, "ESCAPE"),
9445 Extension(ext) => write!(f, "EXTENSION '{}'", value::escape_single_quote_string(ext)),
9446 FixedWidth(spec) => write!(
9447 f,
9448 "FIXEDWIDTH '{}'",
9449 value::escape_single_quote_string(spec)
9450 ),
9451 Gzip => write!(f, "GZIP"),
9452 Header => write!(f, "HEADER"),
9453 IamRole(role) => write!(f, "IAM_ROLE {role}"),
9454 IgnoreHeader(num_rows) => write!(f, "IGNOREHEADER {num_rows}"),
9455 Json(opt) => {
9456 write!(f, "JSON")?;
9457 if let Some(opt) = opt {
9458 write!(f, " AS '{}'", value::escape_single_quote_string(opt))?;
9459 }
9460 Ok(())
9461 }
9462 Manifest { verbose } => write!(f, "MANIFEST{}", if *verbose { " VERBOSE" } else { "" }),
9463 MaxFileSize(file_size) => write!(f, "MAXFILESIZE {file_size}"),
9464 Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)),
9465 Parallel(enabled) => {
9466 write!(
9467 f,
9468 "PARALLEL{}",
9469 match enabled {
9470 Some(true) => " TRUE",
9471 Some(false) => " FALSE",
9472 _ => "",
9473 }
9474 )
9475 }
9476 Parquet => write!(f, "PARQUET"),
9477 PartitionBy(p) => write!(f, "{p}"),
9478 Region(region) => write!(f, "REGION '{}'", value::escape_single_quote_string(region)),
9479 RemoveQuotes => write!(f, "REMOVEQUOTES"),
9480 RowGroupSize(file_size) => write!(f, "ROWGROUPSIZE {file_size}"),
9481 StatUpdate(enabled) => {
9482 write!(
9483 f,
9484 "STATUPDATE{}",
9485 match enabled {
9486 Some(true) => " TRUE",
9487 Some(false) => " FALSE",
9488 _ => "",
9489 }
9490 )
9491 }
9492 TimeFormat(fmt) => {
9493 write!(f, "TIMEFORMAT")?;
9494 if let Some(fmt) = fmt {
9495 write!(f, " '{}'", value::escape_single_quote_string(fmt))?;
9496 }
9497 Ok(())
9498 }
9499 TruncateColumns => write!(f, "TRUNCATECOLUMNS"),
9500 Zstd => write!(f, "ZSTD"),
9501 Credentials(s) => write!(f, "CREDENTIALS '{}'", value::escape_single_quote_string(s)),
9502 }
9503 }
9504}
9505
9506#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9510#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9511#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9512pub struct FileSize {
9513 pub size: ValueWithSpan,
9515 pub unit: Option<FileSizeUnit>,
9517}
9518
9519impl fmt::Display for FileSize {
9520 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9521 write!(f, "{}", self.size)?;
9522 if let Some(unit) = &self.unit {
9523 write!(f, " {unit}")?;
9524 }
9525 Ok(())
9526 }
9527}
9528
9529#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9531#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9532#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9533pub enum FileSizeUnit {
9534 MB,
9536 GB,
9538}
9539
9540impl fmt::Display for FileSizeUnit {
9541 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9542 match self {
9543 FileSizeUnit::MB => write!(f, "MB"),
9544 FileSizeUnit::GB => write!(f, "GB"),
9545 }
9546 }
9547}
9548
9549#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9555#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9556#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9557pub struct UnloadPartitionBy {
9558 pub columns: Vec<Ident>,
9560 pub include: bool,
9562}
9563
9564impl fmt::Display for UnloadPartitionBy {
9565 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9566 write!(
9567 f,
9568 "PARTITION BY ({}){}",
9569 display_comma_separated(&self.columns),
9570 if self.include { " INCLUDE" } else { "" }
9571 )
9572 }
9573}
9574
9575#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9579#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9580#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9581pub enum IamRoleKind {
9582 Default,
9584 Arn(String),
9586}
9587
9588impl fmt::Display for IamRoleKind {
9589 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9590 match self {
9591 IamRoleKind::Default => write!(f, "DEFAULT"),
9592 IamRoleKind::Arn(arn) => write!(f, "'{arn}'"),
9593 }
9594 }
9595}
9596
9597#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9601#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9602#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9603pub enum CopyLegacyCsvOption {
9604 Header,
9606 Quote(char),
9608 Escape(char),
9610 ForceQuote(Vec<Ident>),
9612 ForceNotNull(Vec<Ident>),
9614}
9615
9616impl fmt::Display for CopyLegacyCsvOption {
9617 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9618 use CopyLegacyCsvOption::*;
9619 match self {
9620 Header => write!(f, "HEADER"),
9621 Quote(char) => write!(f, "QUOTE '{char}'"),
9622 Escape(char) => write!(f, "ESCAPE '{char}'"),
9623 ForceQuote(columns) => write!(f, "FORCE QUOTE {}", display_comma_separated(columns)),
9624 ForceNotNull(columns) => {
9625 write!(f, "FORCE NOT NULL {}", display_comma_separated(columns))
9626 }
9627 }
9628 }
9629}
9630
9631#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9633#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9634#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9635pub enum DiscardObject {
9636 ALL,
9638 PLANS,
9640 SEQUENCES,
9642 TEMP,
9644}
9645
9646impl fmt::Display for DiscardObject {
9647 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9648 match self {
9649 DiscardObject::ALL => f.write_str("ALL"),
9650 DiscardObject::PLANS => f.write_str("PLANS"),
9651 DiscardObject::SEQUENCES => f.write_str("SEQUENCES"),
9652 DiscardObject::TEMP => f.write_str("TEMP"),
9653 }
9654 }
9655}
9656
9657#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9659#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9660#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9661pub enum FlushType {
9662 BinaryLogs,
9664 EngineLogs,
9666 ErrorLogs,
9668 GeneralLogs,
9670 Hosts,
9672 Logs,
9674 Privileges,
9676 OptimizerCosts,
9678 RelayLogs,
9680 SlowLogs,
9682 Status,
9684 UserResources,
9686 Tables,
9688}
9689
9690impl fmt::Display for FlushType {
9691 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9692 match self {
9693 FlushType::BinaryLogs => f.write_str("BINARY LOGS"),
9694 FlushType::EngineLogs => f.write_str("ENGINE LOGS"),
9695 FlushType::ErrorLogs => f.write_str("ERROR LOGS"),
9696 FlushType::GeneralLogs => f.write_str("GENERAL LOGS"),
9697 FlushType::Hosts => f.write_str("HOSTS"),
9698 FlushType::Logs => f.write_str("LOGS"),
9699 FlushType::Privileges => f.write_str("PRIVILEGES"),
9700 FlushType::OptimizerCosts => f.write_str("OPTIMIZER_COSTS"),
9701 FlushType::RelayLogs => f.write_str("RELAY LOGS"),
9702 FlushType::SlowLogs => f.write_str("SLOW LOGS"),
9703 FlushType::Status => f.write_str("STATUS"),
9704 FlushType::UserResources => f.write_str("USER_RESOURCES"),
9705 FlushType::Tables => f.write_str("TABLES"),
9706 }
9707 }
9708}
9709
9710#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9712#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9713#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9714pub enum FlushLocation {
9715 NoWriteToBinlog,
9717 Local,
9719}
9720
9721impl fmt::Display for FlushLocation {
9722 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9723 match self {
9724 FlushLocation::NoWriteToBinlog => f.write_str("NO_WRITE_TO_BINLOG"),
9725 FlushLocation::Local => f.write_str("LOCAL"),
9726 }
9727 }
9728}
9729
9730#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9732#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9733#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9734pub enum ContextModifier {
9735 Local,
9737 Session,
9739 Global,
9741}
9742
9743impl fmt::Display for ContextModifier {
9744 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9745 match self {
9746 Self::Local => {
9747 write!(f, "LOCAL ")
9748 }
9749 Self::Session => {
9750 write!(f, "SESSION ")
9751 }
9752 Self::Global => {
9753 write!(f, "GLOBAL ")
9754 }
9755 }
9756 }
9757}
9758
9759#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9761#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9762pub enum DropFunctionOption {
9763 Restrict,
9765 Cascade,
9767}
9768
9769impl fmt::Display for DropFunctionOption {
9770 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9771 match self {
9772 DropFunctionOption::Restrict => write!(f, "RESTRICT "),
9773 DropFunctionOption::Cascade => write!(f, "CASCADE "),
9774 }
9775 }
9776}
9777
9778#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9780#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9781#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9782pub struct FunctionDesc {
9783 pub name: ObjectName,
9785 pub args: Option<Vec<OperateFunctionArg>>,
9787}
9788
9789impl fmt::Display for FunctionDesc {
9790 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9791 write!(f, "{}", self.name)?;
9792 if let Some(args) = &self.args {
9793 write!(f, "({})", display_comma_separated(args))?;
9794 }
9795 Ok(())
9796 }
9797}
9798
9799#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9801#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9802#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9803pub struct OperateFunctionArg {
9804 pub mode: Option<ArgMode>,
9806 pub name: Option<Ident>,
9808 pub data_type: DataType,
9810 pub default_expr: Option<Expr>,
9812}
9813
9814impl OperateFunctionArg {
9815 pub fn unnamed(data_type: DataType) -> Self {
9817 Self {
9818 mode: None,
9819 name: None,
9820 data_type,
9821 default_expr: None,
9822 }
9823 }
9824
9825 pub fn with_name(name: &str, data_type: DataType) -> Self {
9827 Self {
9828 mode: None,
9829 name: Some(name.into()),
9830 data_type,
9831 default_expr: None,
9832 }
9833 }
9834}
9835
9836impl fmt::Display for OperateFunctionArg {
9837 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9838 if let Some(mode) = &self.mode {
9839 write!(f, "{mode} ")?;
9840 }
9841 if let Some(name) = &self.name {
9842 write!(f, "{name} ")?;
9843 }
9844 write!(f, "{}", self.data_type)?;
9845 if let Some(default_expr) = &self.default_expr {
9846 write!(f, " = {default_expr}")?;
9847 }
9848 Ok(())
9849 }
9850}
9851
9852#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9854#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9855#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9856pub enum ArgMode {
9857 In,
9859 Out,
9861 InOut,
9863 Variadic,
9865}
9866
9867impl fmt::Display for ArgMode {
9868 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9869 match self {
9870 ArgMode::In => write!(f, "IN"),
9871 ArgMode::Out => write!(f, "OUT"),
9872 ArgMode::InOut => write!(f, "INOUT"),
9873 ArgMode::Variadic => write!(f, "VARIADIC"),
9874 }
9875 }
9876}
9877
9878#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9880#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9881#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9882pub enum FunctionBehavior {
9883 Immutable,
9885 Stable,
9887 Volatile,
9889}
9890
9891impl fmt::Display for FunctionBehavior {
9892 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9893 match self {
9894 FunctionBehavior::Immutable => write!(f, "IMMUTABLE"),
9895 FunctionBehavior::Stable => write!(f, "STABLE"),
9896 FunctionBehavior::Volatile => write!(f, "VOLATILE"),
9897 }
9898 }
9899}
9900
9901#[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 FunctionSecurity {
9908 Definer,
9910 Invoker,
9912}
9913
9914impl fmt::Display for FunctionSecurity {
9915 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9916 match self {
9917 FunctionSecurity::Definer => write!(f, "SECURITY DEFINER"),
9918 FunctionSecurity::Invoker => write!(f, "SECURITY INVOKER"),
9919 }
9920 }
9921}
9922
9923#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9927#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9928#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9929pub enum FunctionSetValue {
9930 Default,
9932 Values(Vec<Expr>),
9934 FromCurrent,
9936}
9937
9938#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9942#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9943#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9944pub struct FunctionDefinitionSetParam {
9945 pub name: ObjectName,
9947 pub value: FunctionSetValue,
9949}
9950
9951impl fmt::Display for FunctionDefinitionSetParam {
9952 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9953 write!(f, "SET {} ", self.name)?;
9954 match &self.value {
9955 FunctionSetValue::Default => write!(f, "= DEFAULT"),
9956 FunctionSetValue::Values(values) => {
9957 write!(f, "= {}", display_comma_separated(values))
9958 }
9959 FunctionSetValue::FromCurrent => write!(f, "FROM CURRENT"),
9960 }
9961 }
9962}
9963
9964#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9966#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9967#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9968pub enum FunctionCalledOnNull {
9969 CalledOnNullInput,
9971 ReturnsNullOnNullInput,
9973 Strict,
9975}
9976
9977impl fmt::Display for FunctionCalledOnNull {
9978 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9979 match self {
9980 FunctionCalledOnNull::CalledOnNullInput => write!(f, "CALLED ON NULL INPUT"),
9981 FunctionCalledOnNull::ReturnsNullOnNullInput => write!(f, "RETURNS NULL ON NULL INPUT"),
9982 FunctionCalledOnNull::Strict => write!(f, "STRICT"),
9983 }
9984 }
9985}
9986
9987#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
9989#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9990#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
9991pub enum FunctionParallel {
9992 Unsafe,
9994 Restricted,
9996 Safe,
9998}
9999
10000impl fmt::Display for FunctionParallel {
10001 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10002 match self {
10003 FunctionParallel::Unsafe => write!(f, "PARALLEL UNSAFE"),
10004 FunctionParallel::Restricted => write!(f, "PARALLEL RESTRICTED"),
10005 FunctionParallel::Safe => write!(f, "PARALLEL SAFE"),
10006 }
10007 }
10008}
10009
10010#[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 FunctionDeterminismSpecifier {
10017 Deterministic,
10019 NotDeterministic,
10021}
10022
10023impl fmt::Display for FunctionDeterminismSpecifier {
10024 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10025 match self {
10026 FunctionDeterminismSpecifier::Deterministic => {
10027 write!(f, "DETERMINISTIC")
10028 }
10029 FunctionDeterminismSpecifier::NotDeterministic => {
10030 write!(f, "NOT DETERMINISTIC")
10031 }
10032 }
10033 }
10034}
10035
10036#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10043#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10044#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10045pub enum CreateFunctionBody {
10046 AsBeforeOptions {
10059 body: Expr,
10061 link_symbol: Option<Expr>,
10070 },
10071 AsAfterOptions(Expr),
10083 AsBeginEnd(BeginEndStatements),
10099 Return(Expr),
10110
10111 AsReturnExpr(Expr),
10122
10123 AsReturnSelect(Select),
10134}
10135
10136#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10137#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10138#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10139pub enum CreateFunctionUsing {
10141 Jar(String),
10143 File(String),
10145 Archive(String),
10147}
10148
10149impl fmt::Display for CreateFunctionUsing {
10150 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10151 write!(f, "USING ")?;
10152 match self {
10153 CreateFunctionUsing::Jar(uri) => write!(f, "JAR '{uri}'"),
10154 CreateFunctionUsing::File(uri) => write!(f, "FILE '{uri}'"),
10155 CreateFunctionUsing::Archive(uri) => write!(f, "ARCHIVE '{uri}'"),
10156 }
10157 }
10158}
10159
10160#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10165#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10166#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10167pub struct MacroArg {
10168 pub name: Ident,
10170 pub default_expr: Option<Expr>,
10172}
10173
10174impl MacroArg {
10175 pub fn new(name: &str) -> Self {
10177 Self {
10178 name: name.into(),
10179 default_expr: None,
10180 }
10181 }
10182}
10183
10184impl fmt::Display for MacroArg {
10185 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10186 write!(f, "{}", self.name)?;
10187 if let Some(default_expr) = &self.default_expr {
10188 write!(f, " := {default_expr}")?;
10189 }
10190 Ok(())
10191 }
10192}
10193
10194#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10195#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10196#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10197pub enum MacroDefinition {
10199 Expr(Expr),
10201 Table(Box<Query>),
10203}
10204
10205impl fmt::Display for MacroDefinition {
10206 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10207 match self {
10208 MacroDefinition::Expr(expr) => write!(f, "{expr}")?,
10209 MacroDefinition::Table(query) => write!(f, "{query}")?,
10210 }
10211 Ok(())
10212 }
10213}
10214
10215#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10219#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10220#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10221pub enum SchemaName {
10222 Simple(ObjectName),
10224 UnnamedAuthorization(Ident),
10226 NamedAuthorization(ObjectName, Ident),
10228}
10229
10230impl fmt::Display for SchemaName {
10231 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10232 match self {
10233 SchemaName::Simple(name) => {
10234 write!(f, "{name}")
10235 }
10236 SchemaName::UnnamedAuthorization(authorization) => {
10237 write!(f, "AUTHORIZATION {authorization}")
10238 }
10239 SchemaName::NamedAuthorization(name, authorization) => {
10240 write!(f, "{name} AUTHORIZATION {authorization}")
10241 }
10242 }
10243 }
10244}
10245
10246#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10250#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10251#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10252pub enum SearchModifier {
10253 InNaturalLanguageMode,
10255 InNaturalLanguageModeWithQueryExpansion,
10257 InBooleanMode,
10259 WithQueryExpansion,
10261}
10262
10263impl fmt::Display for SearchModifier {
10264 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10265 match self {
10266 Self::InNaturalLanguageMode => {
10267 write!(f, "IN NATURAL LANGUAGE MODE")?;
10268 }
10269 Self::InNaturalLanguageModeWithQueryExpansion => {
10270 write!(f, "IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION")?;
10271 }
10272 Self::InBooleanMode => {
10273 write!(f, "IN BOOLEAN MODE")?;
10274 }
10275 Self::WithQueryExpansion => {
10276 write!(f, "WITH QUERY EXPANSION")?;
10277 }
10278 }
10279
10280 Ok(())
10281 }
10282}
10283
10284#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10286#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10287#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10288pub struct LockTable {
10289 pub table: Ident,
10291 pub alias: Option<Ident>,
10293 pub lock_type: LockTableType,
10295}
10296
10297impl fmt::Display for LockTable {
10298 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10299 let Self {
10300 table: tbl_name,
10301 alias,
10302 lock_type,
10303 } = self;
10304
10305 write!(f, "{tbl_name} ")?;
10306 if let Some(alias) = alias {
10307 write!(f, "AS {alias} ")?;
10308 }
10309 write!(f, "{lock_type}")?;
10310 Ok(())
10311 }
10312}
10313
10314#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10315#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10316#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10317pub enum LockTableType {
10319 Read {
10321 local: bool,
10323 },
10324 Write {
10326 low_priority: bool,
10328 },
10329}
10330
10331impl fmt::Display for LockTableType {
10332 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10333 match self {
10334 Self::Read { local } => {
10335 write!(f, "READ")?;
10336 if *local {
10337 write!(f, " LOCAL")?;
10338 }
10339 }
10340 Self::Write { low_priority } => {
10341 if *low_priority {
10342 write!(f, "LOW_PRIORITY ")?;
10343 }
10344 write!(f, "WRITE")?;
10345 }
10346 }
10347
10348 Ok(())
10349 }
10350}
10351
10352#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10353#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10354#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10355pub struct HiveSetLocation {
10357 pub has_set: bool,
10359 pub location: Ident,
10361}
10362
10363impl fmt::Display for HiveSetLocation {
10364 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10365 if self.has_set {
10366 write!(f, "SET ")?;
10367 }
10368 write!(f, "LOCATION {}", self.location)
10369 }
10370}
10371
10372#[allow(clippy::large_enum_variant)]
10374#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10375#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10376#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10377pub enum MySQLColumnPosition {
10379 First,
10381 After(Ident),
10383}
10384
10385impl Display for MySQLColumnPosition {
10386 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10387 match self {
10388 MySQLColumnPosition::First => write!(f, "FIRST"),
10389 MySQLColumnPosition::After(ident) => {
10390 let column_name = &ident.value;
10391 write!(f, "AFTER {column_name}")
10392 }
10393 }
10394 }
10395}
10396
10397#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10399#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10400#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10401pub enum CreateViewAlgorithm {
10403 Undefined,
10405 Merge,
10407 TempTable,
10409}
10410
10411impl Display for CreateViewAlgorithm {
10412 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10413 match self {
10414 CreateViewAlgorithm::Undefined => write!(f, "UNDEFINED"),
10415 CreateViewAlgorithm::Merge => write!(f, "MERGE"),
10416 CreateViewAlgorithm::TempTable => write!(f, "TEMPTABLE"),
10417 }
10418 }
10419}
10420#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10422#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10423#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10424pub enum CreateViewSecurity {
10426 Definer,
10428 Invoker,
10430}
10431
10432impl Display for CreateViewSecurity {
10433 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10434 match self {
10435 CreateViewSecurity::Definer => write!(f, "DEFINER"),
10436 CreateViewSecurity::Invoker => write!(f, "INVOKER"),
10437 }
10438 }
10439}
10440
10441#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10445#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10446#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10447pub struct CreateViewParams {
10448 pub algorithm: Option<CreateViewAlgorithm>,
10450 pub definer: Option<GranteeName>,
10452 pub security: Option<CreateViewSecurity>,
10454}
10455
10456impl Display for CreateViewParams {
10457 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10458 let CreateViewParams {
10459 algorithm,
10460 definer,
10461 security,
10462 } = self;
10463 if let Some(algorithm) = algorithm {
10464 write!(f, "ALGORITHM = {algorithm} ")?;
10465 }
10466 if let Some(definers) = definer {
10467 write!(f, "DEFINER = {definers} ")?;
10468 }
10469 if let Some(security) = security {
10470 write!(f, "SQL SECURITY {security} ")?;
10471 }
10472 Ok(())
10473 }
10474}
10475
10476#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10477#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10478#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10479pub struct NamedParenthesizedList {
10487 pub key: Ident,
10489 pub name: Option<Ident>,
10491 pub values: Vec<Ident>,
10493}
10494
10495#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10500#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10501#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10502pub struct RowAccessPolicy {
10503 pub policy: ObjectName,
10505 pub on: Vec<Ident>,
10507}
10508
10509impl RowAccessPolicy {
10510 pub fn new(policy: ObjectName, on: Vec<Ident>) -> Self {
10512 Self { policy, on }
10513 }
10514}
10515
10516impl Display for RowAccessPolicy {
10517 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10518 write!(
10519 f,
10520 "WITH ROW ACCESS POLICY {} ON ({})",
10521 self.policy,
10522 display_comma_separated(self.on.as_slice())
10523 )
10524 }
10525}
10526
10527#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10531#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10532#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10533pub struct StorageLifecyclePolicy {
10534 pub policy: ObjectName,
10536 pub on: Vec<Ident>,
10538}
10539
10540impl Display for StorageLifecyclePolicy {
10541 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10542 write!(
10543 f,
10544 "WITH STORAGE LIFECYCLE POLICY {} ON ({})",
10545 self.policy,
10546 display_comma_separated(self.on.as_slice())
10547 )
10548 }
10549}
10550
10551#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10555#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10556#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10557pub struct Tag {
10558 pub key: ObjectName,
10560 pub value: String,
10562}
10563
10564impl Tag {
10565 pub fn new(key: ObjectName, value: String) -> Self {
10567 Self { key, value }
10568 }
10569}
10570
10571impl Display for Tag {
10572 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10573 write!(f, "{}='{}'", self.key, self.value)
10574 }
10575}
10576
10577#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10581#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10582#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10583pub struct ContactEntry {
10584 pub purpose: String,
10586 pub contact: String,
10588}
10589
10590impl Display for ContactEntry {
10591 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10592 write!(f, "{} = {}", self.purpose, self.contact)
10593 }
10594}
10595
10596#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10598#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10599#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10600pub enum CommentDef {
10601 WithEq(String),
10604 WithoutEq(String),
10606}
10607
10608impl Display for CommentDef {
10609 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10610 match self {
10611 CommentDef::WithEq(comment) | CommentDef::WithoutEq(comment) => write!(f, "{comment}"),
10612 }
10613 }
10614}
10615
10616#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10631#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10632#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10633pub enum WrappedCollection<T> {
10634 NoWrapping(T),
10636 Parentheses(T),
10638}
10639
10640impl<T> Display for WrappedCollection<Vec<T>>
10641where
10642 T: Display,
10643{
10644 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10645 match self {
10646 WrappedCollection::NoWrapping(inner) => {
10647 write!(f, "{}", display_comma_separated(inner.as_slice()))
10648 }
10649 WrappedCollection::Parentheses(inner) => {
10650 write!(f, "({})", display_comma_separated(inner.as_slice()))
10651 }
10652 }
10653 }
10654}
10655
10656#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10680#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10681#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10682pub struct UtilityOption {
10683 pub name: Ident,
10685 pub arg: Option<Expr>,
10687}
10688
10689impl Display for UtilityOption {
10690 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10691 if let Some(ref arg) = self.arg {
10692 write!(f, "{} {}", self.name, arg)
10693 } else {
10694 write!(f, "{}", self.name)
10695 }
10696 }
10697}
10698
10699#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10703#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10704#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10705pub struct ShowStatementOptions {
10706 pub show_in: Option<ShowStatementIn>,
10708 pub starts_with: Option<ValueWithSpan>,
10710 pub limit: Option<Expr>,
10712 pub limit_from: Option<ValueWithSpan>,
10714 pub filter_position: Option<ShowStatementFilterPosition>,
10716}
10717
10718impl Display for ShowStatementOptions {
10719 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10720 let (like_in_infix, like_in_suffix) = match &self.filter_position {
10721 Some(ShowStatementFilterPosition::Infix(filter)) => {
10722 (format!(" {filter}"), "".to_string())
10723 }
10724 Some(ShowStatementFilterPosition::Suffix(filter)) => {
10725 ("".to_string(), format!(" {filter}"))
10726 }
10727 None => ("".to_string(), "".to_string()),
10728 };
10729 write!(
10730 f,
10731 "{like_in_infix}{show_in}{starts_with}{limit}{from}{like_in_suffix}",
10732 show_in = match &self.show_in {
10733 Some(i) => format!(" {i}"),
10734 None => String::new(),
10735 },
10736 starts_with = match &self.starts_with {
10737 Some(s) => format!(" STARTS WITH {s}"),
10738 None => String::new(),
10739 },
10740 limit = match &self.limit {
10741 Some(l) => format!(" LIMIT {l}"),
10742 None => String::new(),
10743 },
10744 from = match &self.limit_from {
10745 Some(f) => format!(" FROM {f}"),
10746 None => String::new(),
10747 }
10748 )?;
10749 Ok(())
10750 }
10751}
10752
10753#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10754#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10755#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10756pub enum ShowStatementFilterPosition {
10758 Infix(ShowStatementFilter), Suffix(ShowStatementFilter), }
10763
10764#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10765#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10766#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10767pub enum ShowStatementInParentType {
10769 Account,
10771 Database,
10773 Schema,
10775 Table,
10777 View,
10779}
10780
10781impl fmt::Display for ShowStatementInParentType {
10782 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10783 match self {
10784 ShowStatementInParentType::Account => write!(f, "ACCOUNT"),
10785 ShowStatementInParentType::Database => write!(f, "DATABASE"),
10786 ShowStatementInParentType::Schema => write!(f, "SCHEMA"),
10787 ShowStatementInParentType::Table => write!(f, "TABLE"),
10788 ShowStatementInParentType::View => write!(f, "VIEW"),
10789 }
10790 }
10791}
10792
10793#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10794#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10795#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10796pub struct ShowStatementIn {
10798 pub clause: ShowStatementInClause,
10800 pub parent_type: Option<ShowStatementInParentType>,
10802 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
10804 pub parent_name: Option<ObjectName>,
10805}
10806
10807impl fmt::Display for ShowStatementIn {
10808 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10809 write!(f, "{}", self.clause)?;
10810 if let Some(parent_type) = &self.parent_type {
10811 write!(f, " {parent_type}")?;
10812 }
10813 if let Some(parent_name) = &self.parent_name {
10814 write!(f, " {parent_name}")?;
10815 }
10816 Ok(())
10817 }
10818}
10819
10820#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10822#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10823#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10824pub struct ShowCharset {
10825 pub is_shorthand: bool,
10828 pub filter: Option<ShowStatementFilter>,
10830}
10831
10832impl fmt::Display for ShowCharset {
10833 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10834 write!(f, "SHOW")?;
10835 if self.is_shorthand {
10836 write!(f, " CHARSET")?;
10837 } else {
10838 write!(f, " CHARACTER SET")?;
10839 }
10840 if let Some(filter) = &self.filter {
10841 write!(f, " {filter}")?;
10842 }
10843 Ok(())
10844 }
10845}
10846
10847#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10848#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10849#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10850pub struct ShowObjects {
10852 pub terse: bool,
10854 pub show_options: ShowStatementOptions,
10856}
10857
10858#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10868#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10869#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10870pub enum JsonNullClause {
10871 NullOnNull,
10873 AbsentOnNull,
10875}
10876
10877impl Display for JsonNullClause {
10878 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10879 match self {
10880 JsonNullClause::NullOnNull => write!(f, "NULL ON NULL"),
10881 JsonNullClause::AbsentOnNull => write!(f, "ABSENT ON NULL"),
10882 }
10883 }
10884}
10885
10886#[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 struct JsonReturningClause {
10896 pub data_type: DataType,
10898}
10899
10900impl Display for JsonReturningClause {
10901 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10902 write!(f, "RETURNING {}", self.data_type)
10903 }
10904}
10905
10906#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10908#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10909#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10910pub struct RenameTable {
10911 pub old_name: ObjectName,
10913 pub new_name: ObjectName,
10915}
10916
10917impl fmt::Display for RenameTable {
10918 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10919 write!(f, "{} TO {}", self.old_name, self.new_name)?;
10920 Ok(())
10921 }
10922}
10923
10924#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10926#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10927#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10928pub enum TableObject {
10929 TableName(#[cfg_attr(feature = "visitor", visit(with = "visit_relation"))] ObjectName),
10935
10936 TableFunction(Function),
10943
10944 TableQuery(Box<Query>),
10953}
10954
10955impl fmt::Display for TableObject {
10956 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10957 match self {
10958 Self::TableName(table_name) => write!(f, "{table_name}"),
10959 Self::TableFunction(func) => write!(f, "FUNCTION {func}"),
10960 Self::TableQuery(table_query) => write!(f, "({table_query})"),
10961 }
10962 }
10963}
10964
10965#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10967#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10968#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10969pub struct SetSessionAuthorizationParam {
10970 pub scope: ContextModifier,
10972 pub kind: SetSessionAuthorizationParamKind,
10974}
10975
10976impl fmt::Display for SetSessionAuthorizationParam {
10977 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10978 write!(f, "{}", self.kind)
10979 }
10980}
10981
10982#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
10984#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10985#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
10986pub enum SetSessionAuthorizationParamKind {
10987 Default,
10989
10990 User(Ident),
10992}
10993
10994impl fmt::Display for SetSessionAuthorizationParamKind {
10995 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10996 match self {
10997 SetSessionAuthorizationParamKind::Default => write!(f, "DEFAULT"),
10998 SetSessionAuthorizationParamKind::User(name) => write!(f, "{}", name),
10999 }
11000 }
11001}
11002
11003#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11004#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11005#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11006pub enum SetSessionParamKind {
11008 Generic(SetSessionParamGeneric),
11010 IdentityInsert(SetSessionParamIdentityInsert),
11012 Offsets(SetSessionParamOffsets),
11014 Statistics(SetSessionParamStatistics),
11016}
11017
11018impl fmt::Display for SetSessionParamKind {
11019 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11020 match self {
11021 SetSessionParamKind::Generic(x) => write!(f, "{x}"),
11022 SetSessionParamKind::IdentityInsert(x) => write!(f, "{x}"),
11023 SetSessionParamKind::Offsets(x) => write!(f, "{x}"),
11024 SetSessionParamKind::Statistics(x) => write!(f, "{x}"),
11025 }
11026 }
11027}
11028
11029#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11030#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11031#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11032pub struct SetSessionParamGeneric {
11034 pub names: Vec<String>,
11036 pub value: String,
11038}
11039
11040impl fmt::Display for SetSessionParamGeneric {
11041 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11042 write!(f, "{} {}", display_comma_separated(&self.names), self.value)
11043 }
11044}
11045
11046#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11047#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11048#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11049pub struct SetSessionParamIdentityInsert {
11051 pub obj: ObjectName,
11053 pub value: SessionParamValue,
11055}
11056
11057impl fmt::Display for SetSessionParamIdentityInsert {
11058 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11059 write!(f, "IDENTITY_INSERT {} {}", self.obj, self.value)
11060 }
11061}
11062
11063#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11064#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11065#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11066pub struct SetSessionParamOffsets {
11068 pub keywords: Vec<String>,
11070 pub value: SessionParamValue,
11072}
11073
11074impl fmt::Display for SetSessionParamOffsets {
11075 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11076 write!(
11077 f,
11078 "OFFSETS {} {}",
11079 display_comma_separated(&self.keywords),
11080 self.value
11081 )
11082 }
11083}
11084
11085#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11086#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11087#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11088pub struct SetSessionParamStatistics {
11090 pub topic: SessionParamStatsTopic,
11092 pub value: SessionParamValue,
11094}
11095
11096impl fmt::Display for SetSessionParamStatistics {
11097 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11098 write!(f, "STATISTICS {} {}", self.topic, self.value)
11099 }
11100}
11101
11102#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11103#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11104#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11105pub enum SessionParamStatsTopic {
11107 IO,
11109 Profile,
11111 Time,
11113 Xml,
11115}
11116
11117impl fmt::Display for SessionParamStatsTopic {
11118 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11119 match self {
11120 SessionParamStatsTopic::IO => write!(f, "IO"),
11121 SessionParamStatsTopic::Profile => write!(f, "PROFILE"),
11122 SessionParamStatsTopic::Time => write!(f, "TIME"),
11123 SessionParamStatsTopic::Xml => write!(f, "XML"),
11124 }
11125 }
11126}
11127
11128#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11129#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11130#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11131pub enum SessionParamValue {
11133 On,
11135 Off,
11137}
11138
11139impl fmt::Display for SessionParamValue {
11140 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11141 match self {
11142 SessionParamValue::On => write!(f, "ON"),
11143 SessionParamValue::Off => write!(f, "OFF"),
11144 }
11145 }
11146}
11147
11148#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11155#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11156#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11157pub enum StorageSerializationPolicy {
11158 Compatible,
11160 Optimized,
11162}
11163
11164impl Display for StorageSerializationPolicy {
11165 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11166 match self {
11167 StorageSerializationPolicy::Compatible => write!(f, "COMPATIBLE"),
11168 StorageSerializationPolicy::Optimized => write!(f, "OPTIMIZED"),
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 CatalogSyncNamespaceMode {
11183 Nest,
11185 Flatten,
11187}
11188
11189impl Display for CatalogSyncNamespaceMode {
11190 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11191 match self {
11192 CatalogSyncNamespaceMode::Nest => write!(f, "NEST"),
11193 CatalogSyncNamespaceMode::Flatten => write!(f, "FLATTEN"),
11194 }
11195 }
11196}
11197
11198#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11200#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11201#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11202pub enum CopyIntoSnowflakeKind {
11203 Table,
11206 Location,
11209}
11210
11211#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11212#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11213#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11214pub struct PrintStatement {
11216 pub message: Box<Expr>,
11218}
11219
11220impl fmt::Display for PrintStatement {
11221 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11222 write!(f, "PRINT {}", self.message)
11223 }
11224}
11225
11226#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11230#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11231#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11232pub enum WaitForType {
11233 Delay,
11235 Time,
11237}
11238
11239impl fmt::Display for WaitForType {
11240 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11241 match self {
11242 WaitForType::Delay => write!(f, "DELAY"),
11243 WaitForType::Time => write!(f, "TIME"),
11244 }
11245 }
11246}
11247
11248#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11252#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11253#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11254pub struct WaitForStatement {
11255 pub wait_type: WaitForType,
11257 pub expr: Expr,
11259}
11260
11261impl fmt::Display for WaitForStatement {
11262 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11263 write!(f, "WAITFOR {} {}", self.wait_type, self.expr)
11264 }
11265}
11266
11267#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11272#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11273#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11274pub struct ReturnStatement {
11275 pub value: Option<ReturnStatementValue>,
11277}
11278
11279impl fmt::Display for ReturnStatement {
11280 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11281 match &self.value {
11282 Some(ReturnStatementValue::Expr(expr)) => write!(f, "RETURN {expr}"),
11283 None => write!(f, "RETURN"),
11284 }
11285 }
11286}
11287
11288#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11290#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11291#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11292pub enum ReturnStatementValue {
11293 Expr(Expr),
11295}
11296
11297#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11299#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11300#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11301pub struct OpenStatement {
11302 pub cursor_name: Ident,
11304}
11305
11306impl fmt::Display for OpenStatement {
11307 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11308 write!(f, "OPEN {}", self.cursor_name)
11309 }
11310}
11311
11312#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11316#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11317#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11318pub enum NullInclusion {
11319 IncludeNulls,
11321 ExcludeNulls,
11323}
11324
11325impl fmt::Display for NullInclusion {
11326 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11327 match self {
11328 NullInclusion::IncludeNulls => write!(f, "INCLUDE NULLS"),
11329 NullInclusion::ExcludeNulls => write!(f, "EXCLUDE NULLS"),
11330 }
11331 }
11332}
11333
11334#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11342#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11343#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11344pub struct MemberOf {
11345 pub value: Box<Expr>,
11347 pub array: Box<Expr>,
11349}
11350
11351impl fmt::Display for MemberOf {
11352 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11353 write!(f, "{} MEMBER OF({})", self.value, self.array)
11354 }
11355}
11356
11357#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11358#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11359#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11360pub struct ExportData {
11362 pub options: Vec<SqlOption>,
11364 pub query: Box<Query>,
11366 pub connection: Option<ObjectName>,
11368}
11369
11370impl fmt::Display for ExportData {
11371 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11372 if let Some(connection) = &self.connection {
11373 write!(
11374 f,
11375 "EXPORT DATA WITH CONNECTION {connection} OPTIONS({}) AS {}",
11376 display_comma_separated(&self.options),
11377 self.query
11378 )
11379 } else {
11380 write!(
11381 f,
11382 "EXPORT DATA OPTIONS({}) AS {}",
11383 display_comma_separated(&self.options),
11384 self.query
11385 )
11386 }
11387 }
11388}
11389#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11398#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11399#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11400pub struct CreateUser {
11401 pub or_replace: bool,
11403 pub if_not_exists: bool,
11405 pub name: Ident,
11407 pub options: KeyValueOptions,
11409 pub with_tags: bool,
11411 pub tags: KeyValueOptions,
11413}
11414
11415impl fmt::Display for CreateUser {
11416 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11417 write!(f, "CREATE")?;
11418 if self.or_replace {
11419 write!(f, " OR REPLACE")?;
11420 }
11421 write!(f, " USER")?;
11422 if self.if_not_exists {
11423 write!(f, " IF NOT EXISTS")?;
11424 }
11425 write!(f, " {}", self.name)?;
11426 if !self.options.options.is_empty() {
11427 write!(f, " {}", self.options)?;
11428 }
11429 if !self.tags.options.is_empty() {
11430 if self.with_tags {
11431 write!(f, " WITH")?;
11432 }
11433 write!(f, " TAG ({})", self.tags)?;
11434 }
11435 Ok(())
11436 }
11437}
11438
11439#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11451#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11452#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11453pub struct AlterUser {
11454 pub if_exists: bool,
11456 pub name: Ident,
11458 pub rename_to: Option<Ident>,
11461 pub reset_password: bool,
11463 pub abort_all_queries: bool,
11465 pub add_role_delegation: Option<AlterUserAddRoleDelegation>,
11467 pub remove_role_delegation: Option<AlterUserRemoveRoleDelegation>,
11469 pub enroll_mfa: bool,
11471 pub set_default_mfa_method: Option<MfaMethodKind>,
11473 pub remove_mfa_method: Option<MfaMethodKind>,
11475 pub modify_mfa_method: Option<AlterUserModifyMfaMethod>,
11477 pub add_mfa_method_otp: Option<AlterUserAddMfaMethodOtp>,
11479 pub set_policy: Option<AlterUserSetPolicy>,
11481 pub unset_policy: Option<UserPolicyKind>,
11483 pub set_tag: KeyValueOptions,
11485 pub unset_tag: Vec<String>,
11487 pub set_props: KeyValueOptions,
11489 pub unset_props: Vec<String>,
11491 pub password: Option<AlterUserPassword>,
11493}
11494
11495#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11499#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11500#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11501pub struct AlterUserAddRoleDelegation {
11502 pub role: Ident,
11504 pub integration: Ident,
11506}
11507
11508#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11512#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11513#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11514pub struct AlterUserRemoveRoleDelegation {
11515 pub role: Option<Ident>,
11517 pub integration: Ident,
11519}
11520
11521#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11525#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11526#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11527pub struct AlterUserAddMfaMethodOtp {
11528 pub count: Option<ValueWithSpan>,
11530}
11531
11532#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11536#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11537#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11538pub struct AlterUserModifyMfaMethod {
11539 pub method: MfaMethodKind,
11541 pub comment: String,
11543}
11544
11545#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11547#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11548#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11549pub enum MfaMethodKind {
11550 PassKey,
11552 Totp,
11554 Duo,
11556}
11557
11558impl fmt::Display for MfaMethodKind {
11559 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11560 match self {
11561 MfaMethodKind::PassKey => write!(f, "PASSKEY"),
11562 MfaMethodKind::Totp => write!(f, "TOTP"),
11563 MfaMethodKind::Duo => write!(f, "DUO"),
11564 }
11565 }
11566}
11567
11568#[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 struct AlterUserSetPolicy {
11575 pub policy_kind: UserPolicyKind,
11577 pub policy: Ident,
11579}
11580
11581#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11583#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11584#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11585pub enum UserPolicyKind {
11586 Authentication,
11588 Password,
11590 Session,
11592}
11593
11594impl fmt::Display for UserPolicyKind {
11595 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11596 match self {
11597 UserPolicyKind::Authentication => write!(f, "AUTHENTICATION"),
11598 UserPolicyKind::Password => write!(f, "PASSWORD"),
11599 UserPolicyKind::Session => write!(f, "SESSION"),
11600 }
11601 }
11602}
11603
11604impl fmt::Display for AlterUser {
11605 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11606 write!(f, "ALTER")?;
11607 write!(f, " USER")?;
11608 if self.if_exists {
11609 write!(f, " IF EXISTS")?;
11610 }
11611 write!(f, " {}", self.name)?;
11612 if let Some(new_name) = &self.rename_to {
11613 write!(f, " RENAME TO {new_name}")?;
11614 }
11615 if self.reset_password {
11616 write!(f, " RESET PASSWORD")?;
11617 }
11618 if self.abort_all_queries {
11619 write!(f, " ABORT ALL QUERIES")?;
11620 }
11621 if let Some(role_delegation) = &self.add_role_delegation {
11622 let role = &role_delegation.role;
11623 let integration = &role_delegation.integration;
11624 write!(
11625 f,
11626 " ADD DELEGATED AUTHORIZATION OF ROLE {role} TO SECURITY INTEGRATION {integration}"
11627 )?;
11628 }
11629 if let Some(role_delegation) = &self.remove_role_delegation {
11630 write!(f, " REMOVE DELEGATED")?;
11631 match &role_delegation.role {
11632 Some(role) => write!(f, " AUTHORIZATION OF ROLE {role}")?,
11633 None => write!(f, " AUTHORIZATIONS")?,
11634 }
11635 let integration = &role_delegation.integration;
11636 write!(f, " FROM SECURITY INTEGRATION {integration}")?;
11637 }
11638 if self.enroll_mfa {
11639 write!(f, " ENROLL MFA")?;
11640 }
11641 if let Some(method) = &self.set_default_mfa_method {
11642 write!(f, " SET DEFAULT_MFA_METHOD {method}")?
11643 }
11644 if let Some(method) = &self.remove_mfa_method {
11645 write!(f, " REMOVE MFA METHOD {method}")?;
11646 }
11647 if let Some(modify) = &self.modify_mfa_method {
11648 let method = &modify.method;
11649 let comment = &modify.comment;
11650 write!(
11651 f,
11652 " MODIFY MFA METHOD {method} SET COMMENT '{}'",
11653 value::escape_single_quote_string(comment)
11654 )?;
11655 }
11656 if let Some(add_mfa_method_otp) = &self.add_mfa_method_otp {
11657 write!(f, " ADD MFA METHOD OTP")?;
11658 if let Some(count) = &add_mfa_method_otp.count {
11659 write!(f, " COUNT = {count}")?;
11660 }
11661 }
11662 if let Some(policy) = &self.set_policy {
11663 let policy_kind = &policy.policy_kind;
11664 let name = &policy.policy;
11665 write!(f, " SET {policy_kind} POLICY {name}")?;
11666 }
11667 if let Some(policy_kind) = &self.unset_policy {
11668 write!(f, " UNSET {policy_kind} POLICY")?;
11669 }
11670 if !self.set_tag.options.is_empty() {
11671 write!(f, " SET TAG {}", self.set_tag)?;
11672 }
11673 if !self.unset_tag.is_empty() {
11674 write!(f, " UNSET TAG {}", display_comma_separated(&self.unset_tag))?;
11675 }
11676 let has_props = !self.set_props.options.is_empty();
11677 if has_props {
11678 write!(f, " SET")?;
11679 write!(f, " {}", &self.set_props)?;
11680 }
11681 if !self.unset_props.is_empty() {
11682 write!(f, " UNSET {}", display_comma_separated(&self.unset_props))?;
11683 }
11684 if let Some(password) = &self.password {
11685 write!(f, " {}", password)?;
11686 }
11687 Ok(())
11688 }
11689}
11690
11691#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11695#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11696#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11697pub struct AlterUserPassword {
11698 pub encrypted: bool,
11700 pub password: Option<String>,
11702}
11703
11704impl Display for AlterUserPassword {
11705 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11706 if self.encrypted {
11707 write!(f, "ENCRYPTED ")?;
11708 }
11709 write!(f, "PASSWORD")?;
11710 match &self.password {
11711 None => write!(f, " NULL")?,
11712 Some(password) => write!(f, " '{}'", value::escape_single_quote_string(password))?,
11713 }
11714 Ok(())
11715 }
11716}
11717
11718#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11723#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11724#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11725pub enum CreateTableLikeKind {
11726 Parenthesized(CreateTableLike),
11731 Plain(CreateTableLike),
11737}
11738
11739#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11740#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11741#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11742pub enum CreateTableLikeDefaults {
11744 Including,
11746 Excluding,
11748}
11749
11750impl fmt::Display for CreateTableLikeDefaults {
11751 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11752 match self {
11753 CreateTableLikeDefaults::Including => write!(f, "INCLUDING DEFAULTS"),
11754 CreateTableLikeDefaults::Excluding => write!(f, "EXCLUDING DEFAULTS"),
11755 }
11756 }
11757}
11758
11759#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11760#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11761#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11762pub struct CreateTableLike {
11764 pub name: ObjectName,
11766 pub defaults: Option<CreateTableLikeDefaults>,
11768}
11769
11770impl fmt::Display for CreateTableLike {
11771 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11772 write!(f, "LIKE {}", self.name)?;
11773 if let Some(defaults) = &self.defaults {
11774 write!(f, " {defaults}")?;
11775 }
11776 Ok(())
11777 }
11778}
11779
11780#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11784#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11785#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11786pub enum RefreshModeKind {
11787 Auto,
11789 Full,
11791 Incremental,
11793}
11794
11795impl fmt::Display for RefreshModeKind {
11796 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11797 match self {
11798 RefreshModeKind::Auto => write!(f, "AUTO"),
11799 RefreshModeKind::Full => write!(f, "FULL"),
11800 RefreshModeKind::Incremental => write!(f, "INCREMENTAL"),
11801 }
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 InitializeKind {
11812 OnCreate,
11814 OnSchedule,
11816}
11817
11818impl fmt::Display for InitializeKind {
11819 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11820 match self {
11821 InitializeKind::OnCreate => write!(f, "ON_CREATE"),
11822 InitializeKind::OnSchedule => write!(f, "ON_SCHEDULE"),
11823 }
11824 }
11825}
11826
11827#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11834#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11835#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11836pub struct VacuumStatement {
11837 pub full: bool,
11839 pub sort_only: bool,
11841 pub delete_only: bool,
11843 pub reindex: bool,
11845 pub recluster: bool,
11847 pub table_name: Option<ObjectName>,
11849 pub threshold: Option<ValueWithSpan>,
11851 pub boost: bool,
11853}
11854
11855impl fmt::Display for VacuumStatement {
11856 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11857 write!(
11858 f,
11859 "VACUUM{}{}{}{}{}",
11860 if self.full { " FULL" } else { "" },
11861 if self.sort_only { " SORT ONLY" } else { "" },
11862 if self.delete_only { " DELETE ONLY" } else { "" },
11863 if self.reindex { " REINDEX" } else { "" },
11864 if self.recluster { " RECLUSTER" } else { "" },
11865 )?;
11866 if let Some(table_name) = &self.table_name {
11867 write!(f, " {table_name}")?;
11868 }
11869 if let Some(threshold) = &self.threshold {
11870 write!(f, " TO {threshold} PERCENT")?;
11871 }
11872 if self.boost {
11873 write!(f, " BOOST")?;
11874 }
11875 Ok(())
11876 }
11877}
11878
11879#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11881#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11882#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11883pub enum Reset {
11884 ALL,
11886
11887 ConfigurationParameter(ObjectName),
11889}
11890
11891#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11896#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11897#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11898pub struct ResetStatement {
11899 pub reset: Reset,
11901}
11902
11903#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11909#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11910#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11911pub struct OptimizerHint {
11912 pub prefix: String,
11919 pub text: String,
11921 pub style: OptimizerHintStyle,
11926}
11927
11928#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
11930#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11931#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
11932pub enum OptimizerHintStyle {
11933 SingleLine {
11936 prefix: String,
11938 },
11939 MultiLine,
11942}
11943
11944impl fmt::Display for OptimizerHint {
11945 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11946 match &self.style {
11947 OptimizerHintStyle::SingleLine { prefix } => {
11948 f.write_str(prefix)?;
11949 f.write_str(&self.prefix)?;
11950 f.write_str("+")?;
11951 f.write_str(&self.text)
11952 }
11953 OptimizerHintStyle::MultiLine => {
11954 f.write_str("/*")?;
11955 f.write_str(&self.prefix)?;
11956 f.write_str("+")?;
11957 f.write_str(&self.text)?;
11958 f.write_str("*/")
11959 }
11960 }
11961 }
11962}
11963
11964impl fmt::Display for ResetStatement {
11965 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11966 match &self.reset {
11967 Reset::ALL => write!(f, "RESET ALL"),
11968 Reset::ConfigurationParameter(param) => write!(f, "RESET {}", param),
11969 }
11970 }
11971}
11972
11973impl From<Set> for Statement {
11974 fn from(s: Set) -> Self {
11975 Self::Set(s)
11976 }
11977}
11978
11979impl From<Query> for Statement {
11980 fn from(q: Query) -> Self {
11981 Box::new(q).into()
11982 }
11983}
11984
11985impl From<Box<Query>> for Statement {
11986 fn from(q: Box<Query>) -> Self {
11987 Self::Query(q)
11988 }
11989}
11990
11991impl From<Insert> for Statement {
11992 fn from(i: Insert) -> Self {
11993 Self::Insert(i)
11994 }
11995}
11996
11997impl From<Update> for Statement {
11998 fn from(u: Update) -> Self {
11999 Self::Update(u)
12000 }
12001}
12002
12003impl From<CreateView> for Statement {
12004 fn from(cv: CreateView) -> Self {
12005 Self::CreateView(cv)
12006 }
12007}
12008
12009impl From<CreateRole> for Statement {
12010 fn from(cr: CreateRole) -> Self {
12011 Self::CreateRole(cr)
12012 }
12013}
12014
12015impl From<AlterTable> for Statement {
12016 fn from(at: AlterTable) -> Self {
12017 Self::AlterTable(at)
12018 }
12019}
12020
12021impl From<DropFunction> for Statement {
12022 fn from(df: DropFunction) -> Self {
12023 Self::DropFunction(df)
12024 }
12025}
12026
12027impl From<CreateExtension> for Statement {
12028 fn from(ce: CreateExtension) -> Self {
12029 Self::CreateExtension(ce)
12030 }
12031}
12032
12033impl From<CreateCollation> for Statement {
12034 fn from(c: CreateCollation) -> Self {
12035 Self::CreateCollation(c)
12036 }
12037}
12038
12039impl From<DropExtension> for Statement {
12040 fn from(de: DropExtension) -> Self {
12041 Self::DropExtension(de)
12042 }
12043}
12044
12045impl From<CaseStatement> for Statement {
12046 fn from(c: CaseStatement) -> Self {
12047 Self::Case(c)
12048 }
12049}
12050
12051impl From<IfStatement> for Statement {
12052 fn from(i: IfStatement) -> Self {
12053 Self::If(i)
12054 }
12055}
12056
12057impl From<WhileStatement> for Statement {
12058 fn from(w: WhileStatement) -> Self {
12059 Self::While(w)
12060 }
12061}
12062
12063impl From<RaiseStatement> for Statement {
12064 fn from(r: RaiseStatement) -> Self {
12065 Self::Raise(r)
12066 }
12067}
12068
12069impl From<ThrowStatement> for Statement {
12070 fn from(t: ThrowStatement) -> Self {
12071 Self::Throw(t)
12072 }
12073}
12074
12075impl From<Function> for Statement {
12076 fn from(f: Function) -> Self {
12077 Self::Call(f)
12078 }
12079}
12080
12081impl From<OpenStatement> for Statement {
12082 fn from(o: OpenStatement) -> Self {
12083 Self::Open(o)
12084 }
12085}
12086
12087impl From<Delete> for Statement {
12088 fn from(d: Delete) -> Self {
12089 Self::Delete(d)
12090 }
12091}
12092
12093impl From<CreateTable> for Statement {
12094 fn from(c: CreateTable) -> Self {
12095 Self::CreateTable(c)
12096 }
12097}
12098
12099impl From<CreateIndex> for Statement {
12100 fn from(c: CreateIndex) -> Self {
12101 Self::CreateIndex(c)
12102 }
12103}
12104
12105impl From<CreateServerStatement> for Statement {
12106 fn from(c: CreateServerStatement) -> Self {
12107 Self::CreateServer(c)
12108 }
12109}
12110
12111impl From<CreateConnector> for Statement {
12112 fn from(c: CreateConnector) -> Self {
12113 Self::CreateConnector(c)
12114 }
12115}
12116
12117impl From<CreateOperator> for Statement {
12118 fn from(c: CreateOperator) -> Self {
12119 Self::CreateOperator(c)
12120 }
12121}
12122
12123impl From<CreateOperatorFamily> for Statement {
12124 fn from(c: CreateOperatorFamily) -> Self {
12125 Self::CreateOperatorFamily(c)
12126 }
12127}
12128
12129impl From<CreateOperatorClass> for Statement {
12130 fn from(c: CreateOperatorClass) -> Self {
12131 Self::CreateOperatorClass(c)
12132 }
12133}
12134
12135impl From<AlterSchema> for Statement {
12136 fn from(a: AlterSchema) -> Self {
12137 Self::AlterSchema(a)
12138 }
12139}
12140
12141impl From<AlterFunction> for Statement {
12142 fn from(a: AlterFunction) -> Self {
12143 Self::AlterFunction(a)
12144 }
12145}
12146
12147impl From<AlterType> for Statement {
12148 fn from(a: AlterType) -> Self {
12149 Self::AlterType(a)
12150 }
12151}
12152
12153impl From<AlterCollation> for Statement {
12154 fn from(a: AlterCollation) -> Self {
12155 Self::AlterCollation(a)
12156 }
12157}
12158
12159impl From<AlterOperator> for Statement {
12160 fn from(a: AlterOperator) -> Self {
12161 Self::AlterOperator(a)
12162 }
12163}
12164
12165impl From<AlterOperatorFamily> for Statement {
12166 fn from(a: AlterOperatorFamily) -> Self {
12167 Self::AlterOperatorFamily(a)
12168 }
12169}
12170
12171impl From<AlterOperatorClass> for Statement {
12172 fn from(a: AlterOperatorClass) -> Self {
12173 Self::AlterOperatorClass(a)
12174 }
12175}
12176
12177impl From<Merge> for Statement {
12178 fn from(m: Merge) -> Self {
12179 Self::Merge(m)
12180 }
12181}
12182
12183impl From<AlterUser> for Statement {
12184 fn from(a: AlterUser) -> Self {
12185 Self::AlterUser(a)
12186 }
12187}
12188
12189impl From<DropDomain> for Statement {
12190 fn from(d: DropDomain) -> Self {
12191 Self::DropDomain(d)
12192 }
12193}
12194
12195impl From<ShowCharset> for Statement {
12196 fn from(s: ShowCharset) -> Self {
12197 Self::ShowCharset(s)
12198 }
12199}
12200
12201impl From<ShowObjects> for Statement {
12202 fn from(s: ShowObjects) -> Self {
12203 Self::ShowObjects(s)
12204 }
12205}
12206
12207impl From<Use> for Statement {
12208 fn from(u: Use) -> Self {
12209 Self::Use(u)
12210 }
12211}
12212
12213impl From<CreateFunction> for Statement {
12214 fn from(c: CreateFunction) -> Self {
12215 Self::CreateFunction(c)
12216 }
12217}
12218
12219impl From<CreateTrigger> for Statement {
12220 fn from(c: CreateTrigger) -> Self {
12221 Self::CreateTrigger(c)
12222 }
12223}
12224
12225impl From<DropTrigger> for Statement {
12226 fn from(d: DropTrigger) -> Self {
12227 Self::DropTrigger(d)
12228 }
12229}
12230
12231impl From<DropOperator> for Statement {
12232 fn from(d: DropOperator) -> Self {
12233 Self::DropOperator(d)
12234 }
12235}
12236
12237impl From<DropOperatorFamily> for Statement {
12238 fn from(d: DropOperatorFamily) -> Self {
12239 Self::DropOperatorFamily(d)
12240 }
12241}
12242
12243impl From<DropOperatorClass> for Statement {
12244 fn from(d: DropOperatorClass) -> Self {
12245 Self::DropOperatorClass(d)
12246 }
12247}
12248
12249impl From<DenyStatement> for Statement {
12250 fn from(d: DenyStatement) -> Self {
12251 Self::Deny(d)
12252 }
12253}
12254
12255impl From<CreateDomain> for Statement {
12256 fn from(c: CreateDomain) -> Self {
12257 Self::CreateDomain(c)
12258 }
12259}
12260
12261impl From<RenameTable> for Statement {
12262 fn from(r: RenameTable) -> Self {
12263 vec![r].into()
12264 }
12265}
12266
12267impl From<Vec<RenameTable>> for Statement {
12268 fn from(r: Vec<RenameTable>) -> Self {
12269 Self::RenameTable(r)
12270 }
12271}
12272
12273impl From<PrintStatement> for Statement {
12274 fn from(p: PrintStatement) -> Self {
12275 Self::Print(p)
12276 }
12277}
12278
12279impl From<ReturnStatement> for Statement {
12280 fn from(r: ReturnStatement) -> Self {
12281 Self::Return(r)
12282 }
12283}
12284
12285impl From<ExportData> for Statement {
12286 fn from(e: ExportData) -> Self {
12287 Self::ExportData(e)
12288 }
12289}
12290
12291impl From<CreateUser> for Statement {
12292 fn from(c: CreateUser) -> Self {
12293 Self::CreateUser(c)
12294 }
12295}
12296
12297impl From<VacuumStatement> for Statement {
12298 fn from(v: VacuumStatement) -> Self {
12299 Self::Vacuum(v)
12300 }
12301}
12302
12303impl From<ResetStatement> for Statement {
12304 fn from(r: ResetStatement) -> Self {
12305 Self::Reset(r)
12306 }
12307}
12308
12309#[cfg(test)]
12310mod tests {
12311 use crate::tokenizer::Location;
12312
12313 use super::*;
12314
12315 #[test]
12316 fn test_window_frame_default() {
12317 let window_frame = WindowFrame::default();
12318 assert_eq!(WindowFrameBound::Preceding(None), window_frame.start_bound);
12319 }
12320
12321 #[test]
12322 fn test_grouping_sets_display() {
12323 let grouping_sets = Expr::GroupingSets(vec![
12325 vec![Expr::Identifier(Ident::new("a"))],
12326 vec![Expr::Identifier(Ident::new("b"))],
12327 ]);
12328 assert_eq!("GROUPING SETS ((a), (b))", format!("{grouping_sets}"));
12329
12330 let grouping_sets = Expr::GroupingSets(vec![vec![
12332 Expr::Identifier(Ident::new("a")),
12333 Expr::Identifier(Ident::new("b")),
12334 ]]);
12335 assert_eq!("GROUPING SETS ((a, b))", format!("{grouping_sets}"));
12336
12337 let grouping_sets = Expr::GroupingSets(vec![
12339 vec![
12340 Expr::Identifier(Ident::new("a")),
12341 Expr::Identifier(Ident::new("b")),
12342 ],
12343 vec![
12344 Expr::Identifier(Ident::new("c")),
12345 Expr::Identifier(Ident::new("d")),
12346 ],
12347 ]);
12348 assert_eq!("GROUPING SETS ((a, b), (c, d))", format!("{grouping_sets}"));
12349 }
12350
12351 #[test]
12352 fn test_rollup_display() {
12353 let rollup = Expr::Rollup(vec![vec![Expr::Identifier(Ident::new("a"))]]);
12354 assert_eq!("ROLLUP (a)", format!("{rollup}"));
12355
12356 let rollup = Expr::Rollup(vec![vec![
12357 Expr::Identifier(Ident::new("a")),
12358 Expr::Identifier(Ident::new("b")),
12359 ]]);
12360 assert_eq!("ROLLUP ((a, b))", format!("{rollup}"));
12361
12362 let rollup = Expr::Rollup(vec![
12363 vec![Expr::Identifier(Ident::new("a"))],
12364 vec![Expr::Identifier(Ident::new("b"))],
12365 ]);
12366 assert_eq!("ROLLUP (a, b)", format!("{rollup}"));
12367
12368 let rollup = Expr::Rollup(vec![
12369 vec![Expr::Identifier(Ident::new("a"))],
12370 vec![
12371 Expr::Identifier(Ident::new("b")),
12372 Expr::Identifier(Ident::new("c")),
12373 ],
12374 vec![Expr::Identifier(Ident::new("d"))],
12375 ]);
12376 assert_eq!("ROLLUP (a, (b, c), d)", format!("{rollup}"));
12377 }
12378
12379 #[test]
12380 fn test_cube_display() {
12381 let cube = Expr::Cube(vec![vec![Expr::Identifier(Ident::new("a"))]]);
12382 assert_eq!("CUBE (a)", format!("{cube}"));
12383
12384 let cube = Expr::Cube(vec![vec![
12385 Expr::Identifier(Ident::new("a")),
12386 Expr::Identifier(Ident::new("b")),
12387 ]]);
12388 assert_eq!("CUBE ((a, b))", format!("{cube}"));
12389
12390 let cube = Expr::Cube(vec![
12391 vec![Expr::Identifier(Ident::new("a"))],
12392 vec![Expr::Identifier(Ident::new("b"))],
12393 ]);
12394 assert_eq!("CUBE (a, b)", format!("{cube}"));
12395
12396 let cube = Expr::Cube(vec![
12397 vec![Expr::Identifier(Ident::new("a"))],
12398 vec![
12399 Expr::Identifier(Ident::new("b")),
12400 Expr::Identifier(Ident::new("c")),
12401 ],
12402 vec![Expr::Identifier(Ident::new("d"))],
12403 ]);
12404 assert_eq!("CUBE (a, (b, c), d)", format!("{cube}"));
12405 }
12406
12407 #[test]
12408 fn test_interval_display() {
12409 let interval = Expr::Interval(Interval {
12410 value: Box::new(Expr::Value(
12411 Value::SingleQuotedString(String::from("123:45.67")).with_empty_span(),
12412 )),
12413 leading_field: Some(DateTimeField::Minute),
12414 leading_precision: Some(10),
12415 last_field: Some(DateTimeField::Second),
12416 fractional_seconds_precision: Some(9),
12417 });
12418 assert_eq!(
12419 "INTERVAL '123:45.67' MINUTE (10) TO SECOND (9)",
12420 format!("{interval}"),
12421 );
12422
12423 let interval = Expr::Interval(Interval {
12424 value: Box::new(Expr::Value(
12425 Value::SingleQuotedString(String::from("5")).with_empty_span(),
12426 )),
12427 leading_field: Some(DateTimeField::Second),
12428 leading_precision: Some(1),
12429 last_field: None,
12430 fractional_seconds_precision: Some(3),
12431 });
12432 assert_eq!("INTERVAL '5' SECOND (1, 3)", format!("{interval}"));
12433 }
12434
12435 #[test]
12436 fn test_one_or_many_with_parens_deref() {
12437 use core::ops::Index;
12438
12439 let one = OneOrManyWithParens::One("a");
12440
12441 assert_eq!(one.deref(), &["a"]);
12442 assert_eq!(<OneOrManyWithParens<_> as Deref>::deref(&one), &["a"]);
12443
12444 assert_eq!(one[0], "a");
12445 assert_eq!(one.index(0), &"a");
12446 assert_eq!(
12447 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&one, 0),
12448 &"a"
12449 );
12450
12451 assert_eq!(one.len(), 1);
12452 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&one), 1);
12453
12454 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12455
12456 assert_eq!(many1.deref(), &["b"]);
12457 assert_eq!(<OneOrManyWithParens<_> as Deref>::deref(&many1), &["b"]);
12458
12459 assert_eq!(many1[0], "b");
12460 assert_eq!(many1.index(0), &"b");
12461 assert_eq!(
12462 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many1, 0),
12463 &"b"
12464 );
12465
12466 assert_eq!(many1.len(), 1);
12467 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&many1), 1);
12468
12469 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12470
12471 assert_eq!(many2.deref(), &["c", "d"]);
12472 assert_eq!(
12473 <OneOrManyWithParens<_> as Deref>::deref(&many2),
12474 &["c", "d"]
12475 );
12476
12477 assert_eq!(many2[0], "c");
12478 assert_eq!(many2.index(0), &"c");
12479 assert_eq!(
12480 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many2, 0),
12481 &"c"
12482 );
12483
12484 assert_eq!(many2[1], "d");
12485 assert_eq!(many2.index(1), &"d");
12486 assert_eq!(
12487 <<OneOrManyWithParens<_> as Deref>::Target as Index<usize>>::index(&many2, 1),
12488 &"d"
12489 );
12490
12491 assert_eq!(many2.len(), 2);
12492 assert_eq!(<OneOrManyWithParens<_> as Deref>::Target::len(&many2), 2);
12493 }
12494
12495 #[test]
12496 fn test_one_or_many_with_parens_as_ref() {
12497 let one = OneOrManyWithParens::One("a");
12498
12499 assert_eq!(one.as_ref(), &["a"]);
12500 assert_eq!(<OneOrManyWithParens<_> as AsRef<_>>::as_ref(&one), &["a"]);
12501
12502 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12503
12504 assert_eq!(many1.as_ref(), &["b"]);
12505 assert_eq!(<OneOrManyWithParens<_> as AsRef<_>>::as_ref(&many1), &["b"]);
12506
12507 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12508
12509 assert_eq!(many2.as_ref(), &["c", "d"]);
12510 assert_eq!(
12511 <OneOrManyWithParens<_> as AsRef<_>>::as_ref(&many2),
12512 &["c", "d"]
12513 );
12514 }
12515
12516 #[test]
12517 fn test_one_or_many_with_parens_ref_into_iter() {
12518 let one = OneOrManyWithParens::One("a");
12519
12520 assert_eq!(Vec::from_iter(&one), vec![&"a"]);
12521
12522 let many1 = OneOrManyWithParens::Many(vec!["b"]);
12523
12524 assert_eq!(Vec::from_iter(&many1), vec![&"b"]);
12525
12526 let many2 = OneOrManyWithParens::Many(vec!["c", "d"]);
12527
12528 assert_eq!(Vec::from_iter(&many2), vec![&"c", &"d"]);
12529 }
12530
12531 #[test]
12532 fn test_one_or_many_with_parens_value_into_iter() {
12533 use core::iter::once;
12534
12535 fn test_steps<I>(ours: OneOrManyWithParens<usize>, inner: I, n: usize)
12537 where
12538 I: IntoIterator<Item = usize, IntoIter: DoubleEndedIterator + Clone> + Clone,
12539 {
12540 fn checks<I>(ours: OneOrManyWithParensIntoIter<usize>, inner: I)
12541 where
12542 I: Iterator<Item = usize> + Clone + DoubleEndedIterator,
12543 {
12544 assert_eq!(ours.size_hint(), inner.size_hint());
12545 assert_eq!(ours.clone().count(), inner.clone().count());
12546
12547 assert_eq!(
12548 ours.clone().fold(1, |a, v| a + v),
12549 inner.clone().fold(1, |a, v| a + v)
12550 );
12551
12552 assert_eq!(Vec::from_iter(ours.clone()), Vec::from_iter(inner.clone()));
12553 assert_eq!(
12554 Vec::from_iter(ours.clone().rev()),
12555 Vec::from_iter(inner.clone().rev())
12556 );
12557 }
12558
12559 let mut ours_next = ours.clone().into_iter();
12560 let mut inner_next = inner.clone().into_iter();
12561
12562 for _ in 0..n {
12563 checks(ours_next.clone(), inner_next.clone());
12564
12565 assert_eq!(ours_next.next(), inner_next.next());
12566 }
12567
12568 let mut ours_next_back = ours.clone().into_iter();
12569 let mut inner_next_back = inner.clone().into_iter();
12570
12571 for _ in 0..n {
12572 checks(ours_next_back.clone(), inner_next_back.clone());
12573
12574 assert_eq!(ours_next_back.next_back(), inner_next_back.next_back());
12575 }
12576
12577 let mut ours_mixed = ours.clone().into_iter();
12578 let mut inner_mixed = inner.clone().into_iter();
12579
12580 for i in 0..n {
12581 checks(ours_mixed.clone(), inner_mixed.clone());
12582
12583 if i % 2 == 0 {
12584 assert_eq!(ours_mixed.next_back(), inner_mixed.next_back());
12585 } else {
12586 assert_eq!(ours_mixed.next(), inner_mixed.next());
12587 }
12588 }
12589
12590 let mut ours_mixed2 = ours.into_iter();
12591 let mut inner_mixed2 = inner.into_iter();
12592
12593 for i in 0..n {
12594 checks(ours_mixed2.clone(), inner_mixed2.clone());
12595
12596 if i % 2 == 0 {
12597 assert_eq!(ours_mixed2.next(), inner_mixed2.next());
12598 } else {
12599 assert_eq!(ours_mixed2.next_back(), inner_mixed2.next_back());
12600 }
12601 }
12602 }
12603
12604 test_steps(OneOrManyWithParens::One(1), once(1), 3);
12605 test_steps(OneOrManyWithParens::Many(vec![2]), vec![2], 3);
12606 test_steps(OneOrManyWithParens::Many(vec![3, 4]), vec![3, 4], 4);
12607 }
12608
12609 #[test]
12612 fn test_ident_ord() {
12613 let mut a = Ident::with_span(Span::new(Location::new(1, 1), Location::new(1, 1)), "a");
12614 let mut b = Ident::with_span(Span::new(Location::new(2, 2), Location::new(2, 2)), "b");
12615
12616 assert!(a < b);
12617 std::mem::swap(&mut a.span, &mut b.span);
12618 assert!(a < b);
12619 }
12620}