1#[cfg(not(feature = "std"))]
22use alloc::{
23 boxed::Box,
24 format,
25 string::{String, ToString},
26 vec,
27 vec::Vec,
28};
29use core::fmt::{self, Display, Write};
30
31#[cfg(feature = "serde")]
32use serde::{Deserialize, Serialize};
33
34#[cfg(feature = "visitor")]
35use sqlparser_derive::{Visit, VisitMut};
36
37use crate::ast::value::escape_single_quote_string;
38use crate::ast::{
39 display_comma_separated, display_separated,
40 table_constraints::{
41 CheckConstraint, ForeignKeyConstraint, PrimaryKeyConstraint, TableConstraint,
42 UniqueConstraint,
43 },
44 ArgMode, AttachedToken, CommentDef, ConditionalStatements, CreateFunctionBody,
45 CreateFunctionUsing, CreateServerOption, CreateTableLikeKind, CreateTableOptions,
46 CreateViewParams, DataType, Expr,
47 FileFormat, FunctionBehavior, FunctionCalledOnNull, FunctionDefinitionSetParam, FunctionDesc,
48 FunctionDeterminismSpecifier, FunctionParallel, FunctionSecurity, HiveDistributionStyle,
49 HiveFormat, HiveIOFormat, HiveRowFormat, HiveSetLocation, Ident, InitializeKind,
50 MySQLColumnPosition, ObjectName, OnCommit, OneOrManyWithParens, OperateFunctionArg,
51 OrderByExpr, ProjectionSelect, Query, RefreshModeKind, ResetConfig, RowAccessPolicy,
52 SequenceOptions, Spanned, SqlOption, StorageLifecyclePolicy, StorageSerializationPolicy,
53 TableVersion, Tag, TriggerEvent, TriggerExecBody, TriggerObject, TriggerPeriod,
54 TriggerReferencing, Value, ValueWithSpan, WrappedCollection,
55};
56use crate::display_utils::{DisplayCommaSeparated, Indent, NewLine, SpaceOrNewline};
57use crate::keywords::Keyword;
58use crate::tokenizer::{Span, Token};
59
60#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
62#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
63#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
64pub struct IndexColumn {
65 pub column: OrderByExpr,
67 pub operator_class: Option<ObjectName>,
69}
70
71impl From<Ident> for IndexColumn {
72 fn from(c: Ident) -> Self {
73 Self {
74 column: OrderByExpr::from(c),
75 operator_class: None,
76 }
77 }
78}
79
80impl<'a> From<&'a str> for IndexColumn {
81 fn from(c: &'a str) -> Self {
82 let ident = Ident::new(c);
83 ident.into()
84 }
85}
86
87impl fmt::Display for IndexColumn {
88 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
89 write!(f, "{}", self.column)?;
90 if let Some(operator_class) = &self.operator_class {
91 write!(f, " {operator_class}")?;
92 }
93 Ok(())
94 }
95}
96
97#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
100#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
101#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
102pub enum ReplicaIdentity {
103 Nothing,
105 Full,
107 Default,
109 Index(Ident),
111}
112
113impl fmt::Display for ReplicaIdentity {
114 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
115 match self {
116 ReplicaIdentity::Nothing => f.write_str("NOTHING"),
117 ReplicaIdentity::Full => f.write_str("FULL"),
118 ReplicaIdentity::Default => f.write_str("DEFAULT"),
119 ReplicaIdentity::Index(idx) => write!(f, "USING INDEX {idx}"),
120 }
121 }
122}
123
124#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
126#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
127#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
128pub enum AlterTableOperation {
129 AddConstraint {
131 constraint: TableConstraint,
133 not_valid: bool,
135 },
136 AddColumn {
138 column_keyword: bool,
140 if_not_exists: bool,
142 column_def: ColumnDef,
144 column_position: Option<MySQLColumnPosition>,
146 },
147 AddProjection {
152 if_not_exists: bool,
154 name: Ident,
156 select: ProjectionSelect,
158 },
159 DropProjection {
164 if_exists: bool,
166 name: Ident,
168 },
169 MaterializeProjection {
174 if_exists: bool,
176 name: Ident,
178 partition: Option<Ident>,
180 },
181 ClearProjection {
186 if_exists: bool,
188 name: Ident,
190 partition: Option<Ident>,
192 },
193 DisableRowLevelSecurity,
198 DisableRule {
202 name: Ident,
204 },
205 DisableTrigger {
209 name: Ident,
211 },
212 DropConstraint {
214 if_exists: bool,
216 name: Ident,
218 drop_behavior: Option<DropBehavior>,
220 },
221 DropColumn {
223 has_column_keyword: bool,
225 column_names: Vec<Ident>,
227 if_exists: bool,
229 drop_behavior: Option<DropBehavior>,
231 },
232 AttachPartition {
236 partition: Partition,
240 },
241 DetachPartition {
245 partition: Partition,
248 },
249 FreezePartition {
253 partition: Partition,
255 with_name: Option<Ident>,
257 },
258 UnfreezePartition {
262 partition: Partition,
264 with_name: Option<Ident>,
266 },
267 DropPrimaryKey {
272 drop_behavior: Option<DropBehavior>,
274 },
275 DropForeignKey {
280 name: Ident,
282 drop_behavior: Option<DropBehavior>,
284 },
285 DropIndex {
289 name: Ident,
291 },
292 EnableAlwaysRule {
296 name: Ident,
298 },
299 EnableAlwaysTrigger {
303 name: Ident,
305 },
306 EnableReplicaRule {
310 name: Ident,
312 },
313 EnableReplicaTrigger {
317 name: Ident,
319 },
320 EnableRowLevelSecurity,
325 ForceRowLevelSecurity,
330 NoForceRowLevelSecurity,
335 EnableRule {
339 name: Ident,
341 },
342 EnableTrigger {
346 name: Ident,
348 },
349 RenamePartitions {
351 old_partitions: Vec<Expr>,
353 new_partitions: Vec<Expr>,
355 },
356 ReplicaIdentity {
361 identity: ReplicaIdentity,
363 },
364 AddPartitions {
366 if_not_exists: bool,
368 new_partitions: Vec<Partition>,
370 },
371 DropPartitions {
373 partitions: Vec<Expr>,
375 if_exists: bool,
377 },
378 RenameColumn {
380 old_column_name: Ident,
382 new_column_name: Ident,
384 },
385 RenameTable {
387 table_name: RenameTableNameKind,
389 },
390 ChangeColumn {
393 old_name: Ident,
395 new_name: Ident,
397 data_type: DataType,
399 options: Vec<ColumnOption>,
401 column_position: Option<MySQLColumnPosition>,
403 },
404 ModifyColumn {
407 col_name: Ident,
409 data_type: DataType,
411 options: Vec<ColumnOption>,
413 column_position: Option<MySQLColumnPosition>,
415 },
416 RenameConstraint {
421 old_name: Ident,
423 new_name: Ident,
425 },
426 AlterColumn {
429 column_name: Ident,
431 op: AlterColumnOperation,
433 },
434 SwapWith {
438 table_name: ObjectName,
440 },
441 SetTblProperties {
443 table_properties: Vec<SqlOption>,
445 },
446 OwnerTo {
450 new_owner: Owner,
452 },
453 ClusterBy {
456 exprs: Vec<Expr>,
458 },
459 DropClusteringKey,
461 AlterSortKey {
464 columns: Vec<Expr>,
466 },
467 SuspendRecluster,
469 ResumeRecluster,
471 Refresh {
477 subpath: Option<String>,
479 },
480 Suspend,
484 Resume,
488 Algorithm {
494 equals: bool,
496 algorithm: AlterTableAlgorithm,
498 },
499
500 Lock {
506 equals: bool,
508 lock: AlterTableLock,
510 },
511 AutoIncrement {
517 equals: bool,
519 value: ValueWithSpan,
521 },
522 ValidateConstraint {
524 name: Ident,
526 },
527 SetOptionsParens {
535 options: Vec<SqlOption>,
537 },
538}
539
540#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
544#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
545#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
546pub enum AlterPolicyOperation {
547 Rename {
549 new_name: Ident,
551 },
552 Apply {
554 to: Option<Vec<Owner>>,
556 using: Option<Expr>,
558 with_check: Option<Expr>,
560 },
561}
562
563impl fmt::Display for AlterPolicyOperation {
564 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
565 match self {
566 AlterPolicyOperation::Rename { new_name } => {
567 write!(f, " RENAME TO {new_name}")
568 }
569 AlterPolicyOperation::Apply {
570 to,
571 using,
572 with_check,
573 } => {
574 if let Some(to) = to {
575 write!(f, " TO {}", display_comma_separated(to))?;
576 }
577 if let Some(using) = using {
578 write!(f, " USING ({using})")?;
579 }
580 if let Some(with_check) = with_check {
581 write!(f, " WITH CHECK ({with_check})")?;
582 }
583 Ok(())
584 }
585 }
586 }
587}
588
589#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
593#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
594#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
595pub enum AlterTableAlgorithm {
597 Default,
599 Instant,
601 Inplace,
603 Copy,
605}
606
607impl fmt::Display for AlterTableAlgorithm {
608 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
609 f.write_str(match self {
610 Self::Default => "DEFAULT",
611 Self::Instant => "INSTANT",
612 Self::Inplace => "INPLACE",
613 Self::Copy => "COPY",
614 })
615 }
616}
617
618#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
622#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
623#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
624pub enum AlterTableLock {
626 Default,
628 None,
630 Shared,
632 Exclusive,
634}
635
636impl fmt::Display for AlterTableLock {
637 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
638 f.write_str(match self {
639 Self::Default => "DEFAULT",
640 Self::None => "NONE",
641 Self::Shared => "SHARED",
642 Self::Exclusive => "EXCLUSIVE",
643 })
644 }
645}
646
647#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
648#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
649#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
650pub enum Owner {
652 Ident(Ident),
654 CurrentRole,
656 CurrentUser,
658 SessionUser,
660}
661
662impl fmt::Display for Owner {
663 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
664 match self {
665 Owner::Ident(ident) => write!(f, "{ident}"),
666 Owner::CurrentRole => write!(f, "CURRENT_ROLE"),
667 Owner::CurrentUser => write!(f, "CURRENT_USER"),
668 Owner::SessionUser => write!(f, "SESSION_USER"),
669 }
670 }
671}
672
673#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
674#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
675#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
676pub enum AlterConnectorOwner {
678 User(Ident),
680 Role(Ident),
682}
683
684impl fmt::Display for AlterConnectorOwner {
685 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
686 match self {
687 AlterConnectorOwner::User(ident) => write!(f, "USER {ident}"),
688 AlterConnectorOwner::Role(ident) => write!(f, "ROLE {ident}"),
689 }
690 }
691}
692
693#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
694#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
695#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
696pub enum AlterIndexOperation {
698 RenameIndex {
700 index_name: ObjectName,
702 },
703}
704
705impl fmt::Display for AlterTableOperation {
706 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
707 match self {
708 AlterTableOperation::AddPartitions {
709 if_not_exists,
710 new_partitions,
711 } => write!(
712 f,
713 "ADD{ine} {}",
714 display_separated(new_partitions, " "),
715 ine = if *if_not_exists { " IF NOT EXISTS" } else { "" }
716 ),
717 AlterTableOperation::AddConstraint {
718 not_valid,
719 constraint,
720 } => {
721 write!(f, "ADD {constraint}")?;
722 if *not_valid {
723 write!(f, " NOT VALID")?;
724 }
725 Ok(())
726 }
727 AlterTableOperation::AddColumn {
728 column_keyword,
729 if_not_exists,
730 column_def,
731 column_position,
732 } => {
733 write!(f, "ADD")?;
734 if *column_keyword {
735 write!(f, " COLUMN")?;
736 }
737 if *if_not_exists {
738 write!(f, " IF NOT EXISTS")?;
739 }
740 write!(f, " {column_def}")?;
741
742 if let Some(position) = column_position {
743 write!(f, " {position}")?;
744 }
745
746 Ok(())
747 }
748 AlterTableOperation::AddProjection {
749 if_not_exists,
750 name,
751 select: query,
752 } => {
753 write!(f, "ADD PROJECTION")?;
754 if *if_not_exists {
755 write!(f, " IF NOT EXISTS")?;
756 }
757 write!(f, " {name} ({query})")
758 }
759 AlterTableOperation::Algorithm { equals, algorithm } => {
760 write!(
761 f,
762 "ALGORITHM {}{}",
763 if *equals { "= " } else { "" },
764 algorithm
765 )
766 }
767 AlterTableOperation::DropProjection { if_exists, name } => {
768 write!(f, "DROP PROJECTION")?;
769 if *if_exists {
770 write!(f, " IF EXISTS")?;
771 }
772 write!(f, " {name}")
773 }
774 AlterTableOperation::MaterializeProjection {
775 if_exists,
776 name,
777 partition,
778 } => {
779 write!(f, "MATERIALIZE PROJECTION")?;
780 if *if_exists {
781 write!(f, " IF EXISTS")?;
782 }
783 write!(f, " {name}")?;
784 if let Some(partition) = partition {
785 write!(f, " IN PARTITION {partition}")?;
786 }
787 Ok(())
788 }
789 AlterTableOperation::ClearProjection {
790 if_exists,
791 name,
792 partition,
793 } => {
794 write!(f, "CLEAR PROJECTION")?;
795 if *if_exists {
796 write!(f, " IF EXISTS")?;
797 }
798 write!(f, " {name}")?;
799 if let Some(partition) = partition {
800 write!(f, " IN PARTITION {partition}")?;
801 }
802 Ok(())
803 }
804 AlterTableOperation::AlterColumn { column_name, op } => {
805 write!(f, "ALTER COLUMN {column_name} {op}")
806 }
807 AlterTableOperation::DisableRowLevelSecurity => {
808 write!(f, "DISABLE ROW LEVEL SECURITY")
809 }
810 AlterTableOperation::DisableRule { name } => {
811 write!(f, "DISABLE RULE {name}")
812 }
813 AlterTableOperation::DisableTrigger { name } => {
814 write!(f, "DISABLE TRIGGER {name}")
815 }
816 AlterTableOperation::DropPartitions {
817 partitions,
818 if_exists,
819 } => write!(
820 f,
821 "DROP{ie} PARTITION ({})",
822 display_comma_separated(partitions),
823 ie = if *if_exists { " IF EXISTS" } else { "" }
824 ),
825 AlterTableOperation::DropConstraint {
826 if_exists,
827 name,
828 drop_behavior,
829 } => {
830 write!(
831 f,
832 "DROP CONSTRAINT {}{}",
833 if *if_exists { "IF EXISTS " } else { "" },
834 name
835 )?;
836 if let Some(drop_behavior) = drop_behavior {
837 write!(f, " {drop_behavior}")?;
838 }
839 Ok(())
840 }
841 AlterTableOperation::DropPrimaryKey { drop_behavior } => {
842 write!(f, "DROP PRIMARY KEY")?;
843 if let Some(drop_behavior) = drop_behavior {
844 write!(f, " {drop_behavior}")?;
845 }
846 Ok(())
847 }
848 AlterTableOperation::DropForeignKey {
849 name,
850 drop_behavior,
851 } => {
852 write!(f, "DROP FOREIGN KEY {name}")?;
853 if let Some(drop_behavior) = drop_behavior {
854 write!(f, " {drop_behavior}")?;
855 }
856 Ok(())
857 }
858 AlterTableOperation::DropIndex { name } => write!(f, "DROP INDEX {name}"),
859 AlterTableOperation::DropColumn {
860 has_column_keyword,
861 column_names: column_name,
862 if_exists,
863 drop_behavior,
864 } => {
865 write!(
866 f,
867 "DROP {}{}{}",
868 if *has_column_keyword { "COLUMN " } else { "" },
869 if *if_exists { "IF EXISTS " } else { "" },
870 display_comma_separated(column_name),
871 )?;
872 if let Some(drop_behavior) = drop_behavior {
873 write!(f, " {drop_behavior}")?;
874 }
875 Ok(())
876 }
877 AlterTableOperation::AttachPartition { partition } => {
878 write!(f, "ATTACH {partition}")
879 }
880 AlterTableOperation::DetachPartition { partition } => {
881 write!(f, "DETACH {partition}")
882 }
883 AlterTableOperation::EnableAlwaysRule { name } => {
884 write!(f, "ENABLE ALWAYS RULE {name}")
885 }
886 AlterTableOperation::EnableAlwaysTrigger { name } => {
887 write!(f, "ENABLE ALWAYS TRIGGER {name}")
888 }
889 AlterTableOperation::EnableReplicaRule { name } => {
890 write!(f, "ENABLE REPLICA RULE {name}")
891 }
892 AlterTableOperation::EnableReplicaTrigger { name } => {
893 write!(f, "ENABLE REPLICA TRIGGER {name}")
894 }
895 AlterTableOperation::EnableRowLevelSecurity => {
896 write!(f, "ENABLE ROW LEVEL SECURITY")
897 }
898 AlterTableOperation::ForceRowLevelSecurity => {
899 write!(f, "FORCE ROW LEVEL SECURITY")
900 }
901 AlterTableOperation::NoForceRowLevelSecurity => {
902 write!(f, "NO FORCE ROW LEVEL SECURITY")
903 }
904 AlterTableOperation::EnableRule { name } => {
905 write!(f, "ENABLE RULE {name}")
906 }
907 AlterTableOperation::EnableTrigger { name } => {
908 write!(f, "ENABLE TRIGGER {name}")
909 }
910 AlterTableOperation::RenamePartitions {
911 old_partitions,
912 new_partitions,
913 } => write!(
914 f,
915 "PARTITION ({}) RENAME TO PARTITION ({})",
916 display_comma_separated(old_partitions),
917 display_comma_separated(new_partitions)
918 ),
919 AlterTableOperation::RenameColumn {
920 old_column_name,
921 new_column_name,
922 } => write!(f, "RENAME COLUMN {old_column_name} TO {new_column_name}"),
923 AlterTableOperation::RenameTable { table_name } => {
924 write!(f, "RENAME {table_name}")
925 }
926 AlterTableOperation::ChangeColumn {
927 old_name,
928 new_name,
929 data_type,
930 options,
931 column_position,
932 } => {
933 write!(f, "CHANGE COLUMN {old_name} {new_name} {data_type}")?;
934 if !options.is_empty() {
935 write!(f, " {}", display_separated(options, " "))?;
936 }
937 if let Some(position) = column_position {
938 write!(f, " {position}")?;
939 }
940
941 Ok(())
942 }
943 AlterTableOperation::ModifyColumn {
944 col_name,
945 data_type,
946 options,
947 column_position,
948 } => {
949 write!(f, "MODIFY COLUMN {col_name} {data_type}")?;
950 if !options.is_empty() {
951 write!(f, " {}", display_separated(options, " "))?;
952 }
953 if let Some(position) = column_position {
954 write!(f, " {position}")?;
955 }
956
957 Ok(())
958 }
959 AlterTableOperation::RenameConstraint { old_name, new_name } => {
960 write!(f, "RENAME CONSTRAINT {old_name} TO {new_name}")
961 }
962 AlterTableOperation::SwapWith { table_name } => {
963 write!(f, "SWAP WITH {table_name}")
964 }
965 AlterTableOperation::OwnerTo { new_owner } => {
966 write!(f, "OWNER TO {new_owner}")
967 }
968 AlterTableOperation::SetTblProperties { table_properties } => {
969 write!(
970 f,
971 "SET TBLPROPERTIES({})",
972 display_comma_separated(table_properties)
973 )
974 }
975 AlterTableOperation::FreezePartition {
976 partition,
977 with_name,
978 } => {
979 write!(f, "FREEZE {partition}")?;
980 if let Some(name) = with_name {
981 write!(f, " WITH NAME {name}")?;
982 }
983 Ok(())
984 }
985 AlterTableOperation::UnfreezePartition {
986 partition,
987 with_name,
988 } => {
989 write!(f, "UNFREEZE {partition}")?;
990 if let Some(name) = with_name {
991 write!(f, " WITH NAME {name}")?;
992 }
993 Ok(())
994 }
995 AlterTableOperation::ClusterBy { exprs } => {
996 write!(f, "CLUSTER BY ({})", display_comma_separated(exprs))?;
997 Ok(())
998 }
999 AlterTableOperation::DropClusteringKey => {
1000 write!(f, "DROP CLUSTERING KEY")?;
1001 Ok(())
1002 }
1003 AlterTableOperation::AlterSortKey { columns } => {
1004 write!(f, "ALTER SORTKEY({})", display_comma_separated(columns))?;
1005 Ok(())
1006 }
1007 AlterTableOperation::SuspendRecluster => {
1008 write!(f, "SUSPEND RECLUSTER")?;
1009 Ok(())
1010 }
1011 AlterTableOperation::ResumeRecluster => {
1012 write!(f, "RESUME RECLUSTER")?;
1013 Ok(())
1014 }
1015 AlterTableOperation::Refresh { subpath } => {
1016 write!(f, "REFRESH")?;
1017 if let Some(path) = subpath {
1018 write!(f, " '{path}'")?;
1019 }
1020 Ok(())
1021 }
1022 AlterTableOperation::Suspend => {
1023 write!(f, "SUSPEND")
1024 }
1025 AlterTableOperation::Resume => {
1026 write!(f, "RESUME")
1027 }
1028 AlterTableOperation::AutoIncrement { equals, value } => {
1029 write!(
1030 f,
1031 "AUTO_INCREMENT {}{}",
1032 if *equals { "= " } else { "" },
1033 value
1034 )
1035 }
1036 AlterTableOperation::Lock { equals, lock } => {
1037 write!(f, "LOCK {}{}", if *equals { "= " } else { "" }, lock)
1038 }
1039 AlterTableOperation::ReplicaIdentity { identity } => {
1040 write!(f, "REPLICA IDENTITY {identity}")
1041 }
1042 AlterTableOperation::ValidateConstraint { name } => {
1043 write!(f, "VALIDATE CONSTRAINT {name}")
1044 }
1045 AlterTableOperation::SetOptionsParens { options } => {
1046 write!(f, "SET ({})", display_comma_separated(options))
1047 }
1048 }
1049 }
1050}
1051
1052impl fmt::Display for AlterIndexOperation {
1053 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1054 match self {
1055 AlterIndexOperation::RenameIndex { index_name } => {
1056 write!(f, "RENAME TO {index_name}")
1057 }
1058 }
1059 }
1060}
1061
1062#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1064#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1065#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1066pub struct AlterType {
1067 pub name: ObjectName,
1069 pub operation: AlterTypeOperation,
1071}
1072
1073#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1075#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1076#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1077pub enum AlterTypeOperation {
1078 Rename(AlterTypeRename),
1080 AddValue(AlterTypeAddValue),
1082 RenameValue(AlterTypeRenameValue),
1084}
1085
1086#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1088#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1089#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1090pub struct AlterTypeRename {
1091 pub new_name: Ident,
1093}
1094
1095#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1097#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1098#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1099pub struct AlterTypeAddValue {
1100 pub if_not_exists: bool,
1102 pub value: Ident,
1104 pub position: Option<AlterTypeAddValuePosition>,
1106}
1107
1108#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1110#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1111#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1112pub enum AlterTypeAddValuePosition {
1113 Before(Ident),
1115 After(Ident),
1117}
1118
1119#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1121#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1122#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1123pub struct AlterTypeRenameValue {
1124 pub from: Ident,
1126 pub to: Ident,
1128}
1129
1130impl fmt::Display for AlterTypeOperation {
1131 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1132 match self {
1133 Self::Rename(AlterTypeRename { new_name }) => {
1134 write!(f, "RENAME TO {new_name}")
1135 }
1136 Self::AddValue(AlterTypeAddValue {
1137 if_not_exists,
1138 value,
1139 position,
1140 }) => {
1141 write!(f, "ADD VALUE")?;
1142 if *if_not_exists {
1143 write!(f, " IF NOT EXISTS")?;
1144 }
1145 write!(f, " {value}")?;
1146 match position {
1147 Some(AlterTypeAddValuePosition::Before(neighbor_value)) => {
1148 write!(f, " BEFORE {neighbor_value}")?;
1149 }
1150 Some(AlterTypeAddValuePosition::After(neighbor_value)) => {
1151 write!(f, " AFTER {neighbor_value}")?;
1152 }
1153 None => {}
1154 };
1155 Ok(())
1156 }
1157 Self::RenameValue(AlterTypeRenameValue { from, to }) => {
1158 write!(f, "RENAME VALUE {from} TO {to}")
1159 }
1160 }
1161 }
1162}
1163
1164#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1167#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1168#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1169pub struct AlterOperator {
1170 pub name: ObjectName,
1172 pub left_type: Option<DataType>,
1174 pub right_type: DataType,
1176 pub operation: AlterOperatorOperation,
1178}
1179
1180#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1182#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1183#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1184pub enum AlterOperatorOperation {
1185 OwnerTo(Owner),
1187 SetSchema {
1190 schema_name: ObjectName,
1192 },
1193 Set {
1195 options: Vec<OperatorOption>,
1197 },
1198}
1199
1200#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1202#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1203#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1204pub enum OperatorOption {
1205 Restrict(Option<ObjectName>),
1207 Join(Option<ObjectName>),
1209 Commutator(ObjectName),
1211 Negator(ObjectName),
1213 Hashes,
1215 Merges,
1217}
1218
1219impl fmt::Display for AlterOperator {
1220 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1221 write!(f, "ALTER OPERATOR {} (", self.name)?;
1222 if let Some(left_type) = &self.left_type {
1223 write!(f, "{}", left_type)?;
1224 } else {
1225 write!(f, "NONE")?;
1226 }
1227 write!(f, ", {}) {}", self.right_type, self.operation)
1228 }
1229}
1230
1231impl fmt::Display for AlterOperatorOperation {
1232 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1233 match self {
1234 Self::OwnerTo(owner) => write!(f, "OWNER TO {}", owner),
1235 Self::SetSchema { schema_name } => write!(f, "SET SCHEMA {}", schema_name),
1236 Self::Set { options } => {
1237 write!(f, "SET (")?;
1238 for (i, option) in options.iter().enumerate() {
1239 if i > 0 {
1240 write!(f, ", ")?;
1241 }
1242 write!(f, "{}", option)?;
1243 }
1244 write!(f, ")")
1245 }
1246 }
1247 }
1248}
1249
1250impl fmt::Display for OperatorOption {
1251 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1252 match self {
1253 Self::Restrict(Some(proc_name)) => write!(f, "RESTRICT = {}", proc_name),
1254 Self::Restrict(None) => write!(f, "RESTRICT = NONE"),
1255 Self::Join(Some(proc_name)) => write!(f, "JOIN = {}", proc_name),
1256 Self::Join(None) => write!(f, "JOIN = NONE"),
1257 Self::Commutator(op_name) => write!(f, "COMMUTATOR = {}", op_name),
1258 Self::Negator(op_name) => write!(f, "NEGATOR = {}", op_name),
1259 Self::Hashes => write!(f, "HASHES"),
1260 Self::Merges => write!(f, "MERGES"),
1261 }
1262 }
1263}
1264
1265#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1267#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1268#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1269pub enum AlterColumnOperation {
1270 SetNotNull,
1272 DropNotNull,
1274 SetDefault {
1277 value: Expr,
1279 },
1280 DropDefault,
1282 SetDataType {
1284 data_type: DataType,
1286 using: Option<Expr>,
1288 had_set: bool,
1290 },
1291
1292 AddGenerated {
1296 generated_as: Option<GeneratedAs>,
1298 sequence_options: Option<Vec<SequenceOptions>>,
1300 },
1301}
1302
1303impl fmt::Display for AlterColumnOperation {
1304 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1305 match self {
1306 AlterColumnOperation::SetNotNull => write!(f, "SET NOT NULL",),
1307 AlterColumnOperation::DropNotNull => write!(f, "DROP NOT NULL",),
1308 AlterColumnOperation::SetDefault { value } => {
1309 write!(f, "SET DEFAULT {value}")
1310 }
1311 AlterColumnOperation::DropDefault => {
1312 write!(f, "DROP DEFAULT")
1313 }
1314 AlterColumnOperation::SetDataType {
1315 data_type,
1316 using,
1317 had_set,
1318 } => {
1319 if *had_set {
1320 write!(f, "SET DATA ")?;
1321 }
1322 write!(f, "TYPE {data_type}")?;
1323 if let Some(expr) = using {
1324 write!(f, " USING {expr}")?;
1325 }
1326 Ok(())
1327 }
1328 AlterColumnOperation::AddGenerated {
1329 generated_as,
1330 sequence_options,
1331 } => {
1332 let generated_as = match generated_as {
1333 Some(GeneratedAs::Always) => " ALWAYS",
1334 Some(GeneratedAs::ByDefault) => " BY DEFAULT",
1335 _ => "",
1336 };
1337
1338 write!(f, "ADD GENERATED{generated_as} AS IDENTITY",)?;
1339 if let Some(options) = sequence_options {
1340 write!(f, " (")?;
1341
1342 for sequence_option in options {
1343 write!(f, "{sequence_option}")?;
1344 }
1345
1346 write!(f, " )")?;
1347 }
1348 Ok(())
1349 }
1350 }
1351 }
1352}
1353
1354#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1362#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1363#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1364pub enum KeyOrIndexDisplay {
1365 None,
1367 Key,
1369 Index,
1371}
1372
1373impl KeyOrIndexDisplay {
1374 pub fn is_none(self) -> bool {
1376 matches!(self, Self::None)
1377 }
1378}
1379
1380impl fmt::Display for KeyOrIndexDisplay {
1381 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1382 let left_space = matches!(f.align(), Some(fmt::Alignment::Right));
1383
1384 if left_space && !self.is_none() {
1385 f.write_char(' ')?
1386 }
1387
1388 match self {
1389 KeyOrIndexDisplay::None => {
1390 write!(f, "")
1391 }
1392 KeyOrIndexDisplay::Key => {
1393 write!(f, "KEY")
1394 }
1395 KeyOrIndexDisplay::Index => {
1396 write!(f, "INDEX")
1397 }
1398 }
1399 }
1400}
1401
1402#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1411#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1412#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1413pub enum IndexType {
1414 BTree,
1416 Hash,
1418 GIN,
1420 GiST,
1422 SPGiST,
1424 BRIN,
1426 Bloom,
1428 Custom(Ident),
1431}
1432
1433impl fmt::Display for IndexType {
1434 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1435 match self {
1436 Self::BTree => write!(f, "BTREE"),
1437 Self::Hash => write!(f, "HASH"),
1438 Self::GIN => write!(f, "GIN"),
1439 Self::GiST => write!(f, "GIST"),
1440 Self::SPGiST => write!(f, "SPGIST"),
1441 Self::BRIN => write!(f, "BRIN"),
1442 Self::Bloom => write!(f, "BLOOM"),
1443 Self::Custom(name) => write!(f, "{name}"),
1444 }
1445 }
1446}
1447
1448#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1454#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1455#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1456pub enum IndexOption {
1457 Using(IndexType),
1461 Comment(String),
1463}
1464
1465impl fmt::Display for IndexOption {
1466 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1467 match self {
1468 Self::Using(index_type) => write!(f, "USING {index_type}"),
1469 Self::Comment(s) => write!(f, "COMMENT '{s}'"),
1470 }
1471 }
1472}
1473
1474#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
1478#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1479#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1480pub enum NullsDistinctOption {
1481 None,
1483 Distinct,
1485 NotDistinct,
1487}
1488
1489impl fmt::Display for NullsDistinctOption {
1490 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1491 match self {
1492 Self::None => Ok(()),
1493 Self::Distinct => write!(f, " NULLS DISTINCT"),
1494 Self::NotDistinct => write!(f, " NULLS NOT DISTINCT"),
1495 }
1496 }
1497}
1498
1499#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1500#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1501#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1502pub struct ProcedureParam {
1504 pub name: Ident,
1506 pub data_type: DataType,
1508 pub mode: Option<ArgMode>,
1510 pub default: Option<Expr>,
1512}
1513
1514impl fmt::Display for ProcedureParam {
1515 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1516 if let Some(mode) = &self.mode {
1517 if let Some(default) = &self.default {
1518 write!(f, "{mode} {} {} = {}", self.name, self.data_type, default)
1519 } else {
1520 write!(f, "{mode} {} {}", self.name, self.data_type)
1521 }
1522 } else if let Some(default) = &self.default {
1523 write!(f, "{} {} = {}", self.name, self.data_type, default)
1524 } else {
1525 write!(f, "{} {}", self.name, self.data_type)
1526 }
1527 }
1528}
1529
1530#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1532#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1533#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1534pub struct ColumnDef {
1535 pub name: Ident,
1537 pub data_type: DataType,
1539 pub options: Vec<ColumnOptionDef>,
1541}
1542
1543impl fmt::Display for ColumnDef {
1544 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1545 if self.data_type == DataType::Unspecified {
1546 write!(f, "{}", self.name)?;
1547 } else {
1548 write!(f, "{} {}", self.name, self.data_type)?;
1549 }
1550 for option in &self.options {
1551 write!(f, " {option}")?;
1552 }
1553 Ok(())
1554 }
1555}
1556
1557#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1574#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1575#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1576pub struct ViewColumnDef {
1577 pub name: Ident,
1579 pub data_type: Option<DataType>,
1581 pub options: Option<ColumnOptions>,
1583}
1584
1585#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1586#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1587#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1588pub enum ColumnOptions {
1590 CommaSeparated(Vec<ColumnOption>),
1592 SpaceSeparated(Vec<ColumnOption>),
1594}
1595
1596impl ColumnOptions {
1597 pub fn as_slice(&self) -> &[ColumnOption] {
1599 match self {
1600 ColumnOptions::CommaSeparated(options) => options.as_slice(),
1601 ColumnOptions::SpaceSeparated(options) => options.as_slice(),
1602 }
1603 }
1604}
1605
1606impl fmt::Display for ViewColumnDef {
1607 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1608 write!(f, "{}", self.name)?;
1609 if let Some(data_type) = self.data_type.as_ref() {
1610 write!(f, " {data_type}")?;
1611 }
1612 if let Some(options) = self.options.as_ref() {
1613 match options {
1614 ColumnOptions::CommaSeparated(column_options) => {
1615 write!(f, " {}", display_comma_separated(column_options.as_slice()))?;
1616 }
1617 ColumnOptions::SpaceSeparated(column_options) => {
1618 write!(f, " {}", display_separated(column_options.as_slice(), " "))?
1619 }
1620 }
1621 }
1622 Ok(())
1623 }
1624}
1625
1626#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1643#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1644#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1645pub struct ColumnOptionDef {
1646 pub name: Option<Ident>,
1648 pub option: ColumnOption,
1650}
1651
1652impl fmt::Display for ColumnOptionDef {
1653 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1654 write!(f, "{}{}", display_constraint_name(&self.name), self.option)
1655 }
1656}
1657
1658#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1666#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1667#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1668pub enum IdentityPropertyKind {
1669 Autoincrement(IdentityProperty),
1677 Identity(IdentityProperty),
1690}
1691
1692impl fmt::Display for IdentityPropertyKind {
1693 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1694 let (command, property) = match self {
1695 IdentityPropertyKind::Identity(property) => ("IDENTITY", property),
1696 IdentityPropertyKind::Autoincrement(property) => ("AUTOINCREMENT", property),
1697 };
1698 write!(f, "{command}")?;
1699 if let Some(parameters) = &property.parameters {
1700 write!(f, "{parameters}")?;
1701 }
1702 if let Some(order) = &property.order {
1703 write!(f, "{order}")?;
1704 }
1705 Ok(())
1706 }
1707}
1708
1709#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1711#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1712#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1713pub struct IdentityProperty {
1714 pub parameters: Option<IdentityPropertyFormatKind>,
1716 pub order: Option<IdentityPropertyOrder>,
1718}
1719
1720#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1735#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1736#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1737pub enum IdentityPropertyFormatKind {
1738 FunctionCall(IdentityParameters),
1746 StartAndIncrement(IdentityParameters),
1753}
1754
1755impl fmt::Display for IdentityPropertyFormatKind {
1756 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1757 match self {
1758 IdentityPropertyFormatKind::FunctionCall(parameters) => {
1759 write!(f, "({}, {})", parameters.seed, parameters.increment)
1760 }
1761 IdentityPropertyFormatKind::StartAndIncrement(parameters) => {
1762 write!(
1763 f,
1764 " START {} INCREMENT {}",
1765 parameters.seed, parameters.increment
1766 )
1767 }
1768 }
1769 }
1770}
1771#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1773#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1774#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1775pub struct IdentityParameters {
1776 pub seed: Expr,
1778 pub increment: Expr,
1780}
1781
1782#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
1789#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1790#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1791pub enum IdentityPropertyOrder {
1792 Order,
1794 NoOrder,
1796}
1797
1798impl fmt::Display for IdentityPropertyOrder {
1799 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1800 match self {
1801 IdentityPropertyOrder::Order => write!(f, " ORDER"),
1802 IdentityPropertyOrder::NoOrder => write!(f, " NOORDER"),
1803 }
1804 }
1805}
1806
1807#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1815#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1816#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1817pub enum ColumnPolicy {
1818 MaskingPolicy(ColumnPolicyProperty),
1820 ProjectionPolicy(ColumnPolicyProperty),
1822}
1823
1824impl fmt::Display for ColumnPolicy {
1825 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1826 let (command, property) = match self {
1827 ColumnPolicy::MaskingPolicy(property) => ("MASKING POLICY", property),
1828 ColumnPolicy::ProjectionPolicy(property) => ("PROJECTION POLICY", property),
1829 };
1830 if property.with {
1831 write!(f, "WITH ")?;
1832 }
1833 write!(f, "{command} {}", property.policy_name)?;
1834 if let Some(using_columns) = &property.using_columns {
1835 write!(f, " USING ({})", display_comma_separated(using_columns))?;
1836 }
1837 Ok(())
1838 }
1839}
1840
1841#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1842#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1843#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1844pub struct ColumnPolicyProperty {
1846 pub with: bool,
1853 pub policy_name: ObjectName,
1855 pub using_columns: Option<Vec<Ident>>,
1857}
1858
1859#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1866#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1867#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1868pub struct TagsColumnOption {
1869 pub with: bool,
1876 pub tags: Vec<Tag>,
1878}
1879
1880impl fmt::Display for TagsColumnOption {
1881 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1882 if self.with {
1883 write!(f, "WITH ")?;
1884 }
1885 write!(f, "TAG ({})", display_comma_separated(&self.tags))?;
1886 Ok(())
1887 }
1888}
1889
1890#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1893#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1894#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1895pub enum ColumnOption {
1896 Null,
1898 NotNull,
1900 Default(Expr),
1902
1903 Materialized(Expr),
1908 Ephemeral(Option<Expr>),
1912 Alias(Expr),
1916
1917 PrimaryKey(PrimaryKeyConstraint),
1919 Unique(UniqueConstraint),
1921 ForeignKey(ForeignKeyConstraint),
1929 Check(CheckConstraint),
1931 DialectSpecific(Vec<Token>),
1935 CharacterSet(ObjectName),
1937 Collation(ObjectName),
1939 Comment(String),
1941 OnUpdate(Expr),
1943 Generated {
1946 generated_as: GeneratedAs,
1948 sequence_options: Option<Vec<SequenceOptions>>,
1950 generation_expr: Option<Expr>,
1952 generation_expr_mode: Option<GeneratedExpressionMode>,
1954 generated_keyword: bool,
1956 },
1957 Options(Vec<SqlOption>),
1965 Identity(IdentityPropertyKind),
1973 OnConflict(Keyword),
1976 Policy(ColumnPolicy),
1984 Tags(TagsColumnOption),
1991 Srid(Box<Expr>),
1998 Invisible,
2005}
2006
2007impl From<UniqueConstraint> for ColumnOption {
2008 fn from(c: UniqueConstraint) -> Self {
2009 ColumnOption::Unique(c)
2010 }
2011}
2012
2013impl From<PrimaryKeyConstraint> for ColumnOption {
2014 fn from(c: PrimaryKeyConstraint) -> Self {
2015 ColumnOption::PrimaryKey(c)
2016 }
2017}
2018
2019impl From<CheckConstraint> for ColumnOption {
2020 fn from(c: CheckConstraint) -> Self {
2021 ColumnOption::Check(c)
2022 }
2023}
2024impl From<ForeignKeyConstraint> for ColumnOption {
2025 fn from(fk: ForeignKeyConstraint) -> Self {
2026 ColumnOption::ForeignKey(fk)
2027 }
2028}
2029
2030impl fmt::Display for ColumnOption {
2031 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2032 use ColumnOption::*;
2033 match self {
2034 Null => write!(f, "NULL"),
2035 NotNull => write!(f, "NOT NULL"),
2036 Default(expr) => write!(f, "DEFAULT {expr}"),
2037 Materialized(expr) => write!(f, "MATERIALIZED {expr}"),
2038 Ephemeral(expr) => {
2039 if let Some(e) = expr {
2040 write!(f, "EPHEMERAL {e}")
2041 } else {
2042 write!(f, "EPHEMERAL")
2043 }
2044 }
2045 Alias(expr) => write!(f, "ALIAS {expr}"),
2046 PrimaryKey(constraint) => {
2047 write!(f, "PRIMARY KEY")?;
2048 if let Some(characteristics) = &constraint.characteristics {
2049 write!(f, " {characteristics}")?;
2050 }
2051 Ok(())
2052 }
2053 Unique(constraint) => {
2054 write!(f, "UNIQUE{:>}", constraint.index_type_display)?;
2055 if let Some(characteristics) = &constraint.characteristics {
2056 write!(f, " {characteristics}")?;
2057 }
2058 Ok(())
2059 }
2060 ForeignKey(constraint) => {
2061 write!(f, "REFERENCES {}", constraint.foreign_table)?;
2062 if !constraint.referred_columns.is_empty() {
2063 write!(
2064 f,
2065 " ({})",
2066 display_comma_separated(&constraint.referred_columns)
2067 )?;
2068 }
2069 if let Some(match_kind) = &constraint.match_kind {
2070 write!(f, " {match_kind}")?;
2071 }
2072 if let Some(action) = &constraint.on_delete {
2073 write!(f, " ON DELETE {action}")?;
2074 }
2075 if let Some(action) = &constraint.on_update {
2076 write!(f, " ON UPDATE {action}")?;
2077 }
2078 if let Some(characteristics) = &constraint.characteristics {
2079 write!(f, " {characteristics}")?;
2080 }
2081 Ok(())
2082 }
2083 Check(constraint) => write!(f, "{constraint}"),
2084 DialectSpecific(val) => write!(f, "{}", display_separated(val, " ")),
2085 CharacterSet(n) => write!(f, "CHARACTER SET {n}"),
2086 Collation(n) => write!(f, "COLLATE {n}"),
2087 Comment(v) => write!(f, "COMMENT '{}'", escape_single_quote_string(v)),
2088 OnUpdate(expr) => write!(f, "ON UPDATE {expr}"),
2089 Generated {
2090 generated_as,
2091 sequence_options,
2092 generation_expr,
2093 generation_expr_mode,
2094 generated_keyword,
2095 } => {
2096 if let Some(expr) = generation_expr {
2097 let modifier = match generation_expr_mode {
2098 None => "",
2099 Some(GeneratedExpressionMode::Virtual) => " VIRTUAL",
2100 Some(GeneratedExpressionMode::Stored) => " STORED",
2101 };
2102 if *generated_keyword {
2103 write!(f, "GENERATED ALWAYS AS ({expr}){modifier}")?;
2104 } else {
2105 write!(f, "AS ({expr}){modifier}")?;
2106 }
2107 Ok(())
2108 } else {
2109 let when = match generated_as {
2111 GeneratedAs::Always => "ALWAYS",
2112 GeneratedAs::ByDefault => "BY DEFAULT",
2113 GeneratedAs::ExpStored => "",
2115 };
2116 write!(f, "GENERATED {when} AS IDENTITY")?;
2117 if sequence_options.is_some() {
2118 let so = sequence_options.as_ref().unwrap();
2119 if !so.is_empty() {
2120 write!(f, " (")?;
2121 }
2122 for sequence_option in so {
2123 write!(f, "{sequence_option}")?;
2124 }
2125 if !so.is_empty() {
2126 write!(f, " )")?;
2127 }
2128 }
2129 Ok(())
2130 }
2131 }
2132 Options(options) => {
2133 write!(f, "OPTIONS({})", display_comma_separated(options))
2134 }
2135 Identity(parameters) => {
2136 write!(f, "{parameters}")
2137 }
2138 OnConflict(keyword) => {
2139 write!(f, "ON CONFLICT {keyword:?}")?;
2140 Ok(())
2141 }
2142 Policy(parameters) => {
2143 write!(f, "{parameters}")
2144 }
2145 Tags(tags) => {
2146 write!(f, "{tags}")
2147 }
2148 Srid(srid) => {
2149 write!(f, "SRID {srid}")
2150 }
2151 Invisible => {
2152 write!(f, "INVISIBLE")
2153 }
2154 }
2155 }
2156}
2157
2158#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
2161#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2162#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2163pub enum GeneratedAs {
2164 Always,
2166 ByDefault,
2168 ExpStored,
2170}
2171
2172#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
2175#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2176#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2177pub enum GeneratedExpressionMode {
2178 Virtual,
2180 Stored,
2182}
2183
2184#[must_use]
2185pub(crate) fn display_constraint_name(name: &'_ Option<Ident>) -> impl fmt::Display + '_ {
2186 struct ConstraintName<'a>(&'a Option<Ident>);
2187 impl fmt::Display for ConstraintName<'_> {
2188 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2189 if let Some(name) = self.0 {
2190 write!(f, "CONSTRAINT {name} ")?;
2191 }
2192 Ok(())
2193 }
2194 }
2195 ConstraintName(name)
2196}
2197
2198#[must_use]
2202pub(crate) fn display_option<'a, T: fmt::Display>(
2203 prefix: &'a str,
2204 postfix: &'a str,
2205 option: &'a Option<T>,
2206) -> impl fmt::Display + 'a {
2207 struct OptionDisplay<'a, T>(&'a str, &'a str, &'a Option<T>);
2208 impl<T: fmt::Display> fmt::Display for OptionDisplay<'_, T> {
2209 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2210 if let Some(inner) = self.2 {
2211 let (prefix, postfix) = (self.0, self.1);
2212 write!(f, "{prefix}{inner}{postfix}")?;
2213 }
2214 Ok(())
2215 }
2216 }
2217 OptionDisplay(prefix, postfix, option)
2218}
2219
2220#[must_use]
2224pub(crate) fn display_option_spaced<T: fmt::Display>(option: &Option<T>) -> impl fmt::Display + '_ {
2225 display_option(" ", "", option)
2226}
2227
2228#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default, Eq, Ord, Hash)]
2232#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2233#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2234pub struct ConstraintCharacteristics {
2235 pub deferrable: Option<bool>,
2237 pub initially: Option<DeferrableInitial>,
2239 pub enforced: Option<bool>,
2241}
2242
2243#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2245#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2246#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2247pub enum DeferrableInitial {
2248 Immediate,
2250 Deferred,
2252}
2253
2254impl ConstraintCharacteristics {
2255 fn deferrable_text(&self) -> Option<&'static str> {
2256 self.deferrable.map(|deferrable| {
2257 if deferrable {
2258 "DEFERRABLE"
2259 } else {
2260 "NOT DEFERRABLE"
2261 }
2262 })
2263 }
2264
2265 fn initially_immediate_text(&self) -> Option<&'static str> {
2266 self.initially
2267 .map(|initially_immediate| match initially_immediate {
2268 DeferrableInitial::Immediate => "INITIALLY IMMEDIATE",
2269 DeferrableInitial::Deferred => "INITIALLY DEFERRED",
2270 })
2271 }
2272
2273 fn enforced_text(&self) -> Option<&'static str> {
2274 self.enforced.map(
2275 |enforced| {
2276 if enforced {
2277 "ENFORCED"
2278 } else {
2279 "NOT ENFORCED"
2280 }
2281 },
2282 )
2283 }
2284}
2285
2286impl fmt::Display for ConstraintCharacteristics {
2287 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2288 let deferrable = self.deferrable_text();
2289 let initially_immediate = self.initially_immediate_text();
2290 let enforced = self.enforced_text();
2291
2292 match (deferrable, initially_immediate, enforced) {
2293 (None, None, None) => Ok(()),
2294 (None, None, Some(enforced)) => write!(f, "{enforced}"),
2295 (None, Some(initial), None) => write!(f, "{initial}"),
2296 (None, Some(initial), Some(enforced)) => write!(f, "{initial} {enforced}"),
2297 (Some(deferrable), None, None) => write!(f, "{deferrable}"),
2298 (Some(deferrable), None, Some(enforced)) => write!(f, "{deferrable} {enforced}"),
2299 (Some(deferrable), Some(initial), None) => write!(f, "{deferrable} {initial}"),
2300 (Some(deferrable), Some(initial), Some(enforced)) => {
2301 write!(f, "{deferrable} {initial} {enforced}")
2302 }
2303 }
2304 }
2305}
2306
2307#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2312#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2313#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2314pub enum ReferentialAction {
2315 Restrict,
2317 Cascade,
2319 SetNull,
2321 NoAction,
2323 SetDefault,
2325}
2326
2327impl fmt::Display for ReferentialAction {
2328 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2329 f.write_str(match self {
2330 ReferentialAction::Restrict => "RESTRICT",
2331 ReferentialAction::Cascade => "CASCADE",
2332 ReferentialAction::SetNull => "SET NULL",
2333 ReferentialAction::NoAction => "NO ACTION",
2334 ReferentialAction::SetDefault => "SET DEFAULT",
2335 })
2336 }
2337}
2338
2339#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2343#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2344#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2345pub enum DropBehavior {
2346 Restrict,
2348 Cascade,
2350}
2351
2352impl fmt::Display for DropBehavior {
2353 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2354 f.write_str(match self {
2355 DropBehavior::Restrict => "RESTRICT",
2356 DropBehavior::Cascade => "CASCADE",
2357 })
2358 }
2359}
2360
2361#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2363#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2364#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2365pub enum UserDefinedTypeRepresentation {
2366 Composite {
2368 attributes: Vec<UserDefinedTypeCompositeAttributeDef>,
2370 },
2371 Enum {
2376 labels: Vec<Ident>,
2378 },
2379 Range {
2383 options: Vec<UserDefinedTypeRangeOption>,
2385 },
2386 SqlDefinition {
2392 options: Vec<UserDefinedTypeSqlDefinitionOption>,
2394 },
2395}
2396
2397impl fmt::Display for UserDefinedTypeRepresentation {
2398 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2399 match self {
2400 Self::Composite { attributes } => {
2401 write!(f, "AS ({})", display_comma_separated(attributes))
2402 }
2403 Self::Enum { labels } => {
2404 write!(f, "AS ENUM ({})", display_comma_separated(labels))
2405 }
2406 Self::Range { options } => {
2407 write!(f, "AS RANGE ({})", display_comma_separated(options))
2408 }
2409 Self::SqlDefinition { options } => {
2410 write!(f, "({})", display_comma_separated(options))
2411 }
2412 }
2413 }
2414}
2415
2416#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2418#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2419#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2420pub struct UserDefinedTypeCompositeAttributeDef {
2421 pub name: Ident,
2423 pub data_type: DataType,
2425 pub collation: Option<ObjectName>,
2427}
2428
2429impl fmt::Display for UserDefinedTypeCompositeAttributeDef {
2430 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2431 write!(f, "{} {}", self.name, self.data_type)?;
2432 if let Some(collation) = &self.collation {
2433 write!(f, " COLLATE {collation}")?;
2434 }
2435 Ok(())
2436 }
2437}
2438
2439#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2462#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2463#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2464pub enum UserDefinedTypeInternalLength {
2465 Fixed(u64),
2467 Variable,
2469}
2470
2471impl fmt::Display for UserDefinedTypeInternalLength {
2472 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2473 match self {
2474 UserDefinedTypeInternalLength::Fixed(n) => write!(f, "{}", n),
2475 UserDefinedTypeInternalLength::Variable => write!(f, "VARIABLE"),
2476 }
2477 }
2478}
2479
2480#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2499#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2500#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2501pub enum Alignment {
2502 Char,
2504 Int2,
2506 Int4,
2508 Double,
2510}
2511
2512impl fmt::Display for Alignment {
2513 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2514 match self {
2515 Alignment::Char => write!(f, "char"),
2516 Alignment::Int2 => write!(f, "int2"),
2517 Alignment::Int4 => write!(f, "int4"),
2518 Alignment::Double => write!(f, "double"),
2519 }
2520 }
2521}
2522
2523#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2543#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2544#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2545pub enum UserDefinedTypeStorage {
2546 Plain,
2548 External,
2550 Extended,
2552 Main,
2554}
2555
2556impl fmt::Display for UserDefinedTypeStorage {
2557 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2558 match self {
2559 UserDefinedTypeStorage::Plain => write!(f, "plain"),
2560 UserDefinedTypeStorage::External => write!(f, "external"),
2561 UserDefinedTypeStorage::Extended => write!(f, "extended"),
2562 UserDefinedTypeStorage::Main => write!(f, "main"),
2563 }
2564 }
2565}
2566
2567#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2585#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2586#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2587pub enum UserDefinedTypeRangeOption {
2588 Subtype(DataType),
2590 SubtypeOpClass(ObjectName),
2592 Collation(ObjectName),
2594 Canonical(ObjectName),
2596 SubtypeDiff(ObjectName),
2598 MultirangeTypeName(ObjectName),
2600}
2601
2602impl fmt::Display for UserDefinedTypeRangeOption {
2603 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2604 match self {
2605 UserDefinedTypeRangeOption::Subtype(dt) => write!(f, "SUBTYPE = {}", dt),
2606 UserDefinedTypeRangeOption::SubtypeOpClass(name) => {
2607 write!(f, "SUBTYPE_OPCLASS = {}", name)
2608 }
2609 UserDefinedTypeRangeOption::Collation(name) => write!(f, "COLLATION = {}", name),
2610 UserDefinedTypeRangeOption::Canonical(name) => write!(f, "CANONICAL = {}", name),
2611 UserDefinedTypeRangeOption::SubtypeDiff(name) => write!(f, "SUBTYPE_DIFF = {}", name),
2612 UserDefinedTypeRangeOption::MultirangeTypeName(name) => {
2613 write!(f, "MULTIRANGE_TYPE_NAME = {}", name)
2614 }
2615 }
2616 }
2617}
2618
2619#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2640#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2641#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2642pub enum UserDefinedTypeSqlDefinitionOption {
2643 Input(ObjectName),
2645 Output(ObjectName),
2647 Receive(ObjectName),
2649 Send(ObjectName),
2651 TypmodIn(ObjectName),
2653 TypmodOut(ObjectName),
2655 Analyze(ObjectName),
2657 Subscript(ObjectName),
2659 InternalLength(UserDefinedTypeInternalLength),
2661 PassedByValue,
2663 Alignment(Alignment),
2665 Storage(UserDefinedTypeStorage),
2667 Like(ObjectName),
2669 Category(char),
2671 Preferred(bool),
2673 Default(Expr),
2675 Element(DataType),
2677 Delimiter(String),
2679 Collatable(bool),
2681}
2682
2683impl fmt::Display for UserDefinedTypeSqlDefinitionOption {
2684 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2685 match self {
2686 UserDefinedTypeSqlDefinitionOption::Input(name) => write!(f, "INPUT = {}", name),
2687 UserDefinedTypeSqlDefinitionOption::Output(name) => write!(f, "OUTPUT = {}", name),
2688 UserDefinedTypeSqlDefinitionOption::Receive(name) => write!(f, "RECEIVE = {}", name),
2689 UserDefinedTypeSqlDefinitionOption::Send(name) => write!(f, "SEND = {}", name),
2690 UserDefinedTypeSqlDefinitionOption::TypmodIn(name) => write!(f, "TYPMOD_IN = {}", name),
2691 UserDefinedTypeSqlDefinitionOption::TypmodOut(name) => {
2692 write!(f, "TYPMOD_OUT = {}", name)
2693 }
2694 UserDefinedTypeSqlDefinitionOption::Analyze(name) => write!(f, "ANALYZE = {}", name),
2695 UserDefinedTypeSqlDefinitionOption::Subscript(name) => {
2696 write!(f, "SUBSCRIPT = {}", name)
2697 }
2698 UserDefinedTypeSqlDefinitionOption::InternalLength(len) => {
2699 write!(f, "INTERNALLENGTH = {}", len)
2700 }
2701 UserDefinedTypeSqlDefinitionOption::PassedByValue => write!(f, "PASSEDBYVALUE"),
2702 UserDefinedTypeSqlDefinitionOption::Alignment(align) => {
2703 write!(f, "ALIGNMENT = {}", align)
2704 }
2705 UserDefinedTypeSqlDefinitionOption::Storage(storage) => {
2706 write!(f, "STORAGE = {}", storage)
2707 }
2708 UserDefinedTypeSqlDefinitionOption::Like(name) => write!(f, "LIKE = {}", name),
2709 UserDefinedTypeSqlDefinitionOption::Category(c) => write!(f, "CATEGORY = '{}'", c),
2710 UserDefinedTypeSqlDefinitionOption::Preferred(b) => write!(f, "PREFERRED = {}", b),
2711 UserDefinedTypeSqlDefinitionOption::Default(expr) => write!(f, "DEFAULT = {}", expr),
2712 UserDefinedTypeSqlDefinitionOption::Element(dt) => write!(f, "ELEMENT = {}", dt),
2713 UserDefinedTypeSqlDefinitionOption::Delimiter(s) => {
2714 write!(f, "DELIMITER = '{}'", escape_single_quote_string(s))
2715 }
2716 UserDefinedTypeSqlDefinitionOption::Collatable(b) => write!(f, "COLLATABLE = {}", b),
2717 }
2718 }
2719}
2720
2721#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
2725#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2726#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2727pub enum Partition {
2728 Identifier(Ident),
2730 Expr(Expr),
2732 Part(Expr),
2735 Partitions(Vec<Expr>),
2737}
2738
2739impl fmt::Display for Partition {
2740 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2741 match self {
2742 Partition::Identifier(id) => write!(f, "PARTITION ID {id}"),
2743 Partition::Expr(expr) => write!(f, "PARTITION {expr}"),
2744 Partition::Part(expr) => write!(f, "PART {expr}"),
2745 Partition::Partitions(partitions) => {
2746 write!(f, "PARTITION ({})", display_comma_separated(partitions))
2747 }
2748 }
2749 }
2750}
2751
2752#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2755#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2756#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2757pub enum Deduplicate {
2758 All,
2760 ByExpression(Expr),
2762}
2763
2764impl fmt::Display for Deduplicate {
2765 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2766 match self {
2767 Deduplicate::All => write!(f, "DEDUPLICATE"),
2768 Deduplicate::ByExpression(expr) => write!(f, "DEDUPLICATE BY {expr}"),
2769 }
2770 }
2771}
2772
2773#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2778#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2779#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2780pub struct ClusteredBy {
2781 pub columns: Vec<Ident>,
2783 pub sorted_by: Option<Vec<OrderByExpr>>,
2785 pub num_buckets: Value,
2787}
2788
2789impl fmt::Display for ClusteredBy {
2790 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2791 write!(
2792 f,
2793 "CLUSTERED BY ({})",
2794 display_comma_separated(&self.columns)
2795 )?;
2796 if let Some(ref sorted_by) = self.sorted_by {
2797 write!(f, " SORTED BY ({})", display_comma_separated(sorted_by))?;
2798 }
2799 write!(f, " INTO {} BUCKETS", self.num_buckets)
2800 }
2801}
2802
2803#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2805#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2806#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2807pub struct CreateIndex {
2808 pub name: Option<ObjectName>,
2810 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
2811 pub table_name: ObjectName,
2813 pub using: Option<IndexType>,
2816 pub columns: Vec<IndexColumn>,
2818 pub unique: bool,
2820 pub concurrently: bool,
2822 pub if_not_exists: bool,
2824 pub include: Vec<Ident>,
2826 pub nulls_distinct: Option<bool>,
2828 pub with: Vec<Expr>,
2830 pub predicate: Option<Expr>,
2832 pub index_options: Vec<IndexOption>,
2834 pub alter_options: Vec<AlterTableOperation>,
2841}
2842
2843impl fmt::Display for CreateIndex {
2844 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2845 write!(
2846 f,
2847 "CREATE {unique}INDEX {concurrently}{if_not_exists}",
2848 unique = if self.unique { "UNIQUE " } else { "" },
2849 concurrently = if self.concurrently {
2850 "CONCURRENTLY "
2851 } else {
2852 ""
2853 },
2854 if_not_exists = if self.if_not_exists {
2855 "IF NOT EXISTS "
2856 } else {
2857 ""
2858 },
2859 )?;
2860 if let Some(value) = &self.name {
2861 write!(f, "{value} ")?;
2862 }
2863 write!(f, "ON {}", self.table_name)?;
2864 if let Some(value) = &self.using {
2865 write!(f, " USING {value} ")?;
2866 }
2867 write!(f, "({})", display_comma_separated(&self.columns))?;
2868 if !self.include.is_empty() {
2869 write!(f, " INCLUDE ({})", display_comma_separated(&self.include))?;
2870 }
2871 if let Some(value) = self.nulls_distinct {
2872 if value {
2873 write!(f, " NULLS DISTINCT")?;
2874 } else {
2875 write!(f, " NULLS NOT DISTINCT")?;
2876 }
2877 }
2878 if !self.with.is_empty() {
2879 write!(f, " WITH ({})", display_comma_separated(&self.with))?;
2880 }
2881 if let Some(predicate) = &self.predicate {
2882 write!(f, " WHERE {predicate}")?;
2883 }
2884 if !self.index_options.is_empty() {
2885 write!(f, " {}", display_separated(&self.index_options, " "))?;
2886 }
2887 if !self.alter_options.is_empty() {
2888 write!(f, " {}", display_separated(&self.alter_options, " "))?;
2889 }
2890 Ok(())
2891 }
2892}
2893
2894#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2896#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2897#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2898pub struct CreateTable {
2899 pub or_replace: bool,
2901 pub temporary: bool,
2903 pub external: bool,
2905 pub dynamic: bool,
2907 pub global: Option<bool>,
2909 pub if_not_exists: bool,
2911 pub transient: bool,
2913 pub volatile: bool,
2915 pub iceberg: bool,
2917 pub snapshot: bool,
2920 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
2922 pub name: ObjectName,
2923 pub columns: Vec<ColumnDef>,
2925 pub constraints: Vec<TableConstraint>,
2927 pub hive_distribution: HiveDistributionStyle,
2929 pub hive_formats: Option<HiveFormat>,
2931 pub table_options: CreateTableOptions,
2933 pub file_format: Option<FileFormat>,
2935 pub location: Option<String>,
2937 pub query: Option<Box<Query>>,
2939 pub without_rowid: bool,
2941 pub like: Option<CreateTableLikeKind>,
2943 pub clone: Option<ObjectName>,
2945 pub version: Option<TableVersion>,
2947 pub comment: Option<CommentDef>,
2951 pub on_commit: Option<OnCommit>,
2954 pub on_cluster: Option<Ident>,
2957 pub primary_key: Option<Box<Expr>>,
2960 pub order_by: Option<OneOrManyWithParens<Expr>>,
2964 pub partition_by: Option<Box<Expr>>,
2967 pub cluster_by: Option<WrappedCollection<Vec<Expr>>>,
2972 pub clustered_by: Option<ClusteredBy>,
2975 pub inherits: Option<Vec<ObjectName>>,
2980 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
2984 pub partition_of: Option<ObjectName>,
2985 pub for_values: Option<ForValues>,
2988 pub strict: bool,
2992 pub copy_grants: bool,
2995 pub enable_schema_evolution: Option<bool>,
2998 pub change_tracking: Option<bool>,
3001 pub data_retention_time_in_days: Option<u64>,
3004 pub max_data_extension_time_in_days: Option<u64>,
3007 pub default_ddl_collation: Option<String>,
3010 pub with_aggregation_policy: Option<ObjectName>,
3013 pub with_row_access_policy: Option<RowAccessPolicy>,
3016 pub with_storage_lifecycle_policy: Option<StorageLifecyclePolicy>,
3019 pub with_tags: Option<Vec<Tag>>,
3022 pub external_volume: Option<String>,
3025 pub base_location: Option<String>,
3028 pub catalog: Option<String>,
3031 pub catalog_sync: Option<String>,
3034 pub storage_serialization_policy: Option<StorageSerializationPolicy>,
3037 pub target_lag: Option<String>,
3040 pub warehouse: Option<Ident>,
3043 pub refresh_mode: Option<RefreshModeKind>,
3046 pub initialize: Option<InitializeKind>,
3049 pub require_user: bool,
3052 pub diststyle: Option<DistStyle>,
3055 pub distkey: Option<Expr>,
3058 pub sortkey: Option<Vec<Expr>>,
3061 pub backup: Option<bool>,
3064}
3065
3066impl fmt::Display for CreateTable {
3067 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3068 write!(
3076 f,
3077 "CREATE {or_replace}{external}{global}{temporary}{transient}{volatile}{dynamic}{iceberg}{snapshot}TABLE {if_not_exists}{name}",
3078 or_replace = if self.or_replace { "OR REPLACE " } else { "" },
3079 external = if self.external { "EXTERNAL " } else { "" },
3080 snapshot = if self.snapshot { "SNAPSHOT " } else { "" },
3081 global = self.global
3082 .map(|global| {
3083 if global {
3084 "GLOBAL "
3085 } else {
3086 "LOCAL "
3087 }
3088 })
3089 .unwrap_or(""),
3090 if_not_exists = if self.if_not_exists { "IF NOT EXISTS " } else { "" },
3091 temporary = if self.temporary { "TEMPORARY " } else { "" },
3092 transient = if self.transient { "TRANSIENT " } else { "" },
3093 volatile = if self.volatile { "VOLATILE " } else { "" },
3094 iceberg = if self.iceberg { "ICEBERG " } else { "" },
3096 dynamic = if self.dynamic { "DYNAMIC " } else { "" },
3097 name = self.name,
3098 )?;
3099 if let Some(partition_of) = &self.partition_of {
3100 write!(f, " PARTITION OF {partition_of}")?;
3101 }
3102 if let Some(on_cluster) = &self.on_cluster {
3103 write!(f, " ON CLUSTER {on_cluster}")?;
3104 }
3105 if !self.columns.is_empty() || !self.constraints.is_empty() {
3106 f.write_str(" (")?;
3107 NewLine.fmt(f)?;
3108 Indent(DisplayCommaSeparated(&self.columns)).fmt(f)?;
3109 if !self.columns.is_empty() && !self.constraints.is_empty() {
3110 f.write_str(",")?;
3111 SpaceOrNewline.fmt(f)?;
3112 }
3113 Indent(DisplayCommaSeparated(&self.constraints)).fmt(f)?;
3114 NewLine.fmt(f)?;
3115 f.write_str(")")?;
3116 } else if self.query.is_none()
3117 && self.like.is_none()
3118 && self.clone.is_none()
3119 && self.partition_of.is_none()
3120 {
3121 f.write_str(" ()")?;
3123 } else if let Some(CreateTableLikeKind::Parenthesized(like_in_columns_list)) = &self.like {
3124 write!(f, " ({like_in_columns_list})")?;
3125 }
3126 if let Some(for_values) = &self.for_values {
3127 write!(f, " {for_values}")?;
3128 }
3129
3130 if let Some(comment) = &self.comment {
3133 write!(f, " COMMENT '{comment}'")?;
3134 }
3135
3136 if self.without_rowid {
3138 write!(f, " WITHOUT ROWID")?;
3139 }
3140
3141 if let Some(CreateTableLikeKind::Plain(like)) = &self.like {
3142 write!(f, " {like}")?;
3143 }
3144
3145 if let Some(c) = &self.clone {
3146 write!(f, " CLONE {c}")?;
3147 }
3148
3149 if let Some(version) = &self.version {
3150 write!(f, " {version}")?;
3151 }
3152
3153 match &self.hive_distribution {
3154 HiveDistributionStyle::PARTITIONED { columns } => {
3155 write!(f, " PARTITIONED BY ({})", display_comma_separated(columns))?;
3156 }
3157 HiveDistributionStyle::SKEWED {
3158 columns,
3159 on,
3160 stored_as_directories,
3161 } => {
3162 write!(
3163 f,
3164 " SKEWED BY ({})) ON ({})",
3165 display_comma_separated(columns),
3166 display_comma_separated(on)
3167 )?;
3168 if *stored_as_directories {
3169 write!(f, " STORED AS DIRECTORIES")?;
3170 }
3171 }
3172 _ => (),
3173 }
3174
3175 if let Some(clustered_by) = &self.clustered_by {
3176 write!(f, " {clustered_by}")?;
3177 }
3178
3179 if let Some(HiveFormat {
3180 row_format,
3181 serde_properties,
3182 storage,
3183 location,
3184 }) = &self.hive_formats
3185 {
3186 match row_format {
3187 Some(HiveRowFormat::SERDE { class }) => write!(f, " ROW FORMAT SERDE '{class}'")?,
3188 Some(HiveRowFormat::DELIMITED { delimiters }) => {
3189 write!(f, " ROW FORMAT DELIMITED")?;
3190 if !delimiters.is_empty() {
3191 write!(f, " {}", display_separated(delimiters, " "))?;
3192 }
3193 }
3194 None => (),
3195 }
3196 match storage {
3197 Some(HiveIOFormat::IOF {
3198 input_format,
3199 output_format,
3200 }) => write!(
3201 f,
3202 " STORED AS INPUTFORMAT {input_format} OUTPUTFORMAT {output_format}"
3203 )?,
3204 Some(HiveIOFormat::FileFormat { format }) if !self.external => {
3205 write!(f, " STORED AS {format}")?
3206 }
3207 _ => (),
3208 }
3209 if let Some(serde_properties) = serde_properties.as_ref() {
3210 write!(
3211 f,
3212 " WITH SERDEPROPERTIES ({})",
3213 display_comma_separated(serde_properties)
3214 )?;
3215 }
3216 if !self.external {
3217 if let Some(loc) = location {
3218 write!(f, " LOCATION '{loc}'")?;
3219 }
3220 }
3221 }
3222 if self.external {
3223 if let Some(file_format) = self.file_format {
3224 write!(f, " STORED AS {file_format}")?;
3225 }
3226 if let Some(location) = &self.location {
3227 write!(f, " LOCATION '{location}'")?;
3228 }
3229 }
3230
3231 match &self.table_options {
3232 options @ CreateTableOptions::With(_)
3233 | options @ CreateTableOptions::Plain(_)
3234 | options @ CreateTableOptions::TableProperties(_) => write!(f, " {options}")?,
3235 _ => (),
3236 }
3237
3238 if let Some(primary_key) = &self.primary_key {
3239 write!(f, " PRIMARY KEY {primary_key}")?;
3240 }
3241 if let Some(order_by) = &self.order_by {
3242 write!(f, " ORDER BY {order_by}")?;
3243 }
3244 if let Some(inherits) = &self.inherits {
3245 write!(f, " INHERITS ({})", display_comma_separated(inherits))?;
3246 }
3247 if let Some(partition_by) = self.partition_by.as_ref() {
3248 write!(f, " PARTITION BY {partition_by}")?;
3249 }
3250 if let Some(cluster_by) = self.cluster_by.as_ref() {
3251 write!(f, " CLUSTER BY {cluster_by}")?;
3252 }
3253 if let options @ CreateTableOptions::Options(_) = &self.table_options {
3254 write!(f, " {options}")?;
3255 }
3256 if let Some(external_volume) = self.external_volume.as_ref() {
3257 write!(f, " EXTERNAL_VOLUME='{external_volume}'")?;
3258 }
3259
3260 if let Some(catalog) = self.catalog.as_ref() {
3261 write!(f, " CATALOG='{catalog}'")?;
3262 }
3263
3264 if self.iceberg {
3265 if let Some(base_location) = self.base_location.as_ref() {
3266 write!(f, " BASE_LOCATION='{base_location}'")?;
3267 }
3268 }
3269
3270 if let Some(catalog_sync) = self.catalog_sync.as_ref() {
3271 write!(f, " CATALOG_SYNC='{catalog_sync}'")?;
3272 }
3273
3274 if let Some(storage_serialization_policy) = self.storage_serialization_policy.as_ref() {
3275 write!(
3276 f,
3277 " STORAGE_SERIALIZATION_POLICY={storage_serialization_policy}"
3278 )?;
3279 }
3280
3281 if self.copy_grants {
3282 write!(f, " COPY GRANTS")?;
3283 }
3284
3285 if let Some(is_enabled) = self.enable_schema_evolution {
3286 write!(
3287 f,
3288 " ENABLE_SCHEMA_EVOLUTION={}",
3289 if is_enabled { "TRUE" } else { "FALSE" }
3290 )?;
3291 }
3292
3293 if let Some(is_enabled) = self.change_tracking {
3294 write!(
3295 f,
3296 " CHANGE_TRACKING={}",
3297 if is_enabled { "TRUE" } else { "FALSE" }
3298 )?;
3299 }
3300
3301 if let Some(data_retention_time_in_days) = self.data_retention_time_in_days {
3302 write!(
3303 f,
3304 " DATA_RETENTION_TIME_IN_DAYS={data_retention_time_in_days}",
3305 )?;
3306 }
3307
3308 if let Some(max_data_extension_time_in_days) = self.max_data_extension_time_in_days {
3309 write!(
3310 f,
3311 " MAX_DATA_EXTENSION_TIME_IN_DAYS={max_data_extension_time_in_days}",
3312 )?;
3313 }
3314
3315 if let Some(default_ddl_collation) = &self.default_ddl_collation {
3316 write!(f, " DEFAULT_DDL_COLLATION='{default_ddl_collation}'",)?;
3317 }
3318
3319 if let Some(with_aggregation_policy) = &self.with_aggregation_policy {
3320 write!(f, " WITH AGGREGATION POLICY {with_aggregation_policy}",)?;
3321 }
3322
3323 if let Some(row_access_policy) = &self.with_row_access_policy {
3324 write!(f, " {row_access_policy}",)?;
3325 }
3326
3327 if let Some(storage_lifecycle_policy) = &self.with_storage_lifecycle_policy {
3328 write!(f, " {storage_lifecycle_policy}",)?;
3329 }
3330
3331 if let Some(tag) = &self.with_tags {
3332 write!(f, " WITH TAG ({})", display_comma_separated(tag.as_slice()))?;
3333 }
3334
3335 if let Some(target_lag) = &self.target_lag {
3336 write!(f, " TARGET_LAG='{target_lag}'")?;
3337 }
3338
3339 if let Some(warehouse) = &self.warehouse {
3340 write!(f, " WAREHOUSE={warehouse}")?;
3341 }
3342
3343 if let Some(refresh_mode) = &self.refresh_mode {
3344 write!(f, " REFRESH_MODE={refresh_mode}")?;
3345 }
3346
3347 if let Some(initialize) = &self.initialize {
3348 write!(f, " INITIALIZE={initialize}")?;
3349 }
3350
3351 if self.require_user {
3352 write!(f, " REQUIRE USER")?;
3353 }
3354
3355 if self.on_commit.is_some() {
3356 let on_commit = match self.on_commit {
3357 Some(OnCommit::DeleteRows) => "ON COMMIT DELETE ROWS",
3358 Some(OnCommit::PreserveRows) => "ON COMMIT PRESERVE ROWS",
3359 Some(OnCommit::Drop) => "ON COMMIT DROP",
3360 None => "",
3361 };
3362 write!(f, " {on_commit}")?;
3363 }
3364 if self.strict {
3365 write!(f, " STRICT")?;
3366 }
3367 if let Some(backup) = self.backup {
3368 write!(f, " BACKUP {}", if backup { "YES" } else { "NO" })?;
3369 }
3370 if let Some(diststyle) = &self.diststyle {
3371 write!(f, " DISTSTYLE {diststyle}")?;
3372 }
3373 if let Some(distkey) = &self.distkey {
3374 write!(f, " DISTKEY({distkey})")?;
3375 }
3376 if let Some(sortkey) = &self.sortkey {
3377 write!(f, " SORTKEY({})", display_comma_separated(sortkey))?;
3378 }
3379 if let Some(query) = &self.query {
3380 write!(f, " AS {query}")?;
3381 }
3382 Ok(())
3383 }
3384}
3385
3386#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3392#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3393#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3394pub enum ForValues {
3395 In(Vec<Expr>),
3397 From {
3399 from: Vec<PartitionBoundValue>,
3401 to: Vec<PartitionBoundValue>,
3403 },
3404 With {
3406 modulus: u64,
3408 remainder: u64,
3410 },
3411 Default,
3413}
3414
3415impl fmt::Display for ForValues {
3416 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3417 match self {
3418 ForValues::In(values) => {
3419 write!(f, "FOR VALUES IN ({})", display_comma_separated(values))
3420 }
3421 ForValues::From { from, to } => {
3422 write!(
3423 f,
3424 "FOR VALUES FROM ({}) TO ({})",
3425 display_comma_separated(from),
3426 display_comma_separated(to)
3427 )
3428 }
3429 ForValues::With { modulus, remainder } => {
3430 write!(
3431 f,
3432 "FOR VALUES WITH (MODULUS {modulus}, REMAINDER {remainder})"
3433 )
3434 }
3435 ForValues::Default => write!(f, "DEFAULT"),
3436 }
3437 }
3438}
3439
3440#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3445#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3446#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3447pub enum PartitionBoundValue {
3448 Expr(Expr),
3450 MinValue,
3452 MaxValue,
3454}
3455
3456impl fmt::Display for PartitionBoundValue {
3457 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3458 match self {
3459 PartitionBoundValue::Expr(expr) => write!(f, "{expr}"),
3460 PartitionBoundValue::MinValue => write!(f, "MINVALUE"),
3461 PartitionBoundValue::MaxValue => write!(f, "MAXVALUE"),
3462 }
3463 }
3464}
3465
3466#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3470#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3471#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3472pub enum DistStyle {
3473 Auto,
3475 Even,
3477 Key,
3479 All,
3481}
3482
3483impl fmt::Display for DistStyle {
3484 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3485 match self {
3486 DistStyle::Auto => write!(f, "AUTO"),
3487 DistStyle::Even => write!(f, "EVEN"),
3488 DistStyle::Key => write!(f, "KEY"),
3489 DistStyle::All => write!(f, "ALL"),
3490 }
3491 }
3492}
3493
3494
3495#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3496#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3497#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3498pub struct CreateDomain {
3511 pub name: ObjectName,
3513 pub data_type: DataType,
3515 pub collation: Option<Ident>,
3517 pub default: Option<Expr>,
3519 pub constraints: Vec<TableConstraint>,
3521}
3522
3523impl fmt::Display for CreateDomain {
3524 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3525 write!(
3526 f,
3527 "CREATE DOMAIN {name} AS {data_type}",
3528 name = self.name,
3529 data_type = self.data_type
3530 )?;
3531 if let Some(collation) = &self.collation {
3532 write!(f, " COLLATE {collation}")?;
3533 }
3534 if let Some(default) = &self.default {
3535 write!(f, " DEFAULT {default}")?;
3536 }
3537 if !self.constraints.is_empty() {
3538 write!(f, " {}", display_separated(&self.constraints, " "))?;
3539 }
3540 Ok(())
3541 }
3542}
3543
3544#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3546#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3547#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3548pub enum FunctionReturnType {
3549 DataType(DataType),
3551 SetOf(DataType),
3555}
3556
3557impl fmt::Display for FunctionReturnType {
3558 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3559 match self {
3560 FunctionReturnType::DataType(data_type) => write!(f, "{data_type}"),
3561 FunctionReturnType::SetOf(data_type) => write!(f, "SETOF {data_type}"),
3562 }
3563 }
3564}
3565
3566#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3567#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3568#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3569pub struct CreateFunction {
3571 pub or_alter: bool,
3575 pub or_replace: bool,
3577 pub temporary: bool,
3579 pub if_not_exists: bool,
3581 pub name: ObjectName,
3583 pub args: Option<Vec<OperateFunctionArg>>,
3585 pub return_type: Option<FunctionReturnType>,
3587 pub function_body: Option<CreateFunctionBody>,
3595 pub behavior: Option<FunctionBehavior>,
3601 pub called_on_null: Option<FunctionCalledOnNull>,
3605 pub parallel: Option<FunctionParallel>,
3609 pub security: Option<FunctionSecurity>,
3613 pub set_params: Vec<FunctionDefinitionSetParam>,
3617 pub using: Option<CreateFunctionUsing>,
3619 pub language: Option<Ident>,
3627 pub determinism_specifier: Option<FunctionDeterminismSpecifier>,
3631 pub options: Option<Vec<SqlOption>>,
3635 pub remote_connection: Option<ObjectName>,
3645}
3646
3647impl fmt::Display for CreateFunction {
3648 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3649 write!(
3650 f,
3651 "CREATE {or_alter}{or_replace}{temp}FUNCTION {if_not_exists}{name}",
3652 name = self.name,
3653 temp = if self.temporary { "TEMPORARY " } else { "" },
3654 or_alter = if self.or_alter { "OR ALTER " } else { "" },
3655 or_replace = if self.or_replace { "OR REPLACE " } else { "" },
3656 if_not_exists = if self.if_not_exists {
3657 "IF NOT EXISTS "
3658 } else {
3659 ""
3660 },
3661 )?;
3662 if let Some(args) = &self.args {
3663 write!(f, "({})", display_comma_separated(args))?;
3664 }
3665 if let Some(return_type) = &self.return_type {
3666 write!(f, " RETURNS {return_type}")?;
3667 }
3668 if let Some(determinism_specifier) = &self.determinism_specifier {
3669 write!(f, " {determinism_specifier}")?;
3670 }
3671 if let Some(language) = &self.language {
3672 write!(f, " LANGUAGE {language}")?;
3673 }
3674 if let Some(behavior) = &self.behavior {
3675 write!(f, " {behavior}")?;
3676 }
3677 if let Some(called_on_null) = &self.called_on_null {
3678 write!(f, " {called_on_null}")?;
3679 }
3680 if let Some(parallel) = &self.parallel {
3681 write!(f, " {parallel}")?;
3682 }
3683 if let Some(security) = &self.security {
3684 write!(f, " {security}")?;
3685 }
3686 for set_param in &self.set_params {
3687 write!(f, " {set_param}")?;
3688 }
3689 if let Some(remote_connection) = &self.remote_connection {
3690 write!(f, " REMOTE WITH CONNECTION {remote_connection}")?;
3691 }
3692 if let Some(CreateFunctionBody::AsBeforeOptions { body, link_symbol }) = &self.function_body
3693 {
3694 write!(f, " AS {body}")?;
3695 if let Some(link_symbol) = link_symbol {
3696 write!(f, ", {link_symbol}")?;
3697 }
3698 }
3699 if let Some(CreateFunctionBody::Return(function_body)) = &self.function_body {
3700 write!(f, " RETURN {function_body}")?;
3701 }
3702 if let Some(CreateFunctionBody::AsReturnExpr(function_body)) = &self.function_body {
3703 write!(f, " AS RETURN {function_body}")?;
3704 }
3705 if let Some(CreateFunctionBody::AsReturnSelect(function_body)) = &self.function_body {
3706 write!(f, " AS RETURN {function_body}")?;
3707 }
3708 if let Some(using) = &self.using {
3709 write!(f, " {using}")?;
3710 }
3711 if let Some(options) = &self.options {
3712 write!(
3713 f,
3714 " OPTIONS({})",
3715 display_comma_separated(options.as_slice())
3716 )?;
3717 }
3718 if let Some(CreateFunctionBody::AsAfterOptions(function_body)) = &self.function_body {
3719 write!(f, " AS {function_body}")?;
3720 }
3721 if let Some(CreateFunctionBody::AsBeginEnd(bes)) = &self.function_body {
3722 write!(f, " AS {bes}")?;
3723 }
3724 Ok(())
3725 }
3726}
3727
3728#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3738#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3739#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3740pub struct CreateConnector {
3741 pub name: Ident,
3743 pub if_not_exists: bool,
3745 pub connector_type: Option<String>,
3747 pub url: Option<String>,
3749 pub comment: Option<CommentDef>,
3751 pub with_dcproperties: Option<Vec<SqlOption>>,
3753}
3754
3755impl fmt::Display for CreateConnector {
3756 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3757 write!(
3758 f,
3759 "CREATE CONNECTOR {if_not_exists}{name}",
3760 if_not_exists = if self.if_not_exists {
3761 "IF NOT EXISTS "
3762 } else {
3763 ""
3764 },
3765 name = self.name,
3766 )?;
3767
3768 if let Some(connector_type) = &self.connector_type {
3769 write!(f, " TYPE '{connector_type}'")?;
3770 }
3771
3772 if let Some(url) = &self.url {
3773 write!(f, " URL '{url}'")?;
3774 }
3775
3776 if let Some(comment) = &self.comment {
3777 write!(f, " COMMENT = '{comment}'")?;
3778 }
3779
3780 if let Some(with_dcproperties) = &self.with_dcproperties {
3781 write!(
3782 f,
3783 " WITH DCPROPERTIES({})",
3784 display_comma_separated(with_dcproperties)
3785 )?;
3786 }
3787
3788 Ok(())
3789 }
3790}
3791
3792#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3797#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3798#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3799pub enum AlterSchemaOperation {
3800 SetDefaultCollate {
3802 collate: Expr,
3804 },
3805 AddReplica {
3807 replica: Ident,
3809 options: Option<Vec<SqlOption>>,
3811 },
3812 DropReplica {
3814 replica: Ident,
3816 },
3817 SetOptionsParens {
3819 options: Vec<SqlOption>,
3821 },
3822 Rename {
3824 name: ObjectName,
3826 },
3827 OwnerTo {
3829 owner: Owner,
3831 },
3832}
3833
3834impl fmt::Display for AlterSchemaOperation {
3835 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3836 match self {
3837 AlterSchemaOperation::SetDefaultCollate { collate } => {
3838 write!(f, "SET DEFAULT COLLATE {collate}")
3839 }
3840 AlterSchemaOperation::AddReplica { replica, options } => {
3841 write!(f, "ADD REPLICA {replica}")?;
3842 if let Some(options) = options {
3843 write!(f, " OPTIONS ({})", display_comma_separated(options))?;
3844 }
3845 Ok(())
3846 }
3847 AlterSchemaOperation::DropReplica { replica } => write!(f, "DROP REPLICA {replica}"),
3848 AlterSchemaOperation::SetOptionsParens { options } => {
3849 write!(f, "SET OPTIONS ({})", display_comma_separated(options))
3850 }
3851 AlterSchemaOperation::Rename { name } => write!(f, "RENAME TO {name}"),
3852 AlterSchemaOperation::OwnerTo { owner } => write!(f, "OWNER TO {owner}"),
3853 }
3854 }
3855}
3856#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3862#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3863#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3864pub enum RenameTableNameKind {
3865 As(ObjectName),
3867 To(ObjectName),
3869}
3870
3871impl fmt::Display for RenameTableNameKind {
3872 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3873 match self {
3874 RenameTableNameKind::As(name) => write!(f, "AS {name}"),
3875 RenameTableNameKind::To(name) => write!(f, "TO {name}"),
3876 }
3877 }
3878}
3879
3880#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3881#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3882#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3883pub struct AlterSchema {
3885 pub name: ObjectName,
3887 pub if_exists: bool,
3889 pub operations: Vec<AlterSchemaOperation>,
3891}
3892
3893impl fmt::Display for AlterSchema {
3894 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3895 write!(f, "ALTER SCHEMA ")?;
3896 if self.if_exists {
3897 write!(f, "IF EXISTS ")?;
3898 }
3899 write!(f, "{}", self.name)?;
3900 for operation in &self.operations {
3901 write!(f, " {operation}")?;
3902 }
3903
3904 Ok(())
3905 }
3906}
3907
3908impl Spanned for RenameTableNameKind {
3909 fn span(&self) -> Span {
3910 match self {
3911 RenameTableNameKind::As(name) => name.span(),
3912 RenameTableNameKind::To(name) => name.span(),
3913 }
3914 }
3915}
3916
3917#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
3918#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3919#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3920pub enum TriggerObjectKind {
3922 For(TriggerObject),
3924 ForEach(TriggerObject),
3926}
3927
3928impl Display for TriggerObjectKind {
3929 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3930 match self {
3931 TriggerObjectKind::For(obj) => write!(f, "FOR {obj}"),
3932 TriggerObjectKind::ForEach(obj) => write!(f, "FOR EACH {obj}"),
3933 }
3934 }
3935}
3936
3937#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3938#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3939#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3940pub struct CreateTrigger {
3954 pub or_alter: bool,
3958 pub temporary: bool,
3975 pub or_replace: bool,
3985 pub is_constraint: bool,
3987 pub name: ObjectName,
3989 pub period: Option<TriggerPeriod>,
4018 pub period_before_table: bool,
4029 pub events: Vec<TriggerEvent>,
4031 pub table_name: ObjectName,
4033 pub referenced_table_name: Option<ObjectName>,
4036 pub referencing: Vec<TriggerReferencing>,
4038 pub trigger_object: Option<TriggerObjectKind>,
4043 pub condition: Option<Expr>,
4045 pub exec_body: Option<TriggerExecBody>,
4047 pub statements_as: bool,
4049 pub statements: Option<ConditionalStatements>,
4051 pub characteristics: Option<ConstraintCharacteristics>,
4053}
4054
4055impl Display for CreateTrigger {
4056 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4057 let CreateTrigger {
4058 or_alter,
4059 temporary,
4060 or_replace,
4061 is_constraint,
4062 name,
4063 period_before_table,
4064 period,
4065 events,
4066 table_name,
4067 referenced_table_name,
4068 referencing,
4069 trigger_object,
4070 condition,
4071 exec_body,
4072 statements_as,
4073 statements,
4074 characteristics,
4075 } = self;
4076 write!(
4077 f,
4078 "CREATE {temporary}{or_alter}{or_replace}{is_constraint}TRIGGER {name} ",
4079 temporary = if *temporary { "TEMPORARY " } else { "" },
4080 or_alter = if *or_alter { "OR ALTER " } else { "" },
4081 or_replace = if *or_replace { "OR REPLACE " } else { "" },
4082 is_constraint = if *is_constraint { "CONSTRAINT " } else { "" },
4083 )?;
4084
4085 if *period_before_table {
4086 if let Some(p) = period {
4087 write!(f, "{p} ")?;
4088 }
4089 if !events.is_empty() {
4090 write!(f, "{} ", display_separated(events, " OR "))?;
4091 }
4092 write!(f, "ON {table_name}")?;
4093 } else {
4094 write!(f, "ON {table_name} ")?;
4095 if let Some(p) = period {
4096 write!(f, "{p}")?;
4097 }
4098 if !events.is_empty() {
4099 write!(f, " {}", display_separated(events, ", "))?;
4100 }
4101 }
4102
4103 if let Some(referenced_table_name) = referenced_table_name {
4104 write!(f, " FROM {referenced_table_name}")?;
4105 }
4106
4107 if let Some(characteristics) = characteristics {
4108 write!(f, " {characteristics}")?;
4109 }
4110
4111 if !referencing.is_empty() {
4112 write!(f, " REFERENCING {}", display_separated(referencing, " "))?;
4113 }
4114
4115 if let Some(trigger_object) = trigger_object {
4116 write!(f, " {trigger_object}")?;
4117 }
4118 if let Some(condition) = condition {
4119 write!(f, " WHEN {condition}")?;
4120 }
4121 if let Some(exec_body) = exec_body {
4122 write!(f, " EXECUTE {exec_body}")?;
4123 }
4124 if let Some(statements) = statements {
4125 if *statements_as {
4126 write!(f, " AS")?;
4127 }
4128 write!(f, " {statements}")?;
4129 }
4130 Ok(())
4131 }
4132}
4133
4134#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4135#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4136#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4137pub struct DropTrigger {
4144 pub if_exists: bool,
4146 pub trigger_name: ObjectName,
4148 pub table_name: Option<ObjectName>,
4150 pub option: Option<ReferentialAction>,
4152}
4153
4154impl fmt::Display for DropTrigger {
4155 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4156 let DropTrigger {
4157 if_exists,
4158 trigger_name,
4159 table_name,
4160 option,
4161 } = self;
4162 write!(f, "DROP TRIGGER")?;
4163 if *if_exists {
4164 write!(f, " IF EXISTS")?;
4165 }
4166 match &table_name {
4167 Some(table_name) => write!(f, " {trigger_name} ON {table_name}")?,
4168 None => write!(f, " {trigger_name}")?,
4169 };
4170 if let Some(option) = option {
4171 write!(f, " {option}")?;
4172 }
4173 Ok(())
4174 }
4175}
4176
4177#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4183#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4184#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4185pub struct Truncate {
4186 pub table_names: Vec<super::TruncateTableTarget>,
4188 pub partitions: Option<Vec<Expr>>,
4190 pub table: bool,
4192 pub if_exists: bool,
4194 pub identity: Option<super::TruncateIdentityOption>,
4196 pub cascade: Option<super::CascadeOption>,
4198 pub on_cluster: Option<Ident>,
4201}
4202
4203impl fmt::Display for Truncate {
4204 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4205 let table = if self.table { "TABLE " } else { "" };
4206 let if_exists = if self.if_exists { "IF EXISTS " } else { "" };
4207
4208 write!(
4209 f,
4210 "TRUNCATE {table}{if_exists}{table_names}",
4211 table_names = display_comma_separated(&self.table_names)
4212 )?;
4213
4214 if let Some(identity) = &self.identity {
4215 match identity {
4216 super::TruncateIdentityOption::Restart => write!(f, " RESTART IDENTITY")?,
4217 super::TruncateIdentityOption::Continue => write!(f, " CONTINUE IDENTITY")?,
4218 }
4219 }
4220 if let Some(cascade) = &self.cascade {
4221 match cascade {
4222 super::CascadeOption::Cascade => write!(f, " CASCADE")?,
4223 super::CascadeOption::Restrict => write!(f, " RESTRICT")?,
4224 }
4225 }
4226
4227 if let Some(ref parts) = &self.partitions {
4228 if !parts.is_empty() {
4229 write!(f, " PARTITION ({})", display_comma_separated(parts))?;
4230 }
4231 }
4232 if let Some(on_cluster) = &self.on_cluster {
4233 write!(f, " ON CLUSTER {on_cluster}")?;
4234 }
4235 Ok(())
4236 }
4237}
4238
4239impl Spanned for Truncate {
4240 fn span(&self) -> Span {
4241 Span::union_iter(
4242 self.table_names.iter().map(|i| i.name.span()).chain(
4243 self.partitions
4244 .iter()
4245 .flat_map(|i| i.iter().map(|k| k.span())),
4246 ),
4247 )
4248 }
4249}
4250
4251#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4258#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4259#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4260pub struct Msck {
4261 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4263 pub table_name: ObjectName,
4264 pub repair: bool,
4266 pub partition_action: Option<super::AddDropSync>,
4268}
4269
4270impl fmt::Display for Msck {
4271 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4272 write!(
4273 f,
4274 "MSCK {repair}TABLE {table}",
4275 repair = if self.repair { "REPAIR " } else { "" },
4276 table = self.table_name
4277 )?;
4278 if let Some(pa) = &self.partition_action {
4279 write!(f, " {pa}")?;
4280 }
4281 Ok(())
4282 }
4283}
4284
4285impl Spanned for Msck {
4286 fn span(&self) -> Span {
4287 self.table_name.span()
4288 }
4289}
4290
4291#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4293#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4294#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4295pub struct CreateView {
4296 pub or_alter: bool,
4300 pub or_replace: bool,
4302 pub materialized: bool,
4304 pub secure: bool,
4307 pub name: ObjectName,
4309 pub name_before_not_exists: bool,
4320 pub columns: Vec<ViewColumnDef>,
4322 pub query: Box<Query>,
4324 pub options: CreateTableOptions,
4326 pub cluster_by: Vec<Ident>,
4328 pub comment: Option<String>,
4331 pub with_no_schema_binding: bool,
4333 pub if_not_exists: bool,
4335 pub temporary: bool,
4337 pub copy_grants: bool,
4340 pub to: Option<ObjectName>,
4343 pub params: Option<CreateViewParams>,
4345}
4346
4347impl fmt::Display for CreateView {
4348 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4349 write!(
4350 f,
4351 "CREATE {or_alter}{or_replace}",
4352 or_alter = if self.or_alter { "OR ALTER " } else { "" },
4353 or_replace = if self.or_replace { "OR REPLACE " } else { "" },
4354 )?;
4355 if let Some(ref params) = self.params {
4356 params.fmt(f)?;
4357 }
4358 write!(
4359 f,
4360 "{secure}{materialized}{temporary}VIEW {if_not_and_name}{to}",
4361 if_not_and_name = if self.if_not_exists {
4362 if self.name_before_not_exists {
4363 format!("{} IF NOT EXISTS", self.name)
4364 } else {
4365 format!("IF NOT EXISTS {}", self.name)
4366 }
4367 } else {
4368 format!("{}", self.name)
4369 },
4370 secure = if self.secure { "SECURE " } else { "" },
4371 materialized = if self.materialized {
4372 "MATERIALIZED "
4373 } else {
4374 ""
4375 },
4376 temporary = if self.temporary { "TEMPORARY " } else { "" },
4377 to = self
4378 .to
4379 .as_ref()
4380 .map(|to| format!(" TO {to}"))
4381 .unwrap_or_default()
4382 )?;
4383 if self.copy_grants {
4384 write!(f, " COPY GRANTS")?;
4385 }
4386 if !self.columns.is_empty() {
4387 write!(f, " ({})", display_comma_separated(&self.columns))?;
4388 }
4389 if matches!(self.options, CreateTableOptions::With(_)) {
4390 write!(f, " {}", self.options)?;
4391 }
4392 if let Some(ref comment) = self.comment {
4393 write!(f, " COMMENT = '{}'", escape_single_quote_string(comment))?;
4394 }
4395 if !self.cluster_by.is_empty() {
4396 write!(
4397 f,
4398 " CLUSTER BY ({})",
4399 display_comma_separated(&self.cluster_by)
4400 )?;
4401 }
4402 if matches!(self.options, CreateTableOptions::Options(_)) {
4403 write!(f, " {}", self.options)?;
4404 }
4405 f.write_str(" AS")?;
4406 SpaceOrNewline.fmt(f)?;
4407 self.query.fmt(f)?;
4408 if self.with_no_schema_binding {
4409 write!(f, " WITH NO SCHEMA BINDING")?;
4410 }
4411 Ok(())
4412 }
4413}
4414
4415#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4418#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4419#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4420pub struct CreateExtension {
4421 pub name: Ident,
4423 pub if_not_exists: bool,
4425 pub cascade: bool,
4427 pub schema: Option<Ident>,
4429 pub version: Option<Ident>,
4431}
4432
4433impl fmt::Display for CreateExtension {
4434 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4435 write!(
4436 f,
4437 "CREATE EXTENSION {if_not_exists}{name}",
4438 if_not_exists = if self.if_not_exists {
4439 "IF NOT EXISTS "
4440 } else {
4441 ""
4442 },
4443 name = self.name
4444 )?;
4445 if self.cascade || self.schema.is_some() || self.version.is_some() {
4446 write!(f, " WITH")?;
4447
4448 if let Some(name) = &self.schema {
4449 write!(f, " SCHEMA {name}")?;
4450 }
4451 if let Some(version) = &self.version {
4452 write!(f, " VERSION {version}")?;
4453 }
4454 if self.cascade {
4455 write!(f, " CASCADE")?;
4456 }
4457 }
4458
4459 Ok(())
4460 }
4461}
4462
4463impl Spanned for CreateExtension {
4464 fn span(&self) -> Span {
4465 Span::empty()
4466 }
4467}
4468
4469#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4477#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4478#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4479pub struct DropExtension {
4480 pub names: Vec<Ident>,
4482 pub if_exists: bool,
4484 pub cascade_or_restrict: Option<ReferentialAction>,
4486}
4487
4488impl fmt::Display for DropExtension {
4489 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4490 write!(f, "DROP EXTENSION")?;
4491 if self.if_exists {
4492 write!(f, " IF EXISTS")?;
4493 }
4494 write!(f, " {}", display_comma_separated(&self.names))?;
4495 if let Some(cascade_or_restrict) = &self.cascade_or_restrict {
4496 write!(f, " {cascade_or_restrict}")?;
4497 }
4498 Ok(())
4499 }
4500}
4501
4502impl Spanned for DropExtension {
4503 fn span(&self) -> Span {
4504 Span::empty()
4505 }
4506}
4507
4508#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4511#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4512#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4513pub struct CreateCollation {
4514 pub if_not_exists: bool,
4516 pub name: ObjectName,
4518 pub definition: CreateCollationDefinition,
4520}
4521
4522#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4524#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4525#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4526pub enum CreateCollationDefinition {
4527 From(ObjectName),
4533 Options(Vec<SqlOption>),
4539}
4540
4541impl fmt::Display for CreateCollation {
4542 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4543 write!(
4544 f,
4545 "CREATE COLLATION {if_not_exists}{name}",
4546 if_not_exists = if self.if_not_exists {
4547 "IF NOT EXISTS "
4548 } else {
4549 ""
4550 },
4551 name = self.name
4552 )?;
4553 match &self.definition {
4554 CreateCollationDefinition::From(existing_collation) => {
4555 write!(f, " FROM {existing_collation}")
4556 }
4557 CreateCollationDefinition::Options(options) => {
4558 write!(f, " ({})", display_comma_separated(options))
4559 }
4560 }
4561 }
4562}
4563
4564impl Spanned for CreateCollation {
4565 fn span(&self) -> Span {
4566 Span::empty()
4567 }
4568}
4569
4570#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4573#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4574#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4575pub struct AlterCollation {
4576 pub name: ObjectName,
4578 pub operation: AlterCollationOperation,
4580}
4581
4582#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4584#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4585#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4586pub enum AlterCollationOperation {
4587 RenameTo {
4593 new_name: Ident,
4595 },
4596 OwnerTo(Owner),
4602 SetSchema {
4608 schema_name: ObjectName,
4610 },
4611 RefreshVersion,
4617}
4618
4619impl fmt::Display for AlterCollationOperation {
4620 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4621 match self {
4622 AlterCollationOperation::RenameTo { new_name } => write!(f, "RENAME TO {new_name}"),
4623 AlterCollationOperation::OwnerTo(owner) => write!(f, "OWNER TO {owner}"),
4624 AlterCollationOperation::SetSchema { schema_name } => {
4625 write!(f, "SET SCHEMA {schema_name}")
4626 }
4627 AlterCollationOperation::RefreshVersion => write!(f, "REFRESH VERSION"),
4628 }
4629 }
4630}
4631
4632impl fmt::Display for AlterCollation {
4633 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4634 write!(f, "ALTER COLLATION {} {}", self.name, self.operation)
4635 }
4636}
4637
4638impl Spanned for AlterCollation {
4639 fn span(&self) -> Span {
4640 Span::empty()
4641 }
4642}
4643
4644#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4647#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4648#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4649pub enum AlterTableType {
4650 Iceberg,
4653 Dynamic,
4656 External,
4659}
4660
4661#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4663#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4664#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4665pub struct AlterTable {
4666 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4668 pub name: ObjectName,
4669 pub if_exists: bool,
4671 pub only: bool,
4673 pub operations: Vec<AlterTableOperation>,
4675 pub location: Option<HiveSetLocation>,
4677 pub on_cluster: Option<Ident>,
4681 pub table_type: Option<AlterTableType>,
4683 pub end_token: AttachedToken,
4685}
4686
4687impl fmt::Display for AlterTable {
4688 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4689 match &self.table_type {
4690 Some(AlterTableType::Iceberg) => write!(f, "ALTER ICEBERG TABLE ")?,
4691 Some(AlterTableType::Dynamic) => write!(f, "ALTER DYNAMIC TABLE ")?,
4692 Some(AlterTableType::External) => write!(f, "ALTER EXTERNAL TABLE ")?,
4693 None => write!(f, "ALTER TABLE ")?,
4694 }
4695
4696 if self.if_exists {
4697 write!(f, "IF EXISTS ")?;
4698 }
4699 if self.only {
4700 write!(f, "ONLY ")?;
4701 }
4702 write!(f, "{} ", &self.name)?;
4703 if let Some(cluster) = &self.on_cluster {
4704 write!(f, "ON CLUSTER {cluster} ")?;
4705 }
4706 write!(f, "{}", display_comma_separated(&self.operations))?;
4707 if let Some(loc) = &self.location {
4708 write!(f, " {loc}")?
4709 }
4710 Ok(())
4711 }
4712}
4713
4714#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4716#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4717#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4718pub struct DropFunction {
4719 pub if_exists: bool,
4721 pub func_desc: Vec<FunctionDesc>,
4723 pub drop_behavior: Option<DropBehavior>,
4725}
4726
4727impl fmt::Display for DropFunction {
4728 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4729 write!(
4730 f,
4731 "DROP FUNCTION{} {}",
4732 if self.if_exists { " IF EXISTS" } else { "" },
4733 display_comma_separated(&self.func_desc),
4734 )?;
4735 if let Some(op) = &self.drop_behavior {
4736 write!(f, " {op}")?;
4737 }
4738 Ok(())
4739 }
4740}
4741
4742impl Spanned for DropFunction {
4743 fn span(&self) -> Span {
4744 Span::empty()
4745 }
4746}
4747
4748#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4751#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4752#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4753pub struct CreateOperator {
4754 pub name: ObjectName,
4756 pub function: ObjectName,
4758 pub is_procedure: bool,
4760 pub left_arg: Option<DataType>,
4762 pub right_arg: Option<DataType>,
4764 pub options: Vec<OperatorOption>,
4766}
4767
4768#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4771#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4772#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4773pub struct CreateOperatorFamily {
4774 pub name: ObjectName,
4776 pub using: Ident,
4778}
4779
4780#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4783#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4784#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4785pub struct CreateOperatorClass {
4786 pub name: ObjectName,
4788 pub default: bool,
4790 pub for_type: DataType,
4792 pub using: Ident,
4794 pub family: Option<ObjectName>,
4796 pub items: Vec<OperatorClassItem>,
4798}
4799
4800impl fmt::Display for CreateOperator {
4801 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4802 write!(f, "CREATE OPERATOR {} (", self.name)?;
4803
4804 let function_keyword = if self.is_procedure {
4805 "PROCEDURE"
4806 } else {
4807 "FUNCTION"
4808 };
4809 let mut params = vec![format!("{} = {}", function_keyword, self.function)];
4810
4811 if let Some(left_arg) = &self.left_arg {
4812 params.push(format!("LEFTARG = {}", left_arg));
4813 }
4814 if let Some(right_arg) = &self.right_arg {
4815 params.push(format!("RIGHTARG = {}", right_arg));
4816 }
4817
4818 for option in &self.options {
4819 params.push(option.to_string());
4820 }
4821
4822 write!(f, "{}", params.join(", "))?;
4823 write!(f, ")")
4824 }
4825}
4826
4827impl fmt::Display for CreateOperatorFamily {
4828 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4829 write!(
4830 f,
4831 "CREATE OPERATOR FAMILY {} USING {}",
4832 self.name, self.using
4833 )
4834 }
4835}
4836
4837impl fmt::Display for CreateOperatorClass {
4838 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4839 write!(f, "CREATE OPERATOR CLASS {}", self.name)?;
4840 if self.default {
4841 write!(f, " DEFAULT")?;
4842 }
4843 write!(f, " FOR TYPE {} USING {}", self.for_type, self.using)?;
4844 if let Some(family) = &self.family {
4845 write!(f, " FAMILY {}", family)?;
4846 }
4847 write!(f, " AS {}", display_comma_separated(&self.items))
4848 }
4849}
4850
4851#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4853#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4854#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4855pub struct OperatorArgTypes {
4856 pub left: DataType,
4858 pub right: DataType,
4860}
4861
4862impl fmt::Display for OperatorArgTypes {
4863 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4864 write!(f, "{}, {}", self.left, self.right)
4865 }
4866}
4867
4868#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4870#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4871#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4872pub enum OperatorClassItem {
4873 Operator {
4875 strategy_number: u64,
4877 operator_name: ObjectName,
4879 op_types: Option<OperatorArgTypes>,
4881 purpose: Option<OperatorPurpose>,
4883 },
4884 Function {
4886 support_number: u64,
4888 op_types: Option<Vec<DataType>>,
4890 function_name: ObjectName,
4892 argument_types: Vec<DataType>,
4894 },
4895 Storage {
4897 storage_type: DataType,
4899 },
4900}
4901
4902#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4904#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4905#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4906pub enum OperatorPurpose {
4907 ForSearch,
4909 ForOrderBy {
4911 sort_family: ObjectName,
4913 },
4914}
4915
4916impl fmt::Display for OperatorClassItem {
4917 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4918 match self {
4919 OperatorClassItem::Operator {
4920 strategy_number,
4921 operator_name,
4922 op_types,
4923 purpose,
4924 } => {
4925 write!(f, "OPERATOR {strategy_number} {operator_name}")?;
4926 if let Some(types) = op_types {
4927 write!(f, " ({types})")?;
4928 }
4929 if let Some(purpose) = purpose {
4930 write!(f, " {purpose}")?;
4931 }
4932 Ok(())
4933 }
4934 OperatorClassItem::Function {
4935 support_number,
4936 op_types,
4937 function_name,
4938 argument_types,
4939 } => {
4940 write!(f, "FUNCTION {support_number}")?;
4941 if let Some(types) = op_types {
4942 write!(f, " ({})", display_comma_separated(types))?;
4943 }
4944 write!(f, " {function_name}")?;
4945 if !argument_types.is_empty() {
4946 write!(f, "({})", display_comma_separated(argument_types))?;
4947 }
4948 Ok(())
4949 }
4950 OperatorClassItem::Storage { storage_type } => {
4951 write!(f, "STORAGE {storage_type}")
4952 }
4953 }
4954 }
4955}
4956
4957impl fmt::Display for OperatorPurpose {
4958 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4959 match self {
4960 OperatorPurpose::ForSearch => write!(f, "FOR SEARCH"),
4961 OperatorPurpose::ForOrderBy { sort_family } => {
4962 write!(f, "FOR ORDER BY {sort_family}")
4963 }
4964 }
4965 }
4966}
4967
4968#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4971#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4972#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4973pub struct DropOperator {
4974 pub if_exists: bool,
4976 pub operators: Vec<DropOperatorSignature>,
4978 pub drop_behavior: Option<DropBehavior>,
4980}
4981
4982#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4984#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4985#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4986pub struct DropOperatorSignature {
4987 pub name: ObjectName,
4989 pub left_type: Option<DataType>,
4991 pub right_type: DataType,
4993}
4994
4995impl fmt::Display for DropOperatorSignature {
4996 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4997 write!(f, "{} (", self.name)?;
4998 if let Some(left_type) = &self.left_type {
4999 write!(f, "{}", left_type)?;
5000 } else {
5001 write!(f, "NONE")?;
5002 }
5003 write!(f, ", {})", self.right_type)
5004 }
5005}
5006
5007impl fmt::Display for DropOperator {
5008 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5009 write!(f, "DROP OPERATOR")?;
5010 if self.if_exists {
5011 write!(f, " IF EXISTS")?;
5012 }
5013 write!(f, " {}", display_comma_separated(&self.operators))?;
5014 if let Some(drop_behavior) = &self.drop_behavior {
5015 write!(f, " {}", drop_behavior)?;
5016 }
5017 Ok(())
5018 }
5019}
5020
5021impl Spanned for DropOperator {
5022 fn span(&self) -> Span {
5023 Span::empty()
5024 }
5025}
5026
5027#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5030#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5031#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5032pub struct DropOperatorFamily {
5033 pub if_exists: bool,
5035 pub names: Vec<ObjectName>,
5037 pub using: Ident,
5039 pub drop_behavior: Option<DropBehavior>,
5041}
5042
5043impl fmt::Display for DropOperatorFamily {
5044 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5045 write!(f, "DROP OPERATOR FAMILY")?;
5046 if self.if_exists {
5047 write!(f, " IF EXISTS")?;
5048 }
5049 write!(f, " {}", display_comma_separated(&self.names))?;
5050 write!(f, " USING {}", self.using)?;
5051 if let Some(drop_behavior) = &self.drop_behavior {
5052 write!(f, " {}", drop_behavior)?;
5053 }
5054 Ok(())
5055 }
5056}
5057
5058impl Spanned for DropOperatorFamily {
5059 fn span(&self) -> Span {
5060 Span::empty()
5061 }
5062}
5063
5064#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5067#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5068#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5069pub struct DropOperatorClass {
5070 pub if_exists: bool,
5072 pub names: Vec<ObjectName>,
5074 pub using: Ident,
5076 pub drop_behavior: Option<DropBehavior>,
5078}
5079
5080impl fmt::Display for DropOperatorClass {
5081 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5082 write!(f, "DROP OPERATOR CLASS")?;
5083 if self.if_exists {
5084 write!(f, " IF EXISTS")?;
5085 }
5086 write!(f, " {}", display_comma_separated(&self.names))?;
5087 write!(f, " USING {}", self.using)?;
5088 if let Some(drop_behavior) = &self.drop_behavior {
5089 write!(f, " {}", drop_behavior)?;
5090 }
5091 Ok(())
5092 }
5093}
5094
5095impl Spanned for DropOperatorClass {
5096 fn span(&self) -> Span {
5097 Span::empty()
5098 }
5099}
5100
5101#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5103#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5104#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5105pub enum OperatorFamilyItem {
5106 Operator {
5108 strategy_number: u64,
5110 operator_name: ObjectName,
5112 op_types: Vec<DataType>,
5114 purpose: Option<OperatorPurpose>,
5116 },
5117 Function {
5119 support_number: u64,
5121 op_types: Option<Vec<DataType>>,
5123 function_name: ObjectName,
5125 argument_types: Vec<DataType>,
5127 },
5128}
5129
5130#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5132#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5133#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5134pub enum OperatorFamilyDropItem {
5135 Operator {
5137 strategy_number: u64,
5139 op_types: Vec<DataType>,
5141 },
5142 Function {
5144 support_number: u64,
5146 op_types: Vec<DataType>,
5148 },
5149}
5150
5151impl fmt::Display for OperatorFamilyItem {
5152 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5153 match self {
5154 OperatorFamilyItem::Operator {
5155 strategy_number,
5156 operator_name,
5157 op_types,
5158 purpose,
5159 } => {
5160 write!(
5161 f,
5162 "OPERATOR {strategy_number} {operator_name} ({})",
5163 display_comma_separated(op_types)
5164 )?;
5165 if let Some(purpose) = purpose {
5166 write!(f, " {purpose}")?;
5167 }
5168 Ok(())
5169 }
5170 OperatorFamilyItem::Function {
5171 support_number,
5172 op_types,
5173 function_name,
5174 argument_types,
5175 } => {
5176 write!(f, "FUNCTION {support_number}")?;
5177 if let Some(types) = op_types {
5178 write!(f, " ({})", display_comma_separated(types))?;
5179 }
5180 write!(f, " {function_name}")?;
5181 if !argument_types.is_empty() {
5182 write!(f, "({})", display_comma_separated(argument_types))?;
5183 }
5184 Ok(())
5185 }
5186 }
5187 }
5188}
5189
5190impl fmt::Display for OperatorFamilyDropItem {
5191 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5192 match self {
5193 OperatorFamilyDropItem::Operator {
5194 strategy_number,
5195 op_types,
5196 } => {
5197 write!(
5198 f,
5199 "OPERATOR {strategy_number} ({})",
5200 display_comma_separated(op_types)
5201 )
5202 }
5203 OperatorFamilyDropItem::Function {
5204 support_number,
5205 op_types,
5206 } => {
5207 write!(
5208 f,
5209 "FUNCTION {support_number} ({})",
5210 display_comma_separated(op_types)
5211 )
5212 }
5213 }
5214 }
5215}
5216
5217#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5220#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5221#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5222pub struct AlterOperatorFamily {
5223 pub name: ObjectName,
5225 pub using: Ident,
5227 pub operation: AlterOperatorFamilyOperation,
5229}
5230
5231#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5233#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5234#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5235pub enum AlterOperatorFamilyOperation {
5236 Add {
5238 items: Vec<OperatorFamilyItem>,
5240 },
5241 Drop {
5243 items: Vec<OperatorFamilyDropItem>,
5245 },
5246 RenameTo {
5248 new_name: ObjectName,
5250 },
5251 OwnerTo(Owner),
5253 SetSchema {
5255 schema_name: ObjectName,
5257 },
5258}
5259
5260impl fmt::Display for AlterOperatorFamily {
5261 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5262 write!(
5263 f,
5264 "ALTER OPERATOR FAMILY {} USING {}",
5265 self.name, self.using
5266 )?;
5267 write!(f, " {}", self.operation)
5268 }
5269}
5270
5271impl fmt::Display for AlterOperatorFamilyOperation {
5272 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5273 match self {
5274 AlterOperatorFamilyOperation::Add { items } => {
5275 write!(f, "ADD {}", display_comma_separated(items))
5276 }
5277 AlterOperatorFamilyOperation::Drop { items } => {
5278 write!(f, "DROP {}", display_comma_separated(items))
5279 }
5280 AlterOperatorFamilyOperation::RenameTo { new_name } => {
5281 write!(f, "RENAME TO {new_name}")
5282 }
5283 AlterOperatorFamilyOperation::OwnerTo(owner) => {
5284 write!(f, "OWNER TO {owner}")
5285 }
5286 AlterOperatorFamilyOperation::SetSchema { schema_name } => {
5287 write!(f, "SET SCHEMA {schema_name}")
5288 }
5289 }
5290 }
5291}
5292
5293impl Spanned for AlterOperatorFamily {
5294 fn span(&self) -> Span {
5295 Span::empty()
5296 }
5297}
5298
5299#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5302#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5303#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5304pub struct AlterOperatorClass {
5305 pub name: ObjectName,
5307 pub using: Ident,
5309 pub operation: AlterOperatorClassOperation,
5311}
5312
5313#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5315#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5316#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5317pub enum AlterOperatorClassOperation {
5318 RenameTo {
5321 new_name: ObjectName,
5323 },
5324 OwnerTo(Owner),
5326 SetSchema {
5329 schema_name: ObjectName,
5331 },
5332}
5333
5334impl fmt::Display for AlterOperatorClass {
5335 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5336 write!(f, "ALTER OPERATOR CLASS {} USING {}", self.name, self.using)?;
5337 write!(f, " {}", self.operation)
5338 }
5339}
5340
5341impl fmt::Display for AlterOperatorClassOperation {
5342 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5343 match self {
5344 AlterOperatorClassOperation::RenameTo { new_name } => {
5345 write!(f, "RENAME TO {new_name}")
5346 }
5347 AlterOperatorClassOperation::OwnerTo(owner) => {
5348 write!(f, "OWNER TO {owner}")
5349 }
5350 AlterOperatorClassOperation::SetSchema { schema_name } => {
5351 write!(f, "SET SCHEMA {schema_name}")
5352 }
5353 }
5354 }
5355}
5356
5357impl Spanned for AlterOperatorClass {
5358 fn span(&self) -> Span {
5359 Span::empty()
5360 }
5361}
5362
5363#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5365#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5366#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5367pub struct AlterFunction {
5368 pub kind: AlterFunctionKind,
5370 pub function: FunctionDesc,
5372 pub aggregate_order_by: Option<Vec<OperateFunctionArg>>,
5376 pub aggregate_star: bool,
5380 pub operation: AlterFunctionOperation,
5382}
5383
5384#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5386#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5387#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5388pub enum AlterFunctionKind {
5389 Function,
5391 Aggregate,
5393}
5394
5395impl fmt::Display for AlterFunctionKind {
5396 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5397 match self {
5398 Self::Function => write!(f, "FUNCTION"),
5399 Self::Aggregate => write!(f, "AGGREGATE"),
5400 }
5401 }
5402}
5403
5404#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5406#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5407#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5408pub enum AlterFunctionOperation {
5409 RenameTo {
5411 new_name: Ident,
5413 },
5414 OwnerTo(Owner),
5416 SetSchema {
5418 schema_name: ObjectName,
5420 },
5421 DependsOnExtension {
5423 no: bool,
5425 extension_name: ObjectName,
5427 },
5428 Actions {
5430 actions: Vec<AlterFunctionAction>,
5432 restrict: bool,
5434 },
5435}
5436
5437#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5439#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5440#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5441pub enum AlterFunctionAction {
5442 CalledOnNull(FunctionCalledOnNull),
5444 Behavior(FunctionBehavior),
5446 Leakproof(bool),
5448 Security {
5450 external: bool,
5452 security: FunctionSecurity,
5454 },
5455 Parallel(FunctionParallel),
5457 Cost(Expr),
5459 Rows(Expr),
5461 Support(ObjectName),
5463 Set(FunctionDefinitionSetParam),
5466 Reset(ResetConfig),
5468}
5469
5470impl fmt::Display for AlterFunction {
5471 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5472 write!(f, "ALTER {} ", self.kind)?;
5473 match self.kind {
5474 AlterFunctionKind::Function => {
5475 write!(f, "{} ", self.function)?;
5476 }
5477 AlterFunctionKind::Aggregate => {
5478 write!(f, "{}(", self.function.name)?;
5479 if self.aggregate_star {
5480 write!(f, "*")?;
5481 } else {
5482 if let Some(args) = &self.function.args {
5483 write!(f, "{}", display_comma_separated(args))?;
5484 }
5485 if let Some(order_by_args) = &self.aggregate_order_by {
5486 if self
5487 .function
5488 .args
5489 .as_ref()
5490 .is_some_and(|args| !args.is_empty())
5491 {
5492 write!(f, " ")?;
5493 }
5494 write!(f, "ORDER BY {}", display_comma_separated(order_by_args))?;
5495 }
5496 }
5497 write!(f, ") ")?;
5498 }
5499 }
5500 write!(f, "{}", self.operation)
5501 }
5502}
5503
5504impl fmt::Display for AlterFunctionOperation {
5505 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5506 match self {
5507 AlterFunctionOperation::RenameTo { new_name } => {
5508 write!(f, "RENAME TO {new_name}")
5509 }
5510 AlterFunctionOperation::OwnerTo(owner) => write!(f, "OWNER TO {owner}"),
5511 AlterFunctionOperation::SetSchema { schema_name } => {
5512 write!(f, "SET SCHEMA {schema_name}")
5513 }
5514 AlterFunctionOperation::DependsOnExtension { no, extension_name } => {
5515 if *no {
5516 write!(f, "NO DEPENDS ON EXTENSION {extension_name}")
5517 } else {
5518 write!(f, "DEPENDS ON EXTENSION {extension_name}")
5519 }
5520 }
5521 AlterFunctionOperation::Actions { actions, restrict } => {
5522 write!(f, "{}", display_separated(actions, " "))?;
5523 if *restrict {
5524 write!(f, " RESTRICT")?;
5525 }
5526 Ok(())
5527 }
5528 }
5529 }
5530}
5531
5532impl fmt::Display for AlterFunctionAction {
5533 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5534 match self {
5535 AlterFunctionAction::CalledOnNull(called_on_null) => write!(f, "{called_on_null}"),
5536 AlterFunctionAction::Behavior(behavior) => write!(f, "{behavior}"),
5537 AlterFunctionAction::Leakproof(leakproof) => {
5538 if *leakproof {
5539 write!(f, "LEAKPROOF")
5540 } else {
5541 write!(f, "NOT LEAKPROOF")
5542 }
5543 }
5544 AlterFunctionAction::Security { external, security } => {
5545 if *external {
5546 write!(f, "EXTERNAL ")?;
5547 }
5548 write!(f, "{security}")
5549 }
5550 AlterFunctionAction::Parallel(parallel) => write!(f, "{parallel}"),
5551 AlterFunctionAction::Cost(execution_cost) => write!(f, "COST {execution_cost}"),
5552 AlterFunctionAction::Rows(result_rows) => write!(f, "ROWS {result_rows}"),
5553 AlterFunctionAction::Support(support_function) => {
5554 write!(f, "SUPPORT {support_function}")
5555 }
5556 AlterFunctionAction::Set(set_param) => write!(f, "{set_param}"),
5557 AlterFunctionAction::Reset(reset_config) => match reset_config {
5558 ResetConfig::ALL => write!(f, "RESET ALL"),
5559 ResetConfig::ConfigName(name) => write!(f, "RESET {name}"),
5560 },
5561 }
5562 }
5563}
5564
5565impl Spanned for AlterFunction {
5566 fn span(&self) -> Span {
5567 Span::empty()
5568 }
5569}
5570
5571#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5575#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5576#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5577pub struct CreatePolicy {
5578 pub name: Ident,
5580 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
5582 pub table_name: ObjectName,
5583 pub policy_type: Option<CreatePolicyType>,
5585 pub command: Option<CreatePolicyCommand>,
5587 pub to: Option<Vec<Owner>>,
5589 pub using: Option<Expr>,
5591 pub with_check: Option<Expr>,
5593}
5594
5595impl fmt::Display for CreatePolicy {
5596 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5597 write!(
5598 f,
5599 "CREATE POLICY {name} ON {table_name}",
5600 name = self.name,
5601 table_name = self.table_name,
5602 )?;
5603 if let Some(ref policy_type) = self.policy_type {
5604 write!(f, " AS {policy_type}")?;
5605 }
5606 if let Some(ref command) = self.command {
5607 write!(f, " FOR {command}")?;
5608 }
5609 if let Some(ref to) = self.to {
5610 write!(f, " TO {}", display_comma_separated(to))?;
5611 }
5612 if let Some(ref using) = self.using {
5613 write!(f, " USING ({using})")?;
5614 }
5615 if let Some(ref with_check) = self.with_check {
5616 write!(f, " WITH CHECK ({with_check})")?;
5617 }
5618 Ok(())
5619 }
5620}
5621
5622#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
5628#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5629#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5630pub enum CreatePolicyType {
5631 Permissive,
5633 Restrictive,
5635}
5636
5637impl fmt::Display for CreatePolicyType {
5638 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5639 match self {
5640 CreatePolicyType::Permissive => write!(f, "PERMISSIVE"),
5641 CreatePolicyType::Restrictive => write!(f, "RESTRICTIVE"),
5642 }
5643 }
5644}
5645
5646#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
5652#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5653#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5654pub enum CreatePolicyCommand {
5655 All,
5657 Select,
5659 Insert,
5661 Update,
5663 Delete,
5665}
5666
5667impl fmt::Display for CreatePolicyCommand {
5668 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5669 match self {
5670 CreatePolicyCommand::All => write!(f, "ALL"),
5671 CreatePolicyCommand::Select => write!(f, "SELECT"),
5672 CreatePolicyCommand::Insert => write!(f, "INSERT"),
5673 CreatePolicyCommand::Update => write!(f, "UPDATE"),
5674 CreatePolicyCommand::Delete => write!(f, "DELETE"),
5675 }
5676 }
5677}
5678
5679#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5683#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5684#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5685pub struct DropPolicy {
5686 pub if_exists: bool,
5688 pub name: Ident,
5690 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
5692 pub table_name: ObjectName,
5693 pub drop_behavior: Option<DropBehavior>,
5695}
5696
5697impl fmt::Display for DropPolicy {
5698 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5699 write!(
5700 f,
5701 "DROP POLICY {if_exists}{name} ON {table_name}",
5702 if_exists = if self.if_exists { "IF EXISTS " } else { "" },
5703 name = self.name,
5704 table_name = self.table_name
5705 )?;
5706 if let Some(ref behavior) = self.drop_behavior {
5707 write!(f, " {behavior}")?;
5708 }
5709 Ok(())
5710 }
5711}
5712
5713impl From<CreatePolicy> for crate::ast::Statement {
5714 fn from(v: CreatePolicy) -> Self {
5715 crate::ast::Statement::CreatePolicy(v)
5716 }
5717}
5718
5719impl From<DropPolicy> for crate::ast::Statement {
5720 fn from(v: DropPolicy) -> Self {
5721 crate::ast::Statement::DropPolicy(v)
5722 }
5723}
5724
5725#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5732#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5733#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5734pub struct AlterPolicy {
5735 pub name: Ident,
5737 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
5739 pub table_name: ObjectName,
5740 pub operation: AlterPolicyOperation,
5742}
5743
5744impl fmt::Display for AlterPolicy {
5745 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5746 write!(
5747 f,
5748 "ALTER POLICY {name} ON {table_name}{operation}",
5749 name = self.name,
5750 table_name = self.table_name,
5751 operation = self.operation
5752 )
5753 }
5754}
5755
5756impl From<AlterPolicy> for crate::ast::Statement {
5757 fn from(v: AlterPolicy) -> Self {
5758 crate::ast::Statement::AlterPolicy(v)
5759 }
5760}
5761
5762#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5766#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5767#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5768pub enum FdwRoutineClause {
5769 Function(ObjectName),
5771 NoFunction,
5773}
5774
5775#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5779#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5780#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5781pub struct CreateForeignDataWrapper {
5782 pub name: Ident,
5784 pub handler: Option<FdwRoutineClause>,
5786 pub validator: Option<FdwRoutineClause>,
5788 pub options: Option<Vec<CreateServerOption>>,
5790}
5791
5792impl fmt::Display for CreateForeignDataWrapper {
5793 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5794 write!(f, "CREATE FOREIGN DATA WRAPPER {}", self.name)?;
5795 if let Some(handler) = &self.handler {
5796 match handler {
5797 FdwRoutineClause::Function(name) => write!(f, " HANDLER {name}")?,
5798 FdwRoutineClause::NoFunction => write!(f, " NO HANDLER")?,
5799 }
5800 }
5801 if let Some(validator) = &self.validator {
5802 match validator {
5803 FdwRoutineClause::Function(name) => write!(f, " VALIDATOR {name}")?,
5804 FdwRoutineClause::NoFunction => write!(f, " NO VALIDATOR")?,
5805 }
5806 }
5807 if let Some(options) = &self.options {
5808 write!(f, " OPTIONS ({})", display_comma_separated(options))?;
5809 }
5810 Ok(())
5811 }
5812}
5813
5814impl From<CreateForeignDataWrapper> for crate::ast::Statement {
5815 fn from(v: CreateForeignDataWrapper) -> Self {
5816 crate::ast::Statement::CreateForeignDataWrapper(v)
5817 }
5818}
5819
5820#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5824#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5825#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5826pub struct CreateForeignTable {
5827 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
5829 pub name: ObjectName,
5830 pub if_not_exists: bool,
5832 pub columns: Vec<ColumnDef>,
5834 pub server_name: Ident,
5836 pub options: Option<Vec<CreateServerOption>>,
5838}
5839
5840impl fmt::Display for CreateForeignTable {
5841 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5842 write!(
5843 f,
5844 "CREATE FOREIGN TABLE {if_not_exists}{name} ({columns}) SERVER {server_name}",
5845 if_not_exists = if self.if_not_exists { "IF NOT EXISTS " } else { "" },
5846 name = self.name,
5847 columns = display_comma_separated(&self.columns),
5848 server_name = self.server_name,
5849 )?;
5850 if let Some(options) = &self.options {
5851 write!(f, " OPTIONS ({})", display_comma_separated(options))?;
5852 }
5853 Ok(())
5854 }
5855}
5856
5857impl From<CreateForeignTable> for crate::ast::Statement {
5858 fn from(v: CreateForeignTable) -> Self {
5859 crate::ast::Statement::CreateForeignTable(v)
5860 }
5861}
5862
5863#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5866#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5867#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5868pub struct CreateAggregate {
5869 pub or_replace: bool,
5871 pub name: ObjectName,
5873 pub args: Vec<DataType>,
5875 pub options: Vec<CreateAggregateOption>,
5878}
5879
5880impl fmt::Display for CreateAggregate {
5881 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5882 write!(f, "CREATE")?;
5883 if self.or_replace {
5884 write!(f, " OR REPLACE")?;
5885 }
5886 write!(f, " AGGREGATE {}", self.name)?;
5887 write!(f, " ({})", display_comma_separated(&self.args))?;
5888 write!(f, " (")?;
5889 for (i, option) in self.options.iter().enumerate() {
5890 if i > 0 {
5891 write!(f, ", ")?;
5892 }
5893 write!(f, "{option}")?;
5894 }
5895 write!(f, ")")
5896 }
5897}
5898
5899impl From<CreateAggregate> for crate::ast::Statement {
5900 fn from(v: CreateAggregate) -> Self {
5901 crate::ast::Statement::CreateAggregate(v)
5902 }
5903}
5904
5905#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5909#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5910#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5911pub enum CreateAggregateOption {
5912 Sfunc(ObjectName),
5914 Stype(DataType),
5916 Sspace(u64),
5918 Finalfunc(ObjectName),
5920 FinalfuncExtra,
5922 FinalfuncModify(AggregateModifyKind),
5924 Combinefunc(ObjectName),
5926 Serialfunc(ObjectName),
5928 Deserialfunc(ObjectName),
5930 Initcond(Value),
5932 Msfunc(ObjectName),
5934 Minvfunc(ObjectName),
5936 Mstype(DataType),
5938 Msspace(u64),
5940 Mfinalfunc(ObjectName),
5942 MfinalfuncExtra,
5944 MfinalfuncModify(AggregateModifyKind),
5946 Minitcond(Value),
5948 Sortop(ObjectName),
5950 Parallel(FunctionParallel),
5952 Hypothetical,
5954}
5955
5956impl fmt::Display for CreateAggregateOption {
5957 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5958 match self {
5959 Self::Sfunc(name) => write!(f, "SFUNC = {name}"),
5960 Self::Stype(data_type) => write!(f, "STYPE = {data_type}"),
5961 Self::Sspace(size) => write!(f, "SSPACE = {size}"),
5962 Self::Finalfunc(name) => write!(f, "FINALFUNC = {name}"),
5963 Self::FinalfuncExtra => write!(f, "FINALFUNC_EXTRA"),
5964 Self::FinalfuncModify(kind) => write!(f, "FINALFUNC_MODIFY = {kind}"),
5965 Self::Combinefunc(name) => write!(f, "COMBINEFUNC = {name}"),
5966 Self::Serialfunc(name) => write!(f, "SERIALFUNC = {name}"),
5967 Self::Deserialfunc(name) => write!(f, "DESERIALFUNC = {name}"),
5968 Self::Initcond(cond) => write!(f, "INITCOND = {cond}"),
5969 Self::Msfunc(name) => write!(f, "MSFUNC = {name}"),
5970 Self::Minvfunc(name) => write!(f, "MINVFUNC = {name}"),
5971 Self::Mstype(data_type) => write!(f, "MSTYPE = {data_type}"),
5972 Self::Msspace(size) => write!(f, "MSSPACE = {size}"),
5973 Self::Mfinalfunc(name) => write!(f, "MFINALFUNC = {name}"),
5974 Self::MfinalfuncExtra => write!(f, "MFINALFUNC_EXTRA"),
5975 Self::MfinalfuncModify(kind) => write!(f, "MFINALFUNC_MODIFY = {kind}"),
5976 Self::Minitcond(cond) => write!(f, "MINITCOND = {cond}"),
5977 Self::Sortop(name) => write!(f, "SORTOP = {name}"),
5978 Self::Parallel(parallel) => {
5979 let kind = match parallel {
5980 FunctionParallel::Safe => "SAFE",
5981 FunctionParallel::Restricted => "RESTRICTED",
5982 FunctionParallel::Unsafe => "UNSAFE",
5983 };
5984 write!(f, "PARALLEL = {kind}")
5985 }
5986 Self::Hypothetical => write!(f, "HYPOTHETICAL"),
5987 }
5988 }
5989}
5990
5991#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5995#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5996#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5997pub enum AggregateModifyKind {
5998 ReadOnly,
6000 Shareable,
6002 ReadWrite,
6004}
6005
6006impl fmt::Display for AggregateModifyKind {
6007 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6008 match self {
6009 Self::ReadOnly => write!(f, "READ_ONLY"),
6010 Self::Shareable => write!(f, "SHAREABLE"),
6011 Self::ReadWrite => write!(f, "READ_WRITE"),
6012 }
6013 }
6014}
6015
6016#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6021#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6022#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6023pub struct CreateTextSearchConfiguration {
6024 pub name: ObjectName,
6026 pub options: Vec<SqlOption>,
6028}
6029
6030impl fmt::Display for CreateTextSearchConfiguration {
6031 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6032 write!(
6033 f,
6034 "CREATE TEXT SEARCH CONFIGURATION {name} ({options})",
6035 name = self.name,
6036 options = display_comma_separated(&self.options),
6037 )
6038 }
6039}
6040
6041impl From<CreateTextSearchConfiguration> for crate::ast::Statement {
6042 fn from(v: CreateTextSearchConfiguration) -> Self {
6043 crate::ast::Statement::CreateTextSearchConfiguration(v)
6044 }
6045}
6046
6047#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6052#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6053#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6054pub struct CreateTextSearchDictionary {
6055 pub name: ObjectName,
6057 pub options: Vec<SqlOption>,
6059}
6060
6061impl fmt::Display for CreateTextSearchDictionary {
6062 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6063 write!(
6064 f,
6065 "CREATE TEXT SEARCH DICTIONARY {name} ({options})",
6066 name = self.name,
6067 options = display_comma_separated(&self.options),
6068 )
6069 }
6070}
6071
6072impl From<CreateTextSearchDictionary> for crate::ast::Statement {
6073 fn from(v: CreateTextSearchDictionary) -> Self {
6074 crate::ast::Statement::CreateTextSearchDictionary(v)
6075 }
6076}
6077
6078#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6083#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6084#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6085pub struct CreateTextSearchParser {
6086 pub name: ObjectName,
6088 pub options: Vec<SqlOption>,
6090}
6091
6092impl fmt::Display for CreateTextSearchParser {
6093 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6094 write!(
6095 f,
6096 "CREATE TEXT SEARCH PARSER {name} ({options})",
6097 name = self.name,
6098 options = display_comma_separated(&self.options),
6099 )
6100 }
6101}
6102
6103impl From<CreateTextSearchParser> for crate::ast::Statement {
6104 fn from(v: CreateTextSearchParser) -> Self {
6105 crate::ast::Statement::CreateTextSearchParser(v)
6106 }
6107}
6108
6109#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6114#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6115#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6116pub struct CreateTextSearchTemplate {
6117 pub name: ObjectName,
6119 pub options: Vec<SqlOption>,
6121}
6122
6123impl fmt::Display for CreateTextSearchTemplate {
6124 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6125 write!(
6126 f,
6127 "CREATE TEXT SEARCH TEMPLATE {name} ({options})",
6128 name = self.name,
6129 options = display_comma_separated(&self.options),
6130 )
6131 }
6132}
6133
6134impl From<CreateTextSearchTemplate> for crate::ast::Statement {
6135 fn from(v: CreateTextSearchTemplate) -> Self {
6136 crate::ast::Statement::CreateTextSearchTemplate(v)
6137 }
6138}