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, FileFormat, FunctionBehavior, FunctionCalledOnNull,
47 FunctionDefinitionSetParam, FunctionDesc, FunctionDeterminismSpecifier, FunctionParallel,
48 FunctionSecurity, HiveDistributionStyle, HiveFormat, HiveIOFormat, HiveRowFormat,
49 HiveSetLocation, Ident, InitializeKind, MySQLColumnPosition, ObjectName, OnCommit,
50 OneOrManyWithParens, OperateFunctionArg, OrderByExpr, ProjectionSelect, Query, RefreshModeKind,
51 ResetConfig, RowAccessPolicy, SequenceOptions, Spanned, SqlOption, StorageLifecyclePolicy,
52 StorageSerializationPolicy, TableVersion, Tag, TriggerEvent, TriggerExecBody, TriggerObject,
53 TriggerPeriod, TriggerReferencing, Value, ValueWithSpan, WrappedCollection,
54};
55use crate::display_utils::{DisplayCommaSeparated, Indent, NewLine, SpaceOrNewline};
56use crate::keywords::Keyword;
57use crate::tokenizer::{Span, Token};
58
59#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
61#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
62#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
63pub struct IndexColumn {
64 pub column: OrderByExpr,
66 pub operator_class: Option<ObjectName>,
68}
69
70impl From<Ident> for IndexColumn {
71 fn from(c: Ident) -> Self {
72 Self {
73 column: OrderByExpr::from(c),
74 operator_class: None,
75 }
76 }
77}
78
79impl<'a> From<&'a str> for IndexColumn {
80 fn from(c: &'a str) -> Self {
81 let ident = Ident::new(c);
82 ident.into()
83 }
84}
85
86impl fmt::Display for IndexColumn {
87 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
88 write!(f, "{}", self.column)?;
89 if let Some(operator_class) = &self.operator_class {
90 write!(f, " {operator_class}")?;
91 }
92 Ok(())
93 }
94}
95
96#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
99#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
100#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
101pub enum ReplicaIdentity {
102 Nothing,
104 Full,
106 Default,
108 Index(Ident),
110}
111
112impl fmt::Display for ReplicaIdentity {
113 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
114 match self {
115 ReplicaIdentity::Nothing => f.write_str("NOTHING"),
116 ReplicaIdentity::Full => f.write_str("FULL"),
117 ReplicaIdentity::Default => f.write_str("DEFAULT"),
118 ReplicaIdentity::Index(idx) => write!(f, "USING INDEX {idx}"),
119 }
120 }
121}
122
123#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
125#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
126#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
127pub enum AlterTableOperation {
128 AddConstraint {
130 constraint: TableConstraint,
132 not_valid: bool,
134 },
135 AddColumn {
137 column_keyword: bool,
139 if_not_exists: bool,
141 column_def: ColumnDef,
143 column_position: Option<MySQLColumnPosition>,
145 },
146 AddProjection {
151 if_not_exists: bool,
153 name: Ident,
155 select: ProjectionSelect,
157 },
158 DropProjection {
163 if_exists: bool,
165 name: Ident,
167 },
168 MaterializeProjection {
173 if_exists: bool,
175 name: Ident,
177 partition: Option<Ident>,
179 },
180 ClearProjection {
185 if_exists: bool,
187 name: Ident,
189 partition: Option<Ident>,
191 },
192 DisableRowLevelSecurity,
197 DisableRule {
201 name: Ident,
203 },
204 DisableTrigger {
208 name: Ident,
210 },
211 DropConstraint {
213 if_exists: bool,
215 name: Ident,
217 drop_behavior: Option<DropBehavior>,
219 },
220 DropColumn {
222 has_column_keyword: bool,
224 column_names: Vec<Ident>,
226 if_exists: bool,
228 drop_behavior: Option<DropBehavior>,
230 },
231 AttachPartition {
235 partition: Partition,
239 },
240 DetachPartition {
244 partition: Partition,
247 },
248 AttachPartitionOf {
253 partition_name: ObjectName,
255 partition_bound: ForValues,
257 },
258 DetachPartitionOf {
263 partition_name: ObjectName,
265 concurrently: bool,
267 finalize: bool,
269 },
270 FreezePartition {
274 partition: Partition,
276 with_name: Option<Ident>,
278 },
279 UnfreezePartition {
283 partition: Partition,
285 with_name: Option<Ident>,
287 },
288 DropPrimaryKey {
293 drop_behavior: Option<DropBehavior>,
295 },
296 DropForeignKey {
301 name: Ident,
303 drop_behavior: Option<DropBehavior>,
305 },
306 DropIndex {
310 name: Ident,
312 },
313 EnableAlwaysRule {
317 name: Ident,
319 },
320 EnableAlwaysTrigger {
324 name: Ident,
326 },
327 EnableReplicaRule {
331 name: Ident,
333 },
334 EnableReplicaTrigger {
338 name: Ident,
340 },
341 EnableRowLevelSecurity,
346 ForceRowLevelSecurity,
351 NoForceRowLevelSecurity,
356 EnableRule {
360 name: Ident,
362 },
363 EnableTrigger {
367 name: Ident,
369 },
370 RenamePartitions {
372 old_partitions: Vec<Expr>,
374 new_partitions: Vec<Expr>,
376 },
377 ReplicaIdentity {
382 identity: ReplicaIdentity,
384 },
385 AddPartitions {
387 if_not_exists: bool,
389 new_partitions: Vec<Partition>,
391 },
392 DropPartitions {
394 partitions: Vec<Expr>,
396 if_exists: bool,
398 },
399 RenameColumn {
401 old_column_name: Ident,
403 new_column_name: Ident,
405 },
406 RenameTable {
408 table_name: RenameTableNameKind,
410 },
411 ChangeColumn {
414 old_name: Ident,
416 new_name: Ident,
418 data_type: DataType,
420 options: Vec<ColumnOption>,
422 column_position: Option<MySQLColumnPosition>,
424 },
425 ModifyColumn {
428 col_name: Ident,
430 data_type: DataType,
432 options: Vec<ColumnOption>,
434 column_position: Option<MySQLColumnPosition>,
436 },
437 RenameConstraint {
442 old_name: Ident,
444 new_name: Ident,
446 },
447 AlterColumn {
450 column_name: Ident,
452 op: AlterColumnOperation,
454 },
455 SwapWith {
459 table_name: ObjectName,
461 },
462 SetTblProperties {
464 table_properties: Vec<SqlOption>,
466 },
467 OwnerTo {
471 new_owner: Owner,
473 },
474 ClusterBy {
477 exprs: Vec<Expr>,
479 },
480 DropClusteringKey,
482 AlterSortKey {
485 columns: Vec<Expr>,
487 },
488 SuspendRecluster,
490 ResumeRecluster,
492 Refresh {
498 subpath: Option<String>,
500 },
501 Suspend,
505 Resume,
509 Algorithm {
515 equals: bool,
517 algorithm: AlterTableAlgorithm,
519 },
520
521 Lock {
527 equals: bool,
529 lock: AlterTableLock,
531 },
532 AutoIncrement {
538 equals: bool,
540 value: ValueWithSpan,
542 },
543 ValidateConstraint {
545 name: Ident,
547 },
548 SetOptionsParens {
556 options: Vec<SqlOption>,
558 },
559 SetTablespace {
564 tablespace_name: Ident,
566 },
567}
568
569#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
573#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
574#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
575pub enum AlterPolicyOperation {
576 Rename {
578 new_name: Ident,
580 },
581 Apply {
583 to: Option<Vec<Owner>>,
585 using: Option<Expr>,
587 with_check: Option<Expr>,
589 },
590}
591
592impl fmt::Display for AlterPolicyOperation {
593 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
594 match self {
595 AlterPolicyOperation::Rename { new_name } => {
596 write!(f, " RENAME TO {new_name}")
597 }
598 AlterPolicyOperation::Apply {
599 to,
600 using,
601 with_check,
602 } => {
603 if let Some(to) = to {
604 write!(f, " TO {}", display_comma_separated(to))?;
605 }
606 if let Some(using) = using {
607 write!(f, " USING ({using})")?;
608 }
609 if let Some(with_check) = with_check {
610 write!(f, " WITH CHECK ({with_check})")?;
611 }
612 Ok(())
613 }
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 AlterTableAlgorithm {
626 Default,
628 Instant,
630 Inplace,
632 Copy,
634}
635
636impl fmt::Display for AlterTableAlgorithm {
637 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
638 f.write_str(match self {
639 Self::Default => "DEFAULT",
640 Self::Instant => "INSTANT",
641 Self::Inplace => "INPLACE",
642 Self::Copy => "COPY",
643 })
644 }
645}
646
647#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
651#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
652#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
653pub enum AlterTableLock {
655 Default,
657 None,
659 Shared,
661 Exclusive,
663}
664
665impl fmt::Display for AlterTableLock {
666 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
667 f.write_str(match self {
668 Self::Default => "DEFAULT",
669 Self::None => "NONE",
670 Self::Shared => "SHARED",
671 Self::Exclusive => "EXCLUSIVE",
672 })
673 }
674}
675
676#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
677#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
678#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
679pub enum Owner {
681 Ident(Ident),
683 CurrentRole,
685 CurrentUser,
687 SessionUser,
689}
690
691impl fmt::Display for Owner {
692 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
693 match self {
694 Owner::Ident(ident) => write!(f, "{ident}"),
695 Owner::CurrentRole => write!(f, "CURRENT_ROLE"),
696 Owner::CurrentUser => write!(f, "CURRENT_USER"),
697 Owner::SessionUser => write!(f, "SESSION_USER"),
698 }
699 }
700}
701
702#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
703#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
704#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
705pub enum AlterConnectorOwner {
707 User(Ident),
709 Role(Ident),
711}
712
713impl fmt::Display for AlterConnectorOwner {
714 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
715 match self {
716 AlterConnectorOwner::User(ident) => write!(f, "USER {ident}"),
717 AlterConnectorOwner::Role(ident) => write!(f, "ROLE {ident}"),
718 }
719 }
720}
721
722#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
723#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
724#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
725pub enum AlterIndexOperation {
727 RenameIndex {
729 index_name: ObjectName,
731 },
732 SetTablespace {
737 tablespace_name: Ident,
739 },
740}
741
742impl fmt::Display for AlterTableOperation {
743 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
744 match self {
745 AlterTableOperation::AddPartitions {
746 if_not_exists,
747 new_partitions,
748 } => write!(
749 f,
750 "ADD{ine} {}",
751 display_separated(new_partitions, " "),
752 ine = if *if_not_exists { " IF NOT EXISTS" } else { "" }
753 ),
754 AlterTableOperation::AddConstraint {
755 not_valid,
756 constraint,
757 } => {
758 write!(f, "ADD {constraint}")?;
759 if *not_valid {
760 write!(f, " NOT VALID")?;
761 }
762 Ok(())
763 }
764 AlterTableOperation::AddColumn {
765 column_keyword,
766 if_not_exists,
767 column_def,
768 column_position,
769 } => {
770 write!(f, "ADD")?;
771 if *column_keyword {
772 write!(f, " COLUMN")?;
773 }
774 if *if_not_exists {
775 write!(f, " IF NOT EXISTS")?;
776 }
777 write!(f, " {column_def}")?;
778
779 if let Some(position) = column_position {
780 write!(f, " {position}")?;
781 }
782
783 Ok(())
784 }
785 AlterTableOperation::AddProjection {
786 if_not_exists,
787 name,
788 select: query,
789 } => {
790 write!(f, "ADD PROJECTION")?;
791 if *if_not_exists {
792 write!(f, " IF NOT EXISTS")?;
793 }
794 write!(f, " {name} ({query})")
795 }
796 AlterTableOperation::Algorithm { equals, algorithm } => {
797 write!(
798 f,
799 "ALGORITHM {}{}",
800 if *equals { "= " } else { "" },
801 algorithm
802 )
803 }
804 AlterTableOperation::DropProjection { if_exists, name } => {
805 write!(f, "DROP PROJECTION")?;
806 if *if_exists {
807 write!(f, " IF EXISTS")?;
808 }
809 write!(f, " {name}")
810 }
811 AlterTableOperation::MaterializeProjection {
812 if_exists,
813 name,
814 partition,
815 } => {
816 write!(f, "MATERIALIZE PROJECTION")?;
817 if *if_exists {
818 write!(f, " IF EXISTS")?;
819 }
820 write!(f, " {name}")?;
821 if let Some(partition) = partition {
822 write!(f, " IN PARTITION {partition}")?;
823 }
824 Ok(())
825 }
826 AlterTableOperation::ClearProjection {
827 if_exists,
828 name,
829 partition,
830 } => {
831 write!(f, "CLEAR PROJECTION")?;
832 if *if_exists {
833 write!(f, " IF EXISTS")?;
834 }
835 write!(f, " {name}")?;
836 if let Some(partition) = partition {
837 write!(f, " IN PARTITION {partition}")?;
838 }
839 Ok(())
840 }
841 AlterTableOperation::AlterColumn { column_name, op } => {
842 write!(f, "ALTER COLUMN {column_name} {op}")
843 }
844 AlterTableOperation::DisableRowLevelSecurity => {
845 write!(f, "DISABLE ROW LEVEL SECURITY")
846 }
847 AlterTableOperation::DisableRule { name } => {
848 write!(f, "DISABLE RULE {name}")
849 }
850 AlterTableOperation::DisableTrigger { name } => {
851 write!(f, "DISABLE TRIGGER {name}")
852 }
853 AlterTableOperation::DropPartitions {
854 partitions,
855 if_exists,
856 } => write!(
857 f,
858 "DROP{ie} PARTITION ({})",
859 display_comma_separated(partitions),
860 ie = if *if_exists { " IF EXISTS" } else { "" }
861 ),
862 AlterTableOperation::DropConstraint {
863 if_exists,
864 name,
865 drop_behavior,
866 } => {
867 write!(
868 f,
869 "DROP CONSTRAINT {}{}",
870 if *if_exists { "IF EXISTS " } else { "" },
871 name
872 )?;
873 if let Some(drop_behavior) = drop_behavior {
874 write!(f, " {drop_behavior}")?;
875 }
876 Ok(())
877 }
878 AlterTableOperation::DropPrimaryKey { drop_behavior } => {
879 write!(f, "DROP PRIMARY KEY")?;
880 if let Some(drop_behavior) = drop_behavior {
881 write!(f, " {drop_behavior}")?;
882 }
883 Ok(())
884 }
885 AlterTableOperation::DropForeignKey {
886 name,
887 drop_behavior,
888 } => {
889 write!(f, "DROP FOREIGN KEY {name}")?;
890 if let Some(drop_behavior) = drop_behavior {
891 write!(f, " {drop_behavior}")?;
892 }
893 Ok(())
894 }
895 AlterTableOperation::DropIndex { name } => write!(f, "DROP INDEX {name}"),
896 AlterTableOperation::DropColumn {
897 has_column_keyword,
898 column_names: column_name,
899 if_exists,
900 drop_behavior,
901 } => {
902 write!(
903 f,
904 "DROP {}{}{}",
905 if *has_column_keyword { "COLUMN " } else { "" },
906 if *if_exists { "IF EXISTS " } else { "" },
907 display_comma_separated(column_name),
908 )?;
909 if let Some(drop_behavior) = drop_behavior {
910 write!(f, " {drop_behavior}")?;
911 }
912 Ok(())
913 }
914 AlterTableOperation::AttachPartition { partition } => {
915 write!(f, "ATTACH {partition}")
916 }
917 AlterTableOperation::DetachPartition { partition } => {
918 write!(f, "DETACH {partition}")
919 }
920 AlterTableOperation::AttachPartitionOf {
921 partition_name,
922 partition_bound,
923 } => {
924 write!(f, "ATTACH PARTITION {partition_name} {partition_bound}")
925 }
926 AlterTableOperation::DetachPartitionOf {
927 partition_name,
928 concurrently,
929 finalize,
930 } => {
931 write!(f, "DETACH PARTITION {partition_name}")?;
932 if *concurrently {
933 write!(f, " CONCURRENTLY")?;
934 }
935 if *finalize {
936 write!(f, " FINALIZE")?;
937 }
938 Ok(())
939 }
940 AlterTableOperation::EnableAlwaysRule { name } => {
941 write!(f, "ENABLE ALWAYS RULE {name}")
942 }
943 AlterTableOperation::EnableAlwaysTrigger { name } => {
944 write!(f, "ENABLE ALWAYS TRIGGER {name}")
945 }
946 AlterTableOperation::EnableReplicaRule { name } => {
947 write!(f, "ENABLE REPLICA RULE {name}")
948 }
949 AlterTableOperation::EnableReplicaTrigger { name } => {
950 write!(f, "ENABLE REPLICA TRIGGER {name}")
951 }
952 AlterTableOperation::EnableRowLevelSecurity => {
953 write!(f, "ENABLE ROW LEVEL SECURITY")
954 }
955 AlterTableOperation::ForceRowLevelSecurity => {
956 write!(f, "FORCE ROW LEVEL SECURITY")
957 }
958 AlterTableOperation::NoForceRowLevelSecurity => {
959 write!(f, "NO FORCE ROW LEVEL SECURITY")
960 }
961 AlterTableOperation::EnableRule { name } => {
962 write!(f, "ENABLE RULE {name}")
963 }
964 AlterTableOperation::EnableTrigger { name } => {
965 write!(f, "ENABLE TRIGGER {name}")
966 }
967 AlterTableOperation::RenamePartitions {
968 old_partitions,
969 new_partitions,
970 } => write!(
971 f,
972 "PARTITION ({}) RENAME TO PARTITION ({})",
973 display_comma_separated(old_partitions),
974 display_comma_separated(new_partitions)
975 ),
976 AlterTableOperation::RenameColumn {
977 old_column_name,
978 new_column_name,
979 } => write!(f, "RENAME COLUMN {old_column_name} TO {new_column_name}"),
980 AlterTableOperation::RenameTable { table_name } => {
981 write!(f, "RENAME {table_name}")
982 }
983 AlterTableOperation::ChangeColumn {
984 old_name,
985 new_name,
986 data_type,
987 options,
988 column_position,
989 } => {
990 write!(f, "CHANGE COLUMN {old_name} {new_name} {data_type}")?;
991 if !options.is_empty() {
992 write!(f, " {}", display_separated(options, " "))?;
993 }
994 if let Some(position) = column_position {
995 write!(f, " {position}")?;
996 }
997
998 Ok(())
999 }
1000 AlterTableOperation::ModifyColumn {
1001 col_name,
1002 data_type,
1003 options,
1004 column_position,
1005 } => {
1006 write!(f, "MODIFY COLUMN {col_name} {data_type}")?;
1007 if !options.is_empty() {
1008 write!(f, " {}", display_separated(options, " "))?;
1009 }
1010 if let Some(position) = column_position {
1011 write!(f, " {position}")?;
1012 }
1013
1014 Ok(())
1015 }
1016 AlterTableOperation::RenameConstraint { old_name, new_name } => {
1017 write!(f, "RENAME CONSTRAINT {old_name} TO {new_name}")
1018 }
1019 AlterTableOperation::SwapWith { table_name } => {
1020 write!(f, "SWAP WITH {table_name}")
1021 }
1022 AlterTableOperation::OwnerTo { new_owner } => {
1023 write!(f, "OWNER TO {new_owner}")
1024 }
1025 AlterTableOperation::SetTblProperties { table_properties } => {
1026 write!(
1027 f,
1028 "SET TBLPROPERTIES({})",
1029 display_comma_separated(table_properties)
1030 )
1031 }
1032 AlterTableOperation::FreezePartition {
1033 partition,
1034 with_name,
1035 } => {
1036 write!(f, "FREEZE {partition}")?;
1037 if let Some(name) = with_name {
1038 write!(f, " WITH NAME {name}")?;
1039 }
1040 Ok(())
1041 }
1042 AlterTableOperation::UnfreezePartition {
1043 partition,
1044 with_name,
1045 } => {
1046 write!(f, "UNFREEZE {partition}")?;
1047 if let Some(name) = with_name {
1048 write!(f, " WITH NAME {name}")?;
1049 }
1050 Ok(())
1051 }
1052 AlterTableOperation::ClusterBy { exprs } => {
1053 write!(f, "CLUSTER BY ({})", display_comma_separated(exprs))?;
1054 Ok(())
1055 }
1056 AlterTableOperation::DropClusteringKey => {
1057 write!(f, "DROP CLUSTERING KEY")?;
1058 Ok(())
1059 }
1060 AlterTableOperation::AlterSortKey { columns } => {
1061 write!(f, "ALTER SORTKEY({})", display_comma_separated(columns))?;
1062 Ok(())
1063 }
1064 AlterTableOperation::SuspendRecluster => {
1065 write!(f, "SUSPEND RECLUSTER")?;
1066 Ok(())
1067 }
1068 AlterTableOperation::ResumeRecluster => {
1069 write!(f, "RESUME RECLUSTER")?;
1070 Ok(())
1071 }
1072 AlterTableOperation::Refresh { subpath } => {
1073 write!(f, "REFRESH")?;
1074 if let Some(path) = subpath {
1075 write!(f, " '{path}'")?;
1076 }
1077 Ok(())
1078 }
1079 AlterTableOperation::Suspend => {
1080 write!(f, "SUSPEND")
1081 }
1082 AlterTableOperation::Resume => {
1083 write!(f, "RESUME")
1084 }
1085 AlterTableOperation::AutoIncrement { equals, value } => {
1086 write!(
1087 f,
1088 "AUTO_INCREMENT {}{}",
1089 if *equals { "= " } else { "" },
1090 value
1091 )
1092 }
1093 AlterTableOperation::Lock { equals, lock } => {
1094 write!(f, "LOCK {}{}", if *equals { "= " } else { "" }, lock)
1095 }
1096 AlterTableOperation::ReplicaIdentity { identity } => {
1097 write!(f, "REPLICA IDENTITY {identity}")
1098 }
1099 AlterTableOperation::ValidateConstraint { name } => {
1100 write!(f, "VALIDATE CONSTRAINT {name}")
1101 }
1102 AlterTableOperation::SetOptionsParens { options } => {
1103 write!(f, "SET ({})", display_comma_separated(options))
1104 }
1105 AlterTableOperation::SetTablespace { tablespace_name } => {
1106 write!(f, "SET TABLESPACE {tablespace_name}")
1107 }
1108 }
1109 }
1110}
1111
1112impl fmt::Display for AlterIndexOperation {
1113 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1114 match self {
1115 AlterIndexOperation::RenameIndex { index_name } => {
1116 write!(f, "RENAME TO {index_name}")
1117 }
1118 AlterIndexOperation::SetTablespace { tablespace_name } => {
1119 write!(f, "SET TABLESPACE {tablespace_name}")
1120 }
1121 }
1122 }
1123}
1124
1125#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1127#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1128#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1129pub struct AlterType {
1130 pub name: ObjectName,
1132 pub operation: AlterTypeOperation,
1134}
1135
1136#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1138#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1139#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1140pub enum AlterTypeOperation {
1141 Rename(AlterTypeRename),
1143 AddValue(AlterTypeAddValue),
1145 RenameValue(AlterTypeRenameValue),
1147 OwnerTo {
1153 new_owner: Owner,
1155 },
1156 SetSchema {
1162 new_schema: ObjectName,
1164 },
1165 AddAttribute {
1172 name: Ident,
1174 data_type: DataType,
1176 collation: Option<ObjectName>,
1178 drop_behavior: Option<DropBehavior>,
1180 },
1181 DropAttribute {
1187 if_exists: bool,
1189 name: Ident,
1191 drop_behavior: Option<DropBehavior>,
1193 },
1194 AlterAttribute {
1201 name: Ident,
1203 data_type: DataType,
1205 collation: Option<ObjectName>,
1207 drop_behavior: Option<DropBehavior>,
1209 },
1210 RenameAttribute {
1216 old_name: Ident,
1218 new_name: Ident,
1220 drop_behavior: Option<DropBehavior>,
1222 },
1223}
1224
1225#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1227#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1228#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1229pub struct AlterTypeRename {
1230 pub new_name: Ident,
1232}
1233
1234#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1236#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1237#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1238pub struct AlterTypeAddValue {
1239 pub if_not_exists: bool,
1241 pub value: Ident,
1243 pub position: Option<AlterTypeAddValuePosition>,
1245}
1246
1247#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1249#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1250#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1251pub enum AlterTypeAddValuePosition {
1252 Before(Ident),
1254 After(Ident),
1256}
1257
1258#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1260#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1261#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1262pub struct AlterTypeRenameValue {
1263 pub from: Ident,
1265 pub to: Ident,
1267}
1268
1269impl fmt::Display for AlterTypeOperation {
1270 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1271 match self {
1272 Self::Rename(AlterTypeRename { new_name }) => {
1273 write!(f, "RENAME TO {new_name}")
1274 }
1275 Self::AddValue(AlterTypeAddValue {
1276 if_not_exists,
1277 value,
1278 position,
1279 }) => {
1280 write!(f, "ADD VALUE")?;
1281 if *if_not_exists {
1282 write!(f, " IF NOT EXISTS")?;
1283 }
1284 write!(f, " {value}")?;
1285 match position {
1286 Some(AlterTypeAddValuePosition::Before(neighbor_value)) => {
1287 write!(f, " BEFORE {neighbor_value}")?;
1288 }
1289 Some(AlterTypeAddValuePosition::After(neighbor_value)) => {
1290 write!(f, " AFTER {neighbor_value}")?;
1291 }
1292 None => {}
1293 };
1294 Ok(())
1295 }
1296 Self::RenameValue(AlterTypeRenameValue { from, to }) => {
1297 write!(f, "RENAME VALUE {from} TO {to}")
1298 }
1299 Self::OwnerTo { new_owner } => {
1300 write!(f, "OWNER TO {new_owner}")
1301 }
1302 Self::SetSchema { new_schema } => {
1303 write!(f, "SET SCHEMA {new_schema}")
1304 }
1305 Self::AddAttribute {
1306 name,
1307 data_type,
1308 collation,
1309 drop_behavior,
1310 } => {
1311 write!(f, "ADD ATTRIBUTE {name} {data_type}")?;
1312 if let Some(collation) = collation {
1313 write!(f, " COLLATE {collation}")?;
1314 }
1315 if let Some(drop_behavior) = drop_behavior {
1316 write!(f, " {drop_behavior}")?;
1317 }
1318 Ok(())
1319 }
1320 Self::DropAttribute {
1321 if_exists,
1322 name,
1323 drop_behavior,
1324 } => {
1325 write!(f, "DROP ATTRIBUTE")?;
1326 if *if_exists {
1327 write!(f, " IF EXISTS")?;
1328 }
1329 write!(f, " {name}")?;
1330 if let Some(drop_behavior) = drop_behavior {
1331 write!(f, " {drop_behavior}")?;
1332 }
1333 Ok(())
1334 }
1335 Self::AlterAttribute {
1336 name,
1337 data_type,
1338 collation,
1339 drop_behavior,
1340 } => {
1341 write!(f, "ALTER ATTRIBUTE {name} SET DATA TYPE {data_type}")?;
1342 if let Some(collation) = collation {
1343 write!(f, " COLLATE {collation}")?;
1344 }
1345 if let Some(drop_behavior) = drop_behavior {
1346 write!(f, " {drop_behavior}")?;
1347 }
1348 Ok(())
1349 }
1350 Self::RenameAttribute {
1351 old_name,
1352 new_name,
1353 drop_behavior,
1354 } => {
1355 write!(f, "RENAME ATTRIBUTE {old_name} TO {new_name}")?;
1356 if let Some(drop_behavior) = drop_behavior {
1357 write!(f, " {drop_behavior}")?;
1358 }
1359 Ok(())
1360 }
1361 }
1362 }
1363}
1364
1365#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1368#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1369#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1370pub struct AlterOperator {
1371 pub name: ObjectName,
1373 pub left_type: Option<DataType>,
1375 pub right_type: DataType,
1377 pub operation: AlterOperatorOperation,
1379}
1380
1381#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1383#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1384#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1385pub enum AlterOperatorOperation {
1386 OwnerTo(Owner),
1388 SetSchema {
1391 schema_name: ObjectName,
1393 },
1394 Set {
1396 options: Vec<OperatorOption>,
1398 },
1399}
1400
1401#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1403#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1404#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1405pub enum OperatorOption {
1406 Restrict(Option<ObjectName>),
1408 Join(Option<ObjectName>),
1410 Commutator(ObjectName),
1412 Negator(ObjectName),
1414 Hashes,
1416 Merges,
1418}
1419
1420impl fmt::Display for AlterOperator {
1421 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1422 write!(f, "ALTER OPERATOR {} (", self.name)?;
1423 if let Some(left_type) = &self.left_type {
1424 write!(f, "{}", left_type)?;
1425 } else {
1426 write!(f, "NONE")?;
1427 }
1428 write!(f, ", {}) {}", self.right_type, self.operation)
1429 }
1430}
1431
1432impl fmt::Display for AlterOperatorOperation {
1433 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1434 match self {
1435 Self::OwnerTo(owner) => write!(f, "OWNER TO {}", owner),
1436 Self::SetSchema { schema_name } => write!(f, "SET SCHEMA {}", schema_name),
1437 Self::Set { options } => {
1438 write!(f, "SET (")?;
1439 for (i, option) in options.iter().enumerate() {
1440 if i > 0 {
1441 write!(f, ", ")?;
1442 }
1443 write!(f, "{}", option)?;
1444 }
1445 write!(f, ")")
1446 }
1447 }
1448 }
1449}
1450
1451impl fmt::Display for OperatorOption {
1452 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1453 match self {
1454 Self::Restrict(Some(proc_name)) => write!(f, "RESTRICT = {}", proc_name),
1455 Self::Restrict(None) => write!(f, "RESTRICT = NONE"),
1456 Self::Join(Some(proc_name)) => write!(f, "JOIN = {}", proc_name),
1457 Self::Join(None) => write!(f, "JOIN = NONE"),
1458 Self::Commutator(op_name) => write!(f, "COMMUTATOR = {}", op_name),
1459 Self::Negator(op_name) => write!(f, "NEGATOR = {}", op_name),
1460 Self::Hashes => write!(f, "HASHES"),
1461 Self::Merges => write!(f, "MERGES"),
1462 }
1463 }
1464}
1465
1466#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1468#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1469#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1470pub enum AlterColumnOperation {
1471 SetNotNull,
1473 DropNotNull,
1475 SetDefault {
1478 value: Expr,
1480 },
1481 DropDefault,
1483 SetDataType {
1485 data_type: DataType,
1487 using: Option<Expr>,
1489 had_set: bool,
1491 },
1492
1493 AddGenerated {
1497 generated_as: Option<GeneratedAs>,
1499 sequence_options: Option<Vec<SequenceOptions>>,
1501 },
1502}
1503
1504impl fmt::Display for AlterColumnOperation {
1505 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1506 match self {
1507 AlterColumnOperation::SetNotNull => write!(f, "SET NOT NULL",),
1508 AlterColumnOperation::DropNotNull => write!(f, "DROP NOT NULL",),
1509 AlterColumnOperation::SetDefault { value } => {
1510 write!(f, "SET DEFAULT {value}")
1511 }
1512 AlterColumnOperation::DropDefault => {
1513 write!(f, "DROP DEFAULT")
1514 }
1515 AlterColumnOperation::SetDataType {
1516 data_type,
1517 using,
1518 had_set,
1519 } => {
1520 if *had_set {
1521 write!(f, "SET DATA ")?;
1522 }
1523 write!(f, "TYPE {data_type}")?;
1524 if let Some(expr) = using {
1525 write!(f, " USING {expr}")?;
1526 }
1527 Ok(())
1528 }
1529 AlterColumnOperation::AddGenerated {
1530 generated_as,
1531 sequence_options,
1532 } => {
1533 let generated_as = match generated_as {
1534 Some(GeneratedAs::Always) => " ALWAYS",
1535 Some(GeneratedAs::ByDefault) => " BY DEFAULT",
1536 _ => "",
1537 };
1538
1539 write!(f, "ADD GENERATED{generated_as} AS IDENTITY",)?;
1540 if let Some(options) = sequence_options {
1541 write!(f, " (")?;
1542
1543 for sequence_option in options {
1544 write!(f, "{sequence_option}")?;
1545 }
1546
1547 write!(f, " )")?;
1548 }
1549 Ok(())
1550 }
1551 }
1552 }
1553}
1554
1555#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1563#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1564#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1565pub enum KeyOrIndexDisplay {
1566 None,
1568 Key,
1570 Index,
1572}
1573
1574impl KeyOrIndexDisplay {
1575 pub fn is_none(self) -> bool {
1577 matches!(self, Self::None)
1578 }
1579}
1580
1581impl fmt::Display for KeyOrIndexDisplay {
1582 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1583 let left_space = matches!(f.align(), Some(fmt::Alignment::Right));
1584
1585 if left_space && !self.is_none() {
1586 f.write_char(' ')?
1587 }
1588
1589 match self {
1590 KeyOrIndexDisplay::None => {
1591 write!(f, "")
1592 }
1593 KeyOrIndexDisplay::Key => {
1594 write!(f, "KEY")
1595 }
1596 KeyOrIndexDisplay::Index => {
1597 write!(f, "INDEX")
1598 }
1599 }
1600 }
1601}
1602
1603#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1612#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1613#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1614pub enum IndexType {
1615 BTree,
1617 Hash,
1619 GIN,
1621 GiST,
1623 SPGiST,
1625 BRIN,
1627 Bloom,
1629 Custom(Ident),
1632}
1633
1634impl fmt::Display for IndexType {
1635 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1636 match self {
1637 Self::BTree => write!(f, "BTREE"),
1638 Self::Hash => write!(f, "HASH"),
1639 Self::GIN => write!(f, "GIN"),
1640 Self::GiST => write!(f, "GIST"),
1641 Self::SPGiST => write!(f, "SPGIST"),
1642 Self::BRIN => write!(f, "BRIN"),
1643 Self::Bloom => write!(f, "BLOOM"),
1644 Self::Custom(name) => write!(f, "{name}"),
1645 }
1646 }
1647}
1648
1649#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1655#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1656#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1657pub enum IndexOption {
1658 Using(IndexType),
1662 Comment(String),
1664}
1665
1666impl fmt::Display for IndexOption {
1667 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1668 match self {
1669 Self::Using(index_type) => write!(f, "USING {index_type}"),
1670 Self::Comment(s) => write!(f, "COMMENT '{s}'"),
1671 }
1672 }
1673}
1674
1675#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
1679#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1680#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1681pub enum NullsDistinctOption {
1682 None,
1684 Distinct,
1686 NotDistinct,
1688}
1689
1690impl fmt::Display for NullsDistinctOption {
1691 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1692 match self {
1693 Self::None => Ok(()),
1694 Self::Distinct => write!(f, " NULLS DISTINCT"),
1695 Self::NotDistinct => write!(f, " NULLS NOT DISTINCT"),
1696 }
1697 }
1698}
1699
1700#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1701#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1702#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1703pub struct ProcedureParam {
1705 pub name: Ident,
1707 pub data_type: DataType,
1709 pub mode: Option<ArgMode>,
1711 pub default: Option<Expr>,
1713}
1714
1715impl fmt::Display for ProcedureParam {
1716 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1717 if let Some(mode) = &self.mode {
1718 if let Some(default) = &self.default {
1719 write!(f, "{mode} {} {} = {}", self.name, self.data_type, default)
1720 } else {
1721 write!(f, "{mode} {} {}", self.name, self.data_type)
1722 }
1723 } else if let Some(default) = &self.default {
1724 write!(f, "{} {} = {}", self.name, self.data_type, default)
1725 } else {
1726 write!(f, "{} {}", self.name, self.data_type)
1727 }
1728 }
1729}
1730
1731#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1733#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1734#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1735pub struct ColumnDef {
1736 pub name: Ident,
1738 pub data_type: DataType,
1740 pub options: Vec<ColumnOptionDef>,
1742}
1743
1744impl fmt::Display for ColumnDef {
1745 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1746 if self.data_type == DataType::Unspecified {
1747 write!(f, "{}", self.name)?;
1748 } else {
1749 write!(f, "{} {}", self.name, self.data_type)?;
1750 }
1751 for option in &self.options {
1752 write!(f, " {option}")?;
1753 }
1754 Ok(())
1755 }
1756}
1757
1758#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1775#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1776#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1777pub struct ViewColumnDef {
1778 pub name: Ident,
1780 pub data_type: Option<DataType>,
1782 pub options: Option<ColumnOptions>,
1784}
1785
1786#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1787#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1788#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1789pub enum ColumnOptions {
1791 CommaSeparated(Vec<ColumnOption>),
1793 SpaceSeparated(Vec<ColumnOption>),
1795}
1796
1797impl ColumnOptions {
1798 pub fn as_slice(&self) -> &[ColumnOption] {
1800 match self {
1801 ColumnOptions::CommaSeparated(options) => options.as_slice(),
1802 ColumnOptions::SpaceSeparated(options) => options.as_slice(),
1803 }
1804 }
1805}
1806
1807impl fmt::Display for ViewColumnDef {
1808 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1809 write!(f, "{}", self.name)?;
1810 if let Some(data_type) = self.data_type.as_ref() {
1811 write!(f, " {data_type}")?;
1812 }
1813 if let Some(options) = self.options.as_ref() {
1814 match options {
1815 ColumnOptions::CommaSeparated(column_options) => {
1816 write!(f, " {}", display_comma_separated(column_options.as_slice()))?;
1817 }
1818 ColumnOptions::SpaceSeparated(column_options) => {
1819 write!(f, " {}", display_separated(column_options.as_slice(), " "))?
1820 }
1821 }
1822 }
1823 Ok(())
1824 }
1825}
1826
1827#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1844#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1845#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1846pub struct ColumnOptionDef {
1847 pub name: Option<Ident>,
1849 pub option: ColumnOption,
1851}
1852
1853impl fmt::Display for ColumnOptionDef {
1854 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1855 write!(f, "{}{}", display_constraint_name(&self.name), self.option)
1856 }
1857}
1858
1859#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1867#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1868#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1869pub enum IdentityPropertyKind {
1870 Autoincrement(IdentityProperty),
1878 Identity(IdentityProperty),
1891}
1892
1893impl fmt::Display for IdentityPropertyKind {
1894 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1895 let (command, property) = match self {
1896 IdentityPropertyKind::Identity(property) => ("IDENTITY", property),
1897 IdentityPropertyKind::Autoincrement(property) => ("AUTOINCREMENT", property),
1898 };
1899 write!(f, "{command}")?;
1900 if let Some(parameters) = &property.parameters {
1901 write!(f, "{parameters}")?;
1902 }
1903 if let Some(order) = &property.order {
1904 write!(f, "{order}")?;
1905 }
1906 Ok(())
1907 }
1908}
1909
1910#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1912#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1913#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1914pub struct IdentityProperty {
1915 pub parameters: Option<IdentityPropertyFormatKind>,
1917 pub order: Option<IdentityPropertyOrder>,
1919}
1920
1921#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1936#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1937#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1938pub enum IdentityPropertyFormatKind {
1939 FunctionCall(IdentityParameters),
1947 StartAndIncrement(IdentityParameters),
1954}
1955
1956impl fmt::Display for IdentityPropertyFormatKind {
1957 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1958 match self {
1959 IdentityPropertyFormatKind::FunctionCall(parameters) => {
1960 write!(f, "({}, {})", parameters.seed, parameters.increment)
1961 }
1962 IdentityPropertyFormatKind::StartAndIncrement(parameters) => {
1963 write!(
1964 f,
1965 " START {} INCREMENT {}",
1966 parameters.seed, parameters.increment
1967 )
1968 }
1969 }
1970 }
1971}
1972#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
1974#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1975#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1976pub struct IdentityParameters {
1977 pub seed: Expr,
1979 pub increment: Expr,
1981}
1982
1983#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
1990#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1991#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
1992pub enum IdentityPropertyOrder {
1993 Order,
1995 NoOrder,
1997}
1998
1999impl fmt::Display for IdentityPropertyOrder {
2000 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2001 match self {
2002 IdentityPropertyOrder::Order => write!(f, " ORDER"),
2003 IdentityPropertyOrder::NoOrder => write!(f, " NOORDER"),
2004 }
2005 }
2006}
2007
2008#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2016#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2017#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2018pub enum ColumnPolicy {
2019 MaskingPolicy(ColumnPolicyProperty),
2021 ProjectionPolicy(ColumnPolicyProperty),
2023}
2024
2025impl fmt::Display for ColumnPolicy {
2026 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2027 let (command, property) = match self {
2028 ColumnPolicy::MaskingPolicy(property) => ("MASKING POLICY", property),
2029 ColumnPolicy::ProjectionPolicy(property) => ("PROJECTION POLICY", property),
2030 };
2031 if property.with {
2032 write!(f, "WITH ")?;
2033 }
2034 write!(f, "{command} {}", property.policy_name)?;
2035 if let Some(using_columns) = &property.using_columns {
2036 write!(f, " USING ({})", display_comma_separated(using_columns))?;
2037 }
2038 Ok(())
2039 }
2040}
2041
2042#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2043#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2044#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2045pub struct ColumnPolicyProperty {
2047 pub with: bool,
2054 pub policy_name: ObjectName,
2056 pub using_columns: Option<Vec<Ident>>,
2058}
2059
2060#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2067#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2068#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2069pub struct TagsColumnOption {
2070 pub with: bool,
2077 pub tags: Vec<Tag>,
2079}
2080
2081impl fmt::Display for TagsColumnOption {
2082 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2083 if self.with {
2084 write!(f, "WITH ")?;
2085 }
2086 write!(f, "TAG ({})", display_comma_separated(&self.tags))?;
2087 Ok(())
2088 }
2089}
2090
2091#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2094#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2095#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2096pub enum ColumnOption {
2097 Null,
2099 NotNull,
2101 Default(Expr),
2103
2104 Materialized(Expr),
2109 Ephemeral(Option<Expr>),
2113 Alias(Expr),
2117
2118 PrimaryKey(PrimaryKeyConstraint),
2120 Unique(UniqueConstraint),
2122 ForeignKey(ForeignKeyConstraint),
2130 Check(CheckConstraint),
2132 DialectSpecific(Vec<Token>),
2136 CharacterSet(ObjectName),
2138 Collation(ObjectName),
2140 Comment(String),
2142 OnUpdate(Expr),
2144 Generated {
2147 generated_as: GeneratedAs,
2149 sequence_options: Option<Vec<SequenceOptions>>,
2151 generation_expr: Option<Expr>,
2153 generation_expr_mode: Option<GeneratedExpressionMode>,
2155 generated_keyword: bool,
2157 },
2158 Options(Vec<SqlOption>),
2166 Identity(IdentityPropertyKind),
2174 OnConflict(Keyword),
2177 Policy(ColumnPolicy),
2185 Tags(TagsColumnOption),
2192 Srid(Box<Expr>),
2199 Invisible,
2206}
2207
2208impl From<UniqueConstraint> for ColumnOption {
2209 fn from(c: UniqueConstraint) -> Self {
2210 ColumnOption::Unique(c)
2211 }
2212}
2213
2214impl From<PrimaryKeyConstraint> for ColumnOption {
2215 fn from(c: PrimaryKeyConstraint) -> Self {
2216 ColumnOption::PrimaryKey(c)
2217 }
2218}
2219
2220impl From<CheckConstraint> for ColumnOption {
2221 fn from(c: CheckConstraint) -> Self {
2222 ColumnOption::Check(c)
2223 }
2224}
2225impl From<ForeignKeyConstraint> for ColumnOption {
2226 fn from(fk: ForeignKeyConstraint) -> Self {
2227 ColumnOption::ForeignKey(fk)
2228 }
2229}
2230
2231impl fmt::Display for ColumnOption {
2232 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2233 use ColumnOption::*;
2234 match self {
2235 Null => write!(f, "NULL"),
2236 NotNull => write!(f, "NOT NULL"),
2237 Default(expr) => write!(f, "DEFAULT {expr}"),
2238 Materialized(expr) => write!(f, "MATERIALIZED {expr}"),
2239 Ephemeral(expr) => {
2240 if let Some(e) = expr {
2241 write!(f, "EPHEMERAL {e}")
2242 } else {
2243 write!(f, "EPHEMERAL")
2244 }
2245 }
2246 Alias(expr) => write!(f, "ALIAS {expr}"),
2247 PrimaryKey(constraint) => {
2248 write!(f, "PRIMARY KEY")?;
2249 if let Some(characteristics) = &constraint.characteristics {
2250 write!(f, " {characteristics}")?;
2251 }
2252 Ok(())
2253 }
2254 Unique(constraint) => {
2255 write!(f, "UNIQUE{:>}", constraint.index_type_display)?;
2256 if let Some(characteristics) = &constraint.characteristics {
2257 write!(f, " {characteristics}")?;
2258 }
2259 Ok(())
2260 }
2261 ForeignKey(constraint) => {
2262 write!(f, "REFERENCES {}", constraint.foreign_table)?;
2263 if !constraint.referred_columns.is_empty() {
2264 write!(
2265 f,
2266 " ({})",
2267 display_comma_separated(&constraint.referred_columns)
2268 )?;
2269 }
2270 if let Some(match_kind) = &constraint.match_kind {
2271 write!(f, " {match_kind}")?;
2272 }
2273 if let Some(action) = &constraint.on_delete {
2274 write!(f, " ON DELETE {action}")?;
2275 }
2276 if let Some(action) = &constraint.on_update {
2277 write!(f, " ON UPDATE {action}")?;
2278 }
2279 if let Some(characteristics) = &constraint.characteristics {
2280 write!(f, " {characteristics}")?;
2281 }
2282 Ok(())
2283 }
2284 Check(constraint) => write!(f, "{constraint}"),
2285 DialectSpecific(val) => write!(f, "{}", display_separated(val, " ")),
2286 CharacterSet(n) => write!(f, "CHARACTER SET {n}"),
2287 Collation(n) => write!(f, "COLLATE {n}"),
2288 Comment(v) => write!(f, "COMMENT '{}'", escape_single_quote_string(v)),
2289 OnUpdate(expr) => write!(f, "ON UPDATE {expr}"),
2290 Generated {
2291 generated_as,
2292 sequence_options,
2293 generation_expr,
2294 generation_expr_mode,
2295 generated_keyword,
2296 } => {
2297 if let Some(expr) = generation_expr {
2298 let modifier = match generation_expr_mode {
2299 None => "",
2300 Some(GeneratedExpressionMode::Virtual) => " VIRTUAL",
2301 Some(GeneratedExpressionMode::Stored) => " STORED",
2302 };
2303 if *generated_keyword {
2304 write!(f, "GENERATED ALWAYS AS ({expr}){modifier}")?;
2305 } else {
2306 write!(f, "AS ({expr}){modifier}")?;
2307 }
2308 Ok(())
2309 } else {
2310 let when = match generated_as {
2312 GeneratedAs::Always => "ALWAYS",
2313 GeneratedAs::ByDefault => "BY DEFAULT",
2314 GeneratedAs::ExpStored => "",
2316 };
2317 write!(f, "GENERATED {when} AS IDENTITY")?;
2318 if sequence_options.is_some() {
2319 let so = sequence_options.as_ref().unwrap();
2320 if !so.is_empty() {
2321 write!(f, " (")?;
2322 }
2323 for sequence_option in so {
2324 write!(f, "{sequence_option}")?;
2325 }
2326 if !so.is_empty() {
2327 write!(f, " )")?;
2328 }
2329 }
2330 Ok(())
2331 }
2332 }
2333 Options(options) => {
2334 write!(f, "OPTIONS({})", display_comma_separated(options))
2335 }
2336 Identity(parameters) => {
2337 write!(f, "{parameters}")
2338 }
2339 OnConflict(keyword) => {
2340 write!(f, "ON CONFLICT {keyword:?}")?;
2341 Ok(())
2342 }
2343 Policy(parameters) => {
2344 write!(f, "{parameters}")
2345 }
2346 Tags(tags) => {
2347 write!(f, "{tags}")
2348 }
2349 Srid(srid) => {
2350 write!(f, "SRID {srid}")
2351 }
2352 Invisible => {
2353 write!(f, "INVISIBLE")
2354 }
2355 }
2356 }
2357}
2358
2359#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
2362#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2363#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2364pub enum GeneratedAs {
2365 Always,
2367 ByDefault,
2369 ExpStored,
2371}
2372
2373#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
2376#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2377#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2378pub enum GeneratedExpressionMode {
2379 Virtual,
2381 Stored,
2383}
2384
2385#[must_use]
2386pub(crate) fn display_constraint_name(name: &'_ Option<Ident>) -> impl fmt::Display + '_ {
2387 struct ConstraintName<'a>(&'a Option<Ident>);
2388 impl fmt::Display for ConstraintName<'_> {
2389 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2390 if let Some(name) = self.0 {
2391 write!(f, "CONSTRAINT {name} ")?;
2392 }
2393 Ok(())
2394 }
2395 }
2396 ConstraintName(name)
2397}
2398
2399#[must_use]
2403pub(crate) fn display_option<'a, T: fmt::Display>(
2404 prefix: &'a str,
2405 postfix: &'a str,
2406 option: &'a Option<T>,
2407) -> impl fmt::Display + 'a {
2408 struct OptionDisplay<'a, T>(&'a str, &'a str, &'a Option<T>);
2409 impl<T: fmt::Display> fmt::Display for OptionDisplay<'_, T> {
2410 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2411 if let Some(inner) = self.2 {
2412 let (prefix, postfix) = (self.0, self.1);
2413 write!(f, "{prefix}{inner}{postfix}")?;
2414 }
2415 Ok(())
2416 }
2417 }
2418 OptionDisplay(prefix, postfix, option)
2419}
2420
2421#[must_use]
2425pub(crate) fn display_option_spaced<T: fmt::Display>(option: &Option<T>) -> impl fmt::Display + '_ {
2426 display_option(" ", "", option)
2427}
2428
2429#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Default, Eq, Ord, Hash)]
2433#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2434#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2435pub struct ConstraintCharacteristics {
2436 pub deferrable: Option<bool>,
2438 pub initially: Option<DeferrableInitial>,
2440 pub enforced: Option<bool>,
2442}
2443
2444#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2446#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2447#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2448pub enum DeferrableInitial {
2449 Immediate,
2451 Deferred,
2453}
2454
2455impl ConstraintCharacteristics {
2456 fn deferrable_text(&self) -> Option<&'static str> {
2457 self.deferrable.map(|deferrable| {
2458 if deferrable {
2459 "DEFERRABLE"
2460 } else {
2461 "NOT DEFERRABLE"
2462 }
2463 })
2464 }
2465
2466 fn initially_immediate_text(&self) -> Option<&'static str> {
2467 self.initially
2468 .map(|initially_immediate| match initially_immediate {
2469 DeferrableInitial::Immediate => "INITIALLY IMMEDIATE",
2470 DeferrableInitial::Deferred => "INITIALLY DEFERRED",
2471 })
2472 }
2473
2474 fn enforced_text(&self) -> Option<&'static str> {
2475 self.enforced.map(
2476 |enforced| {
2477 if enforced {
2478 "ENFORCED"
2479 } else {
2480 "NOT ENFORCED"
2481 }
2482 },
2483 )
2484 }
2485}
2486
2487impl fmt::Display for ConstraintCharacteristics {
2488 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2489 let deferrable = self.deferrable_text();
2490 let initially_immediate = self.initially_immediate_text();
2491 let enforced = self.enforced_text();
2492
2493 match (deferrable, initially_immediate, enforced) {
2494 (None, None, None) => Ok(()),
2495 (None, None, Some(enforced)) => write!(f, "{enforced}"),
2496 (None, Some(initial), None) => write!(f, "{initial}"),
2497 (None, Some(initial), Some(enforced)) => write!(f, "{initial} {enforced}"),
2498 (Some(deferrable), None, None) => write!(f, "{deferrable}"),
2499 (Some(deferrable), None, Some(enforced)) => write!(f, "{deferrable} {enforced}"),
2500 (Some(deferrable), Some(initial), None) => write!(f, "{deferrable} {initial}"),
2501 (Some(deferrable), Some(initial), Some(enforced)) => {
2502 write!(f, "{deferrable} {initial} {enforced}")
2503 }
2504 }
2505 }
2506}
2507
2508#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2513#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2514#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2515pub enum ReferentialAction {
2516 Restrict,
2518 Cascade,
2520 SetNull,
2522 NoAction,
2524 SetDefault,
2526}
2527
2528impl fmt::Display for ReferentialAction {
2529 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2530 f.write_str(match self {
2531 ReferentialAction::Restrict => "RESTRICT",
2532 ReferentialAction::Cascade => "CASCADE",
2533 ReferentialAction::SetNull => "SET NULL",
2534 ReferentialAction::NoAction => "NO ACTION",
2535 ReferentialAction::SetDefault => "SET DEFAULT",
2536 })
2537 }
2538}
2539
2540#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2544#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2545#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2546pub enum DropBehavior {
2547 Restrict,
2549 Cascade,
2551}
2552
2553impl fmt::Display for DropBehavior {
2554 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2555 f.write_str(match self {
2556 DropBehavior::Restrict => "RESTRICT",
2557 DropBehavior::Cascade => "CASCADE",
2558 })
2559 }
2560}
2561
2562#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2564#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2565#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2566pub enum UserDefinedTypeRepresentation {
2567 Composite {
2569 attributes: Vec<UserDefinedTypeCompositeAttributeDef>,
2571 },
2572 Enum {
2577 labels: Vec<Ident>,
2579 },
2580 Range {
2584 options: Vec<UserDefinedTypeRangeOption>,
2586 },
2587 SqlDefinition {
2593 options: Vec<UserDefinedTypeSqlDefinitionOption>,
2595 },
2596}
2597
2598impl fmt::Display for UserDefinedTypeRepresentation {
2599 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2600 match self {
2601 Self::Composite { attributes } => {
2602 write!(f, "AS ({})", display_comma_separated(attributes))
2603 }
2604 Self::Enum { labels } => {
2605 write!(f, "AS ENUM ({})", display_comma_separated(labels))
2606 }
2607 Self::Range { options } => {
2608 write!(f, "AS RANGE ({})", display_comma_separated(options))
2609 }
2610 Self::SqlDefinition { options } => {
2611 write!(f, "({})", display_comma_separated(options))
2612 }
2613 }
2614 }
2615}
2616
2617#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2619#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2620#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2621pub struct UserDefinedTypeCompositeAttributeDef {
2622 pub name: Ident,
2624 pub data_type: DataType,
2626 pub collation: Option<ObjectName>,
2628}
2629
2630impl fmt::Display for UserDefinedTypeCompositeAttributeDef {
2631 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2632 write!(f, "{} {}", self.name, self.data_type)?;
2633 if let Some(collation) = &self.collation {
2634 write!(f, " COLLATE {collation}")?;
2635 }
2636 Ok(())
2637 }
2638}
2639
2640#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2663#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2664#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2665pub enum UserDefinedTypeInternalLength {
2666 Fixed(u64),
2668 Variable,
2670}
2671
2672impl fmt::Display for UserDefinedTypeInternalLength {
2673 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2674 match self {
2675 UserDefinedTypeInternalLength::Fixed(n) => write!(f, "{}", n),
2676 UserDefinedTypeInternalLength::Variable => write!(f, "VARIABLE"),
2677 }
2678 }
2679}
2680
2681#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2700#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2701#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2702pub enum Alignment {
2703 Char,
2705 Int2,
2707 Int4,
2709 Double,
2711}
2712
2713impl fmt::Display for Alignment {
2714 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2715 match self {
2716 Alignment::Char => write!(f, "char"),
2717 Alignment::Int2 => write!(f, "int2"),
2718 Alignment::Int4 => write!(f, "int4"),
2719 Alignment::Double => write!(f, "double"),
2720 }
2721 }
2722}
2723
2724#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2744#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2745#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2746pub enum UserDefinedTypeStorage {
2747 Plain,
2749 External,
2751 Extended,
2753 Main,
2755}
2756
2757impl fmt::Display for UserDefinedTypeStorage {
2758 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2759 match self {
2760 UserDefinedTypeStorage::Plain => write!(f, "plain"),
2761 UserDefinedTypeStorage::External => write!(f, "external"),
2762 UserDefinedTypeStorage::Extended => write!(f, "extended"),
2763 UserDefinedTypeStorage::Main => write!(f, "main"),
2764 }
2765 }
2766}
2767
2768#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2786#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2787#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2788pub enum UserDefinedTypeRangeOption {
2789 Subtype(DataType),
2791 SubtypeOpClass(ObjectName),
2793 Collation(ObjectName),
2795 Canonical(ObjectName),
2797 SubtypeDiff(ObjectName),
2799 MultirangeTypeName(ObjectName),
2801}
2802
2803impl fmt::Display for UserDefinedTypeRangeOption {
2804 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2805 match self {
2806 UserDefinedTypeRangeOption::Subtype(dt) => write!(f, "SUBTYPE = {}", dt),
2807 UserDefinedTypeRangeOption::SubtypeOpClass(name) => {
2808 write!(f, "SUBTYPE_OPCLASS = {}", name)
2809 }
2810 UserDefinedTypeRangeOption::Collation(name) => write!(f, "COLLATION = {}", name),
2811 UserDefinedTypeRangeOption::Canonical(name) => write!(f, "CANONICAL = {}", name),
2812 UserDefinedTypeRangeOption::SubtypeDiff(name) => write!(f, "SUBTYPE_DIFF = {}", name),
2813 UserDefinedTypeRangeOption::MultirangeTypeName(name) => {
2814 write!(f, "MULTIRANGE_TYPE_NAME = {}", name)
2815 }
2816 }
2817 }
2818}
2819
2820#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2841#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2842#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2843pub enum UserDefinedTypeSqlDefinitionOption {
2844 Input(ObjectName),
2846 Output(ObjectName),
2848 Receive(ObjectName),
2850 Send(ObjectName),
2852 TypmodIn(ObjectName),
2854 TypmodOut(ObjectName),
2856 Analyze(ObjectName),
2858 Subscript(ObjectName),
2860 InternalLength(UserDefinedTypeInternalLength),
2862 PassedByValue,
2864 Alignment(Alignment),
2866 Storage(UserDefinedTypeStorage),
2868 Like(ObjectName),
2870 Category(char),
2872 Preferred(bool),
2874 Default(Expr),
2876 Element(DataType),
2878 Delimiter(String),
2880 Collatable(bool),
2882}
2883
2884impl fmt::Display for UserDefinedTypeSqlDefinitionOption {
2885 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2886 match self {
2887 UserDefinedTypeSqlDefinitionOption::Input(name) => write!(f, "INPUT = {}", name),
2888 UserDefinedTypeSqlDefinitionOption::Output(name) => write!(f, "OUTPUT = {}", name),
2889 UserDefinedTypeSqlDefinitionOption::Receive(name) => write!(f, "RECEIVE = {}", name),
2890 UserDefinedTypeSqlDefinitionOption::Send(name) => write!(f, "SEND = {}", name),
2891 UserDefinedTypeSqlDefinitionOption::TypmodIn(name) => write!(f, "TYPMOD_IN = {}", name),
2892 UserDefinedTypeSqlDefinitionOption::TypmodOut(name) => {
2893 write!(f, "TYPMOD_OUT = {}", name)
2894 }
2895 UserDefinedTypeSqlDefinitionOption::Analyze(name) => write!(f, "ANALYZE = {}", name),
2896 UserDefinedTypeSqlDefinitionOption::Subscript(name) => {
2897 write!(f, "SUBSCRIPT = {}", name)
2898 }
2899 UserDefinedTypeSqlDefinitionOption::InternalLength(len) => {
2900 write!(f, "INTERNALLENGTH = {}", len)
2901 }
2902 UserDefinedTypeSqlDefinitionOption::PassedByValue => write!(f, "PASSEDBYVALUE"),
2903 UserDefinedTypeSqlDefinitionOption::Alignment(align) => {
2904 write!(f, "ALIGNMENT = {}", align)
2905 }
2906 UserDefinedTypeSqlDefinitionOption::Storage(storage) => {
2907 write!(f, "STORAGE = {}", storage)
2908 }
2909 UserDefinedTypeSqlDefinitionOption::Like(name) => write!(f, "LIKE = {}", name),
2910 UserDefinedTypeSqlDefinitionOption::Category(c) => write!(f, "CATEGORY = '{}'", c),
2911 UserDefinedTypeSqlDefinitionOption::Preferred(b) => write!(f, "PREFERRED = {}", b),
2912 UserDefinedTypeSqlDefinitionOption::Default(expr) => write!(f, "DEFAULT = {}", expr),
2913 UserDefinedTypeSqlDefinitionOption::Element(dt) => write!(f, "ELEMENT = {}", dt),
2914 UserDefinedTypeSqlDefinitionOption::Delimiter(s) => {
2915 write!(f, "DELIMITER = '{}'", escape_single_quote_string(s))
2916 }
2917 UserDefinedTypeSqlDefinitionOption::Collatable(b) => write!(f, "COLLATABLE = {}", b),
2918 }
2919 }
2920}
2921
2922#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
2926#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2927#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2928pub enum Partition {
2929 Identifier(Ident),
2931 Expr(Expr),
2933 Part(Expr),
2936 Partitions(Vec<Expr>),
2938}
2939
2940impl fmt::Display for Partition {
2941 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2942 match self {
2943 Partition::Identifier(id) => write!(f, "PARTITION ID {id}"),
2944 Partition::Expr(expr) => write!(f, "PARTITION {expr}"),
2945 Partition::Part(expr) => write!(f, "PART {expr}"),
2946 Partition::Partitions(partitions) => {
2947 write!(f, "PARTITION ({})", display_comma_separated(partitions))
2948 }
2949 }
2950 }
2951}
2952
2953#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2956#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2957#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2958pub enum Deduplicate {
2959 All,
2961 ByExpression(Expr),
2963}
2964
2965impl fmt::Display for Deduplicate {
2966 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2967 match self {
2968 Deduplicate::All => write!(f, "DEDUPLICATE"),
2969 Deduplicate::ByExpression(expr) => write!(f, "DEDUPLICATE BY {expr}"),
2970 }
2971 }
2972}
2973
2974#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2979#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2980#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
2981pub struct ClusteredBy {
2982 pub columns: Vec<Ident>,
2984 pub sorted_by: Option<Vec<OrderByExpr>>,
2986 pub num_buckets: Value,
2988}
2989
2990impl fmt::Display for ClusteredBy {
2991 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2992 write!(
2993 f,
2994 "CLUSTERED BY ({})",
2995 display_comma_separated(&self.columns)
2996 )?;
2997 if let Some(ref sorted_by) = self.sorted_by {
2998 write!(f, " SORTED BY ({})", display_comma_separated(sorted_by))?;
2999 }
3000 write!(f, " INTO {} BUCKETS", self.num_buckets)
3001 }
3002}
3003
3004#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3006#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3007#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3008pub struct CreateIndex {
3009 pub name: Option<ObjectName>,
3011 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3012 pub table_name: ObjectName,
3014 pub using: Option<IndexType>,
3017 pub columns: Vec<IndexColumn>,
3019 pub unique: bool,
3021 pub concurrently: bool,
3023 pub if_not_exists: bool,
3025 pub include: Vec<Ident>,
3027 pub nulls_distinct: Option<bool>,
3029 pub with: Vec<Expr>,
3031 pub predicate: Option<Expr>,
3033 pub index_options: Vec<IndexOption>,
3035 pub alter_options: Vec<AlterTableOperation>,
3042}
3043
3044impl fmt::Display for CreateIndex {
3045 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3046 write!(
3047 f,
3048 "CREATE {unique}INDEX {concurrently}{if_not_exists}",
3049 unique = if self.unique { "UNIQUE " } else { "" },
3050 concurrently = if self.concurrently {
3051 "CONCURRENTLY "
3052 } else {
3053 ""
3054 },
3055 if_not_exists = if self.if_not_exists {
3056 "IF NOT EXISTS "
3057 } else {
3058 ""
3059 },
3060 )?;
3061 if let Some(value) = &self.name {
3062 write!(f, "{value} ")?;
3063 }
3064 write!(f, "ON {}", self.table_name)?;
3065 if let Some(value) = &self.using {
3066 write!(f, " USING {value} ")?;
3067 }
3068 write!(f, "({})", display_comma_separated(&self.columns))?;
3069 if !self.include.is_empty() {
3070 write!(f, " INCLUDE ({})", display_comma_separated(&self.include))?;
3071 }
3072 if let Some(value) = self.nulls_distinct {
3073 if value {
3074 write!(f, " NULLS DISTINCT")?;
3075 } else {
3076 write!(f, " NULLS NOT DISTINCT")?;
3077 }
3078 }
3079 if !self.with.is_empty() {
3080 write!(f, " WITH ({})", display_comma_separated(&self.with))?;
3081 }
3082 if let Some(predicate) = &self.predicate {
3083 write!(f, " WHERE {predicate}")?;
3084 }
3085 if !self.index_options.is_empty() {
3086 write!(f, " {}", display_separated(&self.index_options, " "))?;
3087 }
3088 if !self.alter_options.is_empty() {
3089 write!(f, " {}", display_separated(&self.alter_options, " "))?;
3090 }
3091 Ok(())
3092 }
3093}
3094
3095#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3097#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3098#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3099pub struct CreateTable {
3100 pub or_replace: bool,
3102 pub temporary: bool,
3104 pub external: bool,
3106 pub dynamic: bool,
3108 pub global: Option<bool>,
3110 pub if_not_exists: bool,
3112 pub transient: bool,
3114 pub volatile: bool,
3116 pub iceberg: bool,
3118 pub snapshot: bool,
3121 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3123 pub name: ObjectName,
3124 pub columns: Vec<ColumnDef>,
3126 pub constraints: Vec<TableConstraint>,
3128 pub hive_distribution: HiveDistributionStyle,
3130 pub hive_formats: Option<HiveFormat>,
3132 pub table_options: CreateTableOptions,
3134 pub file_format: Option<FileFormat>,
3136 pub location: Option<String>,
3138 pub query: Option<Box<Query>>,
3140 pub without_rowid: bool,
3142 pub like: Option<CreateTableLikeKind>,
3144 pub clone: Option<ObjectName>,
3146 pub version: Option<TableVersion>,
3148 pub comment: Option<CommentDef>,
3152 pub on_commit: Option<OnCommit>,
3155 pub on_cluster: Option<Ident>,
3158 pub primary_key: Option<Box<Expr>>,
3161 pub order_by: Option<OneOrManyWithParens<Expr>>,
3165 pub partition_by: Option<Box<Expr>>,
3168 pub cluster_by: Option<WrappedCollection<Vec<Expr>>>,
3173 pub clustered_by: Option<ClusteredBy>,
3176 pub inherits: Option<Vec<ObjectName>>,
3181 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
3185 pub partition_of: Option<ObjectName>,
3186 pub for_values: Option<ForValues>,
3189 pub strict: bool,
3193 pub copy_grants: bool,
3196 pub enable_schema_evolution: Option<bool>,
3199 pub change_tracking: Option<bool>,
3202 pub data_retention_time_in_days: Option<u64>,
3205 pub max_data_extension_time_in_days: Option<u64>,
3208 pub default_ddl_collation: Option<String>,
3211 pub with_aggregation_policy: Option<ObjectName>,
3214 pub with_row_access_policy: Option<RowAccessPolicy>,
3217 pub with_storage_lifecycle_policy: Option<StorageLifecyclePolicy>,
3220 pub with_tags: Option<Vec<Tag>>,
3223 pub external_volume: Option<String>,
3226 pub base_location: Option<String>,
3229 pub catalog: Option<String>,
3232 pub catalog_sync: Option<String>,
3235 pub storage_serialization_policy: Option<StorageSerializationPolicy>,
3238 pub target_lag: Option<String>,
3241 pub warehouse: Option<Ident>,
3244 pub refresh_mode: Option<RefreshModeKind>,
3247 pub initialize: Option<InitializeKind>,
3250 pub require_user: bool,
3253 pub diststyle: Option<DistStyle>,
3256 pub distkey: Option<Expr>,
3259 pub sortkey: Option<Vec<Expr>>,
3262 pub backup: Option<bool>,
3265}
3266
3267impl fmt::Display for CreateTable {
3268 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3269 write!(
3277 f,
3278 "CREATE {or_replace}{external}{global}{temporary}{transient}{volatile}{dynamic}{iceberg}{snapshot}TABLE {if_not_exists}{name}",
3279 or_replace = if self.or_replace { "OR REPLACE " } else { "" },
3280 external = if self.external { "EXTERNAL " } else { "" },
3281 snapshot = if self.snapshot { "SNAPSHOT " } else { "" },
3282 global = self.global
3283 .map(|global| {
3284 if global {
3285 "GLOBAL "
3286 } else {
3287 "LOCAL "
3288 }
3289 })
3290 .unwrap_or(""),
3291 if_not_exists = if self.if_not_exists { "IF NOT EXISTS " } else { "" },
3292 temporary = if self.temporary { "TEMPORARY " } else { "" },
3293 transient = if self.transient { "TRANSIENT " } else { "" },
3294 volatile = if self.volatile { "VOLATILE " } else { "" },
3295 iceberg = if self.iceberg { "ICEBERG " } else { "" },
3297 dynamic = if self.dynamic { "DYNAMIC " } else { "" },
3298 name = self.name,
3299 )?;
3300 if let Some(partition_of) = &self.partition_of {
3301 write!(f, " PARTITION OF {partition_of}")?;
3302 }
3303 if let Some(on_cluster) = &self.on_cluster {
3304 write!(f, " ON CLUSTER {on_cluster}")?;
3305 }
3306 if !self.columns.is_empty() || !self.constraints.is_empty() {
3307 f.write_str(" (")?;
3308 NewLine.fmt(f)?;
3309 Indent(DisplayCommaSeparated(&self.columns)).fmt(f)?;
3310 if !self.columns.is_empty() && !self.constraints.is_empty() {
3311 f.write_str(",")?;
3312 SpaceOrNewline.fmt(f)?;
3313 }
3314 Indent(DisplayCommaSeparated(&self.constraints)).fmt(f)?;
3315 NewLine.fmt(f)?;
3316 f.write_str(")")?;
3317 } else if self.query.is_none()
3318 && self.like.is_none()
3319 && self.clone.is_none()
3320 && self.partition_of.is_none()
3321 {
3322 f.write_str(" ()")?;
3324 } else if let Some(CreateTableLikeKind::Parenthesized(like_in_columns_list)) = &self.like {
3325 write!(f, " ({like_in_columns_list})")?;
3326 }
3327 if let Some(for_values) = &self.for_values {
3328 write!(f, " {for_values}")?;
3329 }
3330
3331 if let Some(comment) = &self.comment {
3334 write!(f, " COMMENT '{comment}'")?;
3335 }
3336
3337 if self.without_rowid {
3339 write!(f, " WITHOUT ROWID")?;
3340 }
3341
3342 if let Some(CreateTableLikeKind::Plain(like)) = &self.like {
3343 write!(f, " {like}")?;
3344 }
3345
3346 if let Some(c) = &self.clone {
3347 write!(f, " CLONE {c}")?;
3348 }
3349
3350 if let Some(version) = &self.version {
3351 write!(f, " {version}")?;
3352 }
3353
3354 match &self.hive_distribution {
3355 HiveDistributionStyle::PARTITIONED { columns } => {
3356 write!(f, " PARTITIONED BY ({})", display_comma_separated(columns))?;
3357 }
3358 HiveDistributionStyle::SKEWED {
3359 columns,
3360 on,
3361 stored_as_directories,
3362 } => {
3363 write!(
3364 f,
3365 " SKEWED BY ({})) ON ({})",
3366 display_comma_separated(columns),
3367 display_comma_separated(on)
3368 )?;
3369 if *stored_as_directories {
3370 write!(f, " STORED AS DIRECTORIES")?;
3371 }
3372 }
3373 _ => (),
3374 }
3375
3376 if let Some(clustered_by) = &self.clustered_by {
3377 write!(f, " {clustered_by}")?;
3378 }
3379
3380 if let Some(HiveFormat {
3381 row_format,
3382 serde_properties,
3383 storage,
3384 location,
3385 }) = &self.hive_formats
3386 {
3387 match row_format {
3388 Some(HiveRowFormat::SERDE { class }) => write!(f, " ROW FORMAT SERDE '{class}'")?,
3389 Some(HiveRowFormat::DELIMITED { delimiters }) => {
3390 write!(f, " ROW FORMAT DELIMITED")?;
3391 if !delimiters.is_empty() {
3392 write!(f, " {}", display_separated(delimiters, " "))?;
3393 }
3394 }
3395 None => (),
3396 }
3397 match storage {
3398 Some(HiveIOFormat::IOF {
3399 input_format,
3400 output_format,
3401 }) => write!(
3402 f,
3403 " STORED AS INPUTFORMAT {input_format} OUTPUTFORMAT {output_format}"
3404 )?,
3405 Some(HiveIOFormat::FileFormat { format }) if !self.external => {
3406 write!(f, " STORED AS {format}")?
3407 }
3408 _ => (),
3409 }
3410 if let Some(serde_properties) = serde_properties.as_ref() {
3411 write!(
3412 f,
3413 " WITH SERDEPROPERTIES ({})",
3414 display_comma_separated(serde_properties)
3415 )?;
3416 }
3417 if !self.external {
3418 if let Some(loc) = location {
3419 write!(f, " LOCATION '{loc}'")?;
3420 }
3421 }
3422 }
3423 if self.external {
3424 if let Some(file_format) = self.file_format {
3425 write!(f, " STORED AS {file_format}")?;
3426 }
3427 if let Some(location) = &self.location {
3428 write!(f, " LOCATION '{location}'")?;
3429 }
3430 }
3431
3432 match &self.table_options {
3433 options @ CreateTableOptions::With(_)
3434 | options @ CreateTableOptions::Plain(_)
3435 | options @ CreateTableOptions::TableProperties(_) => write!(f, " {options}")?,
3436 _ => (),
3437 }
3438
3439 if let Some(primary_key) = &self.primary_key {
3440 write!(f, " PRIMARY KEY {primary_key}")?;
3441 }
3442 if let Some(order_by) = &self.order_by {
3443 write!(f, " ORDER BY {order_by}")?;
3444 }
3445 if let Some(inherits) = &self.inherits {
3446 write!(f, " INHERITS ({})", display_comma_separated(inherits))?;
3447 }
3448 if let Some(partition_by) = self.partition_by.as_ref() {
3449 write!(f, " PARTITION BY {partition_by}")?;
3450 }
3451 if let Some(cluster_by) = self.cluster_by.as_ref() {
3452 write!(f, " CLUSTER BY {cluster_by}")?;
3453 }
3454 if let options @ CreateTableOptions::Options(_) = &self.table_options {
3455 write!(f, " {options}")?;
3456 }
3457 if let Some(external_volume) = self.external_volume.as_ref() {
3458 write!(f, " EXTERNAL_VOLUME='{external_volume}'")?;
3459 }
3460
3461 if let Some(catalog) = self.catalog.as_ref() {
3462 write!(f, " CATALOG='{catalog}'")?;
3463 }
3464
3465 if self.iceberg {
3466 if let Some(base_location) = self.base_location.as_ref() {
3467 write!(f, " BASE_LOCATION='{base_location}'")?;
3468 }
3469 }
3470
3471 if let Some(catalog_sync) = self.catalog_sync.as_ref() {
3472 write!(f, " CATALOG_SYNC='{catalog_sync}'")?;
3473 }
3474
3475 if let Some(storage_serialization_policy) = self.storage_serialization_policy.as_ref() {
3476 write!(
3477 f,
3478 " STORAGE_SERIALIZATION_POLICY={storage_serialization_policy}"
3479 )?;
3480 }
3481
3482 if self.copy_grants {
3483 write!(f, " COPY GRANTS")?;
3484 }
3485
3486 if let Some(is_enabled) = self.enable_schema_evolution {
3487 write!(
3488 f,
3489 " ENABLE_SCHEMA_EVOLUTION={}",
3490 if is_enabled { "TRUE" } else { "FALSE" }
3491 )?;
3492 }
3493
3494 if let Some(is_enabled) = self.change_tracking {
3495 write!(
3496 f,
3497 " CHANGE_TRACKING={}",
3498 if is_enabled { "TRUE" } else { "FALSE" }
3499 )?;
3500 }
3501
3502 if let Some(data_retention_time_in_days) = self.data_retention_time_in_days {
3503 write!(
3504 f,
3505 " DATA_RETENTION_TIME_IN_DAYS={data_retention_time_in_days}",
3506 )?;
3507 }
3508
3509 if let Some(max_data_extension_time_in_days) = self.max_data_extension_time_in_days {
3510 write!(
3511 f,
3512 " MAX_DATA_EXTENSION_TIME_IN_DAYS={max_data_extension_time_in_days}",
3513 )?;
3514 }
3515
3516 if let Some(default_ddl_collation) = &self.default_ddl_collation {
3517 write!(f, " DEFAULT_DDL_COLLATION='{default_ddl_collation}'",)?;
3518 }
3519
3520 if let Some(with_aggregation_policy) = &self.with_aggregation_policy {
3521 write!(f, " WITH AGGREGATION POLICY {with_aggregation_policy}",)?;
3522 }
3523
3524 if let Some(row_access_policy) = &self.with_row_access_policy {
3525 write!(f, " {row_access_policy}",)?;
3526 }
3527
3528 if let Some(storage_lifecycle_policy) = &self.with_storage_lifecycle_policy {
3529 write!(f, " {storage_lifecycle_policy}",)?;
3530 }
3531
3532 if let Some(tag) = &self.with_tags {
3533 write!(f, " WITH TAG ({})", display_comma_separated(tag.as_slice()))?;
3534 }
3535
3536 if let Some(target_lag) = &self.target_lag {
3537 write!(f, " TARGET_LAG='{target_lag}'")?;
3538 }
3539
3540 if let Some(warehouse) = &self.warehouse {
3541 write!(f, " WAREHOUSE={warehouse}")?;
3542 }
3543
3544 if let Some(refresh_mode) = &self.refresh_mode {
3545 write!(f, " REFRESH_MODE={refresh_mode}")?;
3546 }
3547
3548 if let Some(initialize) = &self.initialize {
3549 write!(f, " INITIALIZE={initialize}")?;
3550 }
3551
3552 if self.require_user {
3553 write!(f, " REQUIRE USER")?;
3554 }
3555
3556 if self.on_commit.is_some() {
3557 let on_commit = match self.on_commit {
3558 Some(OnCommit::DeleteRows) => "ON COMMIT DELETE ROWS",
3559 Some(OnCommit::PreserveRows) => "ON COMMIT PRESERVE ROWS",
3560 Some(OnCommit::Drop) => "ON COMMIT DROP",
3561 None => "",
3562 };
3563 write!(f, " {on_commit}")?;
3564 }
3565 if self.strict {
3566 write!(f, " STRICT")?;
3567 }
3568 if let Some(backup) = self.backup {
3569 write!(f, " BACKUP {}", if backup { "YES" } else { "NO" })?;
3570 }
3571 if let Some(diststyle) = &self.diststyle {
3572 write!(f, " DISTSTYLE {diststyle}")?;
3573 }
3574 if let Some(distkey) = &self.distkey {
3575 write!(f, " DISTKEY({distkey})")?;
3576 }
3577 if let Some(sortkey) = &self.sortkey {
3578 write!(f, " SORTKEY({})", display_comma_separated(sortkey))?;
3579 }
3580 if let Some(query) = &self.query {
3581 write!(f, " AS {query}")?;
3582 }
3583 Ok(())
3584 }
3585}
3586
3587#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3593#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3594#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3595pub enum ForValues {
3596 In(Vec<Expr>),
3598 From {
3600 from: Vec<PartitionBoundValue>,
3602 to: Vec<PartitionBoundValue>,
3604 },
3605 With {
3607 modulus: u64,
3609 remainder: u64,
3611 },
3612 Default,
3614}
3615
3616impl fmt::Display for ForValues {
3617 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3618 match self {
3619 ForValues::In(values) => {
3620 write!(f, "FOR VALUES IN ({})", display_comma_separated(values))
3621 }
3622 ForValues::From { from, to } => {
3623 write!(
3624 f,
3625 "FOR VALUES FROM ({}) TO ({})",
3626 display_comma_separated(from),
3627 display_comma_separated(to)
3628 )
3629 }
3630 ForValues::With { modulus, remainder } => {
3631 write!(
3632 f,
3633 "FOR VALUES WITH (MODULUS {modulus}, REMAINDER {remainder})"
3634 )
3635 }
3636 ForValues::Default => write!(f, "DEFAULT"),
3637 }
3638 }
3639}
3640
3641#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3646#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3647#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3648pub enum PartitionBoundValue {
3649 Expr(Expr),
3651 MinValue,
3653 MaxValue,
3655}
3656
3657impl fmt::Display for PartitionBoundValue {
3658 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3659 match self {
3660 PartitionBoundValue::Expr(expr) => write!(f, "{expr}"),
3661 PartitionBoundValue::MinValue => write!(f, "MINVALUE"),
3662 PartitionBoundValue::MaxValue => write!(f, "MAXVALUE"),
3663 }
3664 }
3665}
3666
3667#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3671#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3672#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3673pub enum DistStyle {
3674 Auto,
3676 Even,
3678 Key,
3680 All,
3682}
3683
3684impl fmt::Display for DistStyle {
3685 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3686 match self {
3687 DistStyle::Auto => write!(f, "AUTO"),
3688 DistStyle::Even => write!(f, "EVEN"),
3689 DistStyle::Key => write!(f, "KEY"),
3690 DistStyle::All => write!(f, "ALL"),
3691 }
3692 }
3693}
3694
3695#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3696#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3697#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3698pub struct CreateDomain {
3711 pub name: ObjectName,
3713 pub data_type: DataType,
3715 pub collation: Option<Ident>,
3717 pub default: Option<Expr>,
3719 pub constraints: Vec<TableConstraint>,
3721}
3722
3723impl fmt::Display for CreateDomain {
3724 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3725 write!(
3726 f,
3727 "CREATE DOMAIN {name} AS {data_type}",
3728 name = self.name,
3729 data_type = self.data_type
3730 )?;
3731 if let Some(collation) = &self.collation {
3732 write!(f, " COLLATE {collation}")?;
3733 }
3734 if let Some(default) = &self.default {
3735 write!(f, " DEFAULT {default}")?;
3736 }
3737 if !self.constraints.is_empty() {
3738 write!(f, " {}", display_separated(&self.constraints, " "))?;
3739 }
3740 Ok(())
3741 }
3742}
3743
3744#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3746#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3747#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3748pub enum FunctionReturnType {
3749 DataType(DataType),
3751 SetOf(DataType),
3755}
3756
3757impl fmt::Display for FunctionReturnType {
3758 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3759 match self {
3760 FunctionReturnType::DataType(data_type) => write!(f, "{data_type}"),
3761 FunctionReturnType::SetOf(data_type) => write!(f, "SETOF {data_type}"),
3762 }
3763 }
3764}
3765
3766#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3767#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3768#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3769pub struct CreateFunction {
3771 pub or_alter: bool,
3775 pub or_replace: bool,
3777 pub temporary: bool,
3779 pub if_not_exists: bool,
3781 pub name: ObjectName,
3783 pub args: Option<Vec<OperateFunctionArg>>,
3785 pub return_type: Option<FunctionReturnType>,
3787 pub function_body: Option<CreateFunctionBody>,
3795 pub behavior: Option<FunctionBehavior>,
3801 pub called_on_null: Option<FunctionCalledOnNull>,
3805 pub parallel: Option<FunctionParallel>,
3809 pub security: Option<FunctionSecurity>,
3813 pub set_params: Vec<FunctionDefinitionSetParam>,
3817 pub using: Option<CreateFunctionUsing>,
3819 pub language: Option<Ident>,
3827 pub determinism_specifier: Option<FunctionDeterminismSpecifier>,
3831 pub options: Option<Vec<SqlOption>>,
3835 pub remote_connection: Option<ObjectName>,
3845}
3846
3847impl fmt::Display for CreateFunction {
3848 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3849 write!(
3850 f,
3851 "CREATE {or_alter}{or_replace}{temp}FUNCTION {if_not_exists}{name}",
3852 name = self.name,
3853 temp = if self.temporary { "TEMPORARY " } else { "" },
3854 or_alter = if self.or_alter { "OR ALTER " } else { "" },
3855 or_replace = if self.or_replace { "OR REPLACE " } else { "" },
3856 if_not_exists = if self.if_not_exists {
3857 "IF NOT EXISTS "
3858 } else {
3859 ""
3860 },
3861 )?;
3862 if let Some(args) = &self.args {
3863 write!(f, "({})", display_comma_separated(args))?;
3864 }
3865 if let Some(return_type) = &self.return_type {
3866 write!(f, " RETURNS {return_type}")?;
3867 }
3868 if let Some(determinism_specifier) = &self.determinism_specifier {
3869 write!(f, " {determinism_specifier}")?;
3870 }
3871 if let Some(language) = &self.language {
3872 write!(f, " LANGUAGE {language}")?;
3873 }
3874 if let Some(behavior) = &self.behavior {
3875 write!(f, " {behavior}")?;
3876 }
3877 if let Some(called_on_null) = &self.called_on_null {
3878 write!(f, " {called_on_null}")?;
3879 }
3880 if let Some(parallel) = &self.parallel {
3881 write!(f, " {parallel}")?;
3882 }
3883 if let Some(security) = &self.security {
3884 write!(f, " {security}")?;
3885 }
3886 for set_param in &self.set_params {
3887 write!(f, " {set_param}")?;
3888 }
3889 if let Some(remote_connection) = &self.remote_connection {
3890 write!(f, " REMOTE WITH CONNECTION {remote_connection}")?;
3891 }
3892 if let Some(CreateFunctionBody::AsBeforeOptions { body, link_symbol }) = &self.function_body
3893 {
3894 write!(f, " AS {body}")?;
3895 if let Some(link_symbol) = link_symbol {
3896 write!(f, ", {link_symbol}")?;
3897 }
3898 }
3899 if let Some(CreateFunctionBody::Return(function_body)) = &self.function_body {
3900 write!(f, " RETURN {function_body}")?;
3901 }
3902 if let Some(CreateFunctionBody::AsReturnExpr(function_body)) = &self.function_body {
3903 write!(f, " AS RETURN {function_body}")?;
3904 }
3905 if let Some(CreateFunctionBody::AsReturnSelect(function_body)) = &self.function_body {
3906 write!(f, " AS RETURN {function_body}")?;
3907 }
3908 if let Some(using) = &self.using {
3909 write!(f, " {using}")?;
3910 }
3911 if let Some(options) = &self.options {
3912 write!(
3913 f,
3914 " OPTIONS({})",
3915 display_comma_separated(options.as_slice())
3916 )?;
3917 }
3918 if let Some(CreateFunctionBody::AsAfterOptions(function_body)) = &self.function_body {
3919 write!(f, " AS {function_body}")?;
3920 }
3921 if let Some(CreateFunctionBody::AsBeginEnd(bes)) = &self.function_body {
3922 write!(f, " AS {bes}")?;
3923 }
3924 Ok(())
3925 }
3926}
3927
3928#[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 CreateConnector {
3941 pub name: Ident,
3943 pub if_not_exists: bool,
3945 pub connector_type: Option<String>,
3947 pub url: Option<String>,
3949 pub comment: Option<CommentDef>,
3951 pub with_dcproperties: Option<Vec<SqlOption>>,
3953}
3954
3955impl fmt::Display for CreateConnector {
3956 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3957 write!(
3958 f,
3959 "CREATE CONNECTOR {if_not_exists}{name}",
3960 if_not_exists = if self.if_not_exists {
3961 "IF NOT EXISTS "
3962 } else {
3963 ""
3964 },
3965 name = self.name,
3966 )?;
3967
3968 if let Some(connector_type) = &self.connector_type {
3969 write!(f, " TYPE '{connector_type}'")?;
3970 }
3971
3972 if let Some(url) = &self.url {
3973 write!(f, " URL '{url}'")?;
3974 }
3975
3976 if let Some(comment) = &self.comment {
3977 write!(f, " COMMENT = '{comment}'")?;
3978 }
3979
3980 if let Some(with_dcproperties) = &self.with_dcproperties {
3981 write!(
3982 f,
3983 " WITH DCPROPERTIES({})",
3984 display_comma_separated(with_dcproperties)
3985 )?;
3986 }
3987
3988 Ok(())
3989 }
3990}
3991
3992#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
3997#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3998#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
3999pub enum AlterSchemaOperation {
4000 SetDefaultCollate {
4002 collate: Expr,
4004 },
4005 AddReplica {
4007 replica: Ident,
4009 options: Option<Vec<SqlOption>>,
4011 },
4012 DropReplica {
4014 replica: Ident,
4016 },
4017 SetOptionsParens {
4019 options: Vec<SqlOption>,
4021 },
4022 Rename {
4024 name: ObjectName,
4026 },
4027 OwnerTo {
4029 owner: Owner,
4031 },
4032}
4033
4034impl fmt::Display for AlterSchemaOperation {
4035 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4036 match self {
4037 AlterSchemaOperation::SetDefaultCollate { collate } => {
4038 write!(f, "SET DEFAULT COLLATE {collate}")
4039 }
4040 AlterSchemaOperation::AddReplica { replica, options } => {
4041 write!(f, "ADD REPLICA {replica}")?;
4042 if let Some(options) = options {
4043 write!(f, " OPTIONS ({})", display_comma_separated(options))?;
4044 }
4045 Ok(())
4046 }
4047 AlterSchemaOperation::DropReplica { replica } => write!(f, "DROP REPLICA {replica}"),
4048 AlterSchemaOperation::SetOptionsParens { options } => {
4049 write!(f, "SET OPTIONS ({})", display_comma_separated(options))
4050 }
4051 AlterSchemaOperation::Rename { name } => write!(f, "RENAME TO {name}"),
4052 AlterSchemaOperation::OwnerTo { owner } => write!(f, "OWNER TO {owner}"),
4053 }
4054 }
4055}
4056#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4062#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4063#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4064pub enum RenameTableNameKind {
4065 As(ObjectName),
4067 To(ObjectName),
4069}
4070
4071impl fmt::Display for RenameTableNameKind {
4072 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4073 match self {
4074 RenameTableNameKind::As(name) => write!(f, "AS {name}"),
4075 RenameTableNameKind::To(name) => write!(f, "TO {name}"),
4076 }
4077 }
4078}
4079
4080#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4081#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4082#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4083pub struct AlterSchema {
4085 pub name: ObjectName,
4087 pub if_exists: bool,
4089 pub operations: Vec<AlterSchemaOperation>,
4091}
4092
4093impl fmt::Display for AlterSchema {
4094 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4095 write!(f, "ALTER SCHEMA ")?;
4096 if self.if_exists {
4097 write!(f, "IF EXISTS ")?;
4098 }
4099 write!(f, "{}", self.name)?;
4100 for operation in &self.operations {
4101 write!(f, " {operation}")?;
4102 }
4103
4104 Ok(())
4105 }
4106}
4107
4108impl Spanned for RenameTableNameKind {
4109 fn span(&self) -> Span {
4110 match self {
4111 RenameTableNameKind::As(name) => name.span(),
4112 RenameTableNameKind::To(name) => name.span(),
4113 }
4114 }
4115}
4116
4117#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
4118#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4119#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4120pub enum TriggerObjectKind {
4122 For(TriggerObject),
4124 ForEach(TriggerObject),
4126}
4127
4128impl Display for TriggerObjectKind {
4129 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4130 match self {
4131 TriggerObjectKind::For(obj) => write!(f, "FOR {obj}"),
4132 TriggerObjectKind::ForEach(obj) => write!(f, "FOR EACH {obj}"),
4133 }
4134 }
4135}
4136
4137#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4138#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4139#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4140pub struct CreateTrigger {
4154 pub or_alter: bool,
4158 pub temporary: bool,
4175 pub or_replace: bool,
4185 pub is_constraint: bool,
4187 pub name: ObjectName,
4189 pub period: Option<TriggerPeriod>,
4218 pub period_before_table: bool,
4229 pub events: Vec<TriggerEvent>,
4231 pub table_name: ObjectName,
4233 pub referenced_table_name: Option<ObjectName>,
4236 pub referencing: Vec<TriggerReferencing>,
4238 pub trigger_object: Option<TriggerObjectKind>,
4243 pub condition: Option<Expr>,
4245 pub exec_body: Option<TriggerExecBody>,
4247 pub statements_as: bool,
4249 pub statements: Option<ConditionalStatements>,
4251 pub characteristics: Option<ConstraintCharacteristics>,
4253}
4254
4255impl Display for CreateTrigger {
4256 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4257 let CreateTrigger {
4258 or_alter,
4259 temporary,
4260 or_replace,
4261 is_constraint,
4262 name,
4263 period_before_table,
4264 period,
4265 events,
4266 table_name,
4267 referenced_table_name,
4268 referencing,
4269 trigger_object,
4270 condition,
4271 exec_body,
4272 statements_as,
4273 statements,
4274 characteristics,
4275 } = self;
4276 write!(
4277 f,
4278 "CREATE {temporary}{or_alter}{or_replace}{is_constraint}TRIGGER {name} ",
4279 temporary = if *temporary { "TEMPORARY " } else { "" },
4280 or_alter = if *or_alter { "OR ALTER " } else { "" },
4281 or_replace = if *or_replace { "OR REPLACE " } else { "" },
4282 is_constraint = if *is_constraint { "CONSTRAINT " } else { "" },
4283 )?;
4284
4285 if *period_before_table {
4286 if let Some(p) = period {
4287 write!(f, "{p} ")?;
4288 }
4289 if !events.is_empty() {
4290 write!(f, "{} ", display_separated(events, " OR "))?;
4291 }
4292 write!(f, "ON {table_name}")?;
4293 } else {
4294 write!(f, "ON {table_name} ")?;
4295 if let Some(p) = period {
4296 write!(f, "{p}")?;
4297 }
4298 if !events.is_empty() {
4299 write!(f, " {}", display_separated(events, ", "))?;
4300 }
4301 }
4302
4303 if let Some(referenced_table_name) = referenced_table_name {
4304 write!(f, " FROM {referenced_table_name}")?;
4305 }
4306
4307 if let Some(characteristics) = characteristics {
4308 write!(f, " {characteristics}")?;
4309 }
4310
4311 if !referencing.is_empty() {
4312 write!(f, " REFERENCING {}", display_separated(referencing, " "))?;
4313 }
4314
4315 if let Some(trigger_object) = trigger_object {
4316 write!(f, " {trigger_object}")?;
4317 }
4318 if let Some(condition) = condition {
4319 write!(f, " WHEN {condition}")?;
4320 }
4321 if let Some(exec_body) = exec_body {
4322 write!(f, " EXECUTE {exec_body}")?;
4323 }
4324 if let Some(statements) = statements {
4325 if *statements_as {
4326 write!(f, " AS")?;
4327 }
4328 write!(f, " {statements}")?;
4329 }
4330 Ok(())
4331 }
4332}
4333
4334#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4335#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4336#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4337pub struct DropTrigger {
4344 pub if_exists: bool,
4346 pub trigger_name: ObjectName,
4348 pub table_name: Option<ObjectName>,
4350 pub option: Option<ReferentialAction>,
4352}
4353
4354impl fmt::Display for DropTrigger {
4355 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4356 let DropTrigger {
4357 if_exists,
4358 trigger_name,
4359 table_name,
4360 option,
4361 } = self;
4362 write!(f, "DROP TRIGGER")?;
4363 if *if_exists {
4364 write!(f, " IF EXISTS")?;
4365 }
4366 match &table_name {
4367 Some(table_name) => write!(f, " {trigger_name} ON {table_name}")?,
4368 None => write!(f, " {trigger_name}")?,
4369 };
4370 if let Some(option) = option {
4371 write!(f, " {option}")?;
4372 }
4373 Ok(())
4374 }
4375}
4376
4377#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4383#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4384#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4385pub struct Truncate {
4386 pub table_names: Vec<super::TruncateTableTarget>,
4388 pub partitions: Option<Vec<Expr>>,
4390 pub table: bool,
4392 pub if_exists: bool,
4394 pub identity: Option<super::TruncateIdentityOption>,
4396 pub cascade: Option<super::CascadeOption>,
4398 pub on_cluster: Option<Ident>,
4401}
4402
4403impl fmt::Display for Truncate {
4404 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4405 let table = if self.table { "TABLE " } else { "" };
4406 let if_exists = if self.if_exists { "IF EXISTS " } else { "" };
4407
4408 write!(
4409 f,
4410 "TRUNCATE {table}{if_exists}{table_names}",
4411 table_names = display_comma_separated(&self.table_names)
4412 )?;
4413
4414 if let Some(identity) = &self.identity {
4415 match identity {
4416 super::TruncateIdentityOption::Restart => write!(f, " RESTART IDENTITY")?,
4417 super::TruncateIdentityOption::Continue => write!(f, " CONTINUE IDENTITY")?,
4418 }
4419 }
4420 if let Some(cascade) = &self.cascade {
4421 match cascade {
4422 super::CascadeOption::Cascade => write!(f, " CASCADE")?,
4423 super::CascadeOption::Restrict => write!(f, " RESTRICT")?,
4424 }
4425 }
4426
4427 if let Some(ref parts) = &self.partitions {
4428 if !parts.is_empty() {
4429 write!(f, " PARTITION ({})", display_comma_separated(parts))?;
4430 }
4431 }
4432 if let Some(on_cluster) = &self.on_cluster {
4433 write!(f, " ON CLUSTER {on_cluster}")?;
4434 }
4435 Ok(())
4436 }
4437}
4438
4439impl Spanned for Truncate {
4440 fn span(&self) -> Span {
4441 Span::union_iter(
4442 self.table_names.iter().map(|i| i.name.span()).chain(
4443 self.partitions
4444 .iter()
4445 .flat_map(|i| i.iter().map(|k| k.span())),
4446 ),
4447 )
4448 }
4449}
4450
4451#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4458#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4459#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4460pub struct Msck {
4461 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4463 pub table_name: ObjectName,
4464 pub repair: bool,
4466 pub partition_action: Option<super::AddDropSync>,
4468}
4469
4470impl fmt::Display for Msck {
4471 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4472 write!(
4473 f,
4474 "MSCK {repair}TABLE {table}",
4475 repair = if self.repair { "REPAIR " } else { "" },
4476 table = self.table_name
4477 )?;
4478 if let Some(pa) = &self.partition_action {
4479 write!(f, " {pa}")?;
4480 }
4481 Ok(())
4482 }
4483}
4484
4485impl Spanned for Msck {
4486 fn span(&self) -> Span {
4487 self.table_name.span()
4488 }
4489}
4490
4491#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4493#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4494#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4495pub struct CreateView {
4496 pub or_alter: bool,
4500 pub or_replace: bool,
4502 pub materialized: bool,
4504 pub secure: bool,
4507 pub name: ObjectName,
4509 pub name_before_not_exists: bool,
4520 pub columns: Vec<ViewColumnDef>,
4522 pub query: Box<Query>,
4524 pub options: CreateTableOptions,
4526 pub cluster_by: Vec<Ident>,
4528 pub comment: Option<String>,
4531 pub with_no_schema_binding: bool,
4533 pub if_not_exists: bool,
4535 pub temporary: bool,
4537 pub copy_grants: bool,
4540 pub to: Option<ObjectName>,
4543 pub params: Option<CreateViewParams>,
4545 pub with_data: Option<bool>,
4550}
4551
4552impl fmt::Display for CreateView {
4553 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4554 write!(
4555 f,
4556 "CREATE {or_alter}{or_replace}",
4557 or_alter = if self.or_alter { "OR ALTER " } else { "" },
4558 or_replace = if self.or_replace { "OR REPLACE " } else { "" },
4559 )?;
4560 if let Some(ref params) = self.params {
4561 params.fmt(f)?;
4562 }
4563 write!(
4564 f,
4565 "{secure}{materialized}{temporary}VIEW {if_not_and_name}{to}",
4566 if_not_and_name = if self.if_not_exists {
4567 if self.name_before_not_exists {
4568 format!("{} IF NOT EXISTS", self.name)
4569 } else {
4570 format!("IF NOT EXISTS {}", self.name)
4571 }
4572 } else {
4573 format!("{}", self.name)
4574 },
4575 secure = if self.secure { "SECURE " } else { "" },
4576 materialized = if self.materialized {
4577 "MATERIALIZED "
4578 } else {
4579 ""
4580 },
4581 temporary = if self.temporary { "TEMPORARY " } else { "" },
4582 to = self
4583 .to
4584 .as_ref()
4585 .map(|to| format!(" TO {to}"))
4586 .unwrap_or_default()
4587 )?;
4588 if self.copy_grants {
4589 write!(f, " COPY GRANTS")?;
4590 }
4591 if !self.columns.is_empty() {
4592 write!(f, " ({})", display_comma_separated(&self.columns))?;
4593 }
4594 if matches!(self.options, CreateTableOptions::With(_)) {
4595 write!(f, " {}", self.options)?;
4596 }
4597 if let Some(ref comment) = self.comment {
4598 write!(f, " COMMENT = '{}'", escape_single_quote_string(comment))?;
4599 }
4600 if !self.cluster_by.is_empty() {
4601 write!(
4602 f,
4603 " CLUSTER BY ({})",
4604 display_comma_separated(&self.cluster_by)
4605 )?;
4606 }
4607 if matches!(self.options, CreateTableOptions::Options(_)) {
4608 write!(f, " {}", self.options)?;
4609 }
4610 f.write_str(" AS")?;
4611 SpaceOrNewline.fmt(f)?;
4612 self.query.fmt(f)?;
4613 if self.with_no_schema_binding {
4614 write!(f, " WITH NO SCHEMA BINDING")?;
4615 }
4616 match self.with_data {
4617 Some(true) => write!(f, " WITH DATA")?,
4618 Some(false) => write!(f, " WITH NO DATA")?,
4619 None => {}
4620 }
4621 Ok(())
4622 }
4623}
4624
4625#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4628#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4629#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4630pub struct CreateExtension {
4631 pub name: Ident,
4633 pub if_not_exists: bool,
4635 pub cascade: bool,
4637 pub schema: Option<Ident>,
4639 pub version: Option<Ident>,
4641}
4642
4643impl fmt::Display for CreateExtension {
4644 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4645 write!(
4646 f,
4647 "CREATE EXTENSION {if_not_exists}{name}",
4648 if_not_exists = if self.if_not_exists {
4649 "IF NOT EXISTS "
4650 } else {
4651 ""
4652 },
4653 name = self.name
4654 )?;
4655 if self.cascade || self.schema.is_some() || self.version.is_some() {
4656 write!(f, " WITH")?;
4657
4658 if let Some(name) = &self.schema {
4659 write!(f, " SCHEMA {name}")?;
4660 }
4661 if let Some(version) = &self.version {
4662 write!(f, " VERSION {version}")?;
4663 }
4664 if self.cascade {
4665 write!(f, " CASCADE")?;
4666 }
4667 }
4668
4669 Ok(())
4670 }
4671}
4672
4673impl Spanned for CreateExtension {
4674 fn span(&self) -> Span {
4675 Span::empty()
4676 }
4677}
4678
4679#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4687#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4688#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4689pub struct DropExtension {
4690 pub names: Vec<Ident>,
4692 pub if_exists: bool,
4694 pub cascade_or_restrict: Option<ReferentialAction>,
4696}
4697
4698impl fmt::Display for DropExtension {
4699 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4700 write!(f, "DROP EXTENSION")?;
4701 if self.if_exists {
4702 write!(f, " IF EXISTS")?;
4703 }
4704 write!(f, " {}", display_comma_separated(&self.names))?;
4705 if let Some(cascade_or_restrict) = &self.cascade_or_restrict {
4706 write!(f, " {cascade_or_restrict}")?;
4707 }
4708 Ok(())
4709 }
4710}
4711
4712impl Spanned for DropExtension {
4713 fn span(&self) -> Span {
4714 Span::empty()
4715 }
4716}
4717
4718#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4721#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4722#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4723pub struct CreateCollation {
4724 pub if_not_exists: bool,
4726 pub name: ObjectName,
4728 pub definition: CreateCollationDefinition,
4730}
4731
4732#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4734#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4735#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4736pub enum CreateCollationDefinition {
4737 From(ObjectName),
4743 Options(Vec<SqlOption>),
4749}
4750
4751impl fmt::Display for CreateCollation {
4752 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4753 write!(
4754 f,
4755 "CREATE COLLATION {if_not_exists}{name}",
4756 if_not_exists = if self.if_not_exists {
4757 "IF NOT EXISTS "
4758 } else {
4759 ""
4760 },
4761 name = self.name
4762 )?;
4763 match &self.definition {
4764 CreateCollationDefinition::From(existing_collation) => {
4765 write!(f, " FROM {existing_collation}")
4766 }
4767 CreateCollationDefinition::Options(options) => {
4768 write!(f, " ({})", display_comma_separated(options))
4769 }
4770 }
4771 }
4772}
4773
4774impl Spanned for CreateCollation {
4775 fn span(&self) -> Span {
4776 Span::empty()
4777 }
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 AlterCollation {
4786 pub name: ObjectName,
4788 pub operation: AlterCollationOperation,
4790}
4791
4792#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4794#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4795#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4796pub enum AlterCollationOperation {
4797 RenameTo {
4803 new_name: Ident,
4805 },
4806 OwnerTo(Owner),
4812 SetSchema {
4818 schema_name: ObjectName,
4820 },
4821 RefreshVersion,
4827}
4828
4829impl fmt::Display for AlterCollationOperation {
4830 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4831 match self {
4832 AlterCollationOperation::RenameTo { new_name } => write!(f, "RENAME TO {new_name}"),
4833 AlterCollationOperation::OwnerTo(owner) => write!(f, "OWNER TO {owner}"),
4834 AlterCollationOperation::SetSchema { schema_name } => {
4835 write!(f, "SET SCHEMA {schema_name}")
4836 }
4837 AlterCollationOperation::RefreshVersion => write!(f, "REFRESH VERSION"),
4838 }
4839 }
4840}
4841
4842impl fmt::Display for AlterCollation {
4843 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4844 write!(f, "ALTER COLLATION {} {}", self.name, self.operation)
4845 }
4846}
4847
4848impl Spanned for AlterCollation {
4849 fn span(&self) -> Span {
4850 Span::empty()
4851 }
4852}
4853
4854#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4857#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4858#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4859pub enum AlterTableType {
4860 Iceberg,
4863 Dynamic,
4866 External,
4869}
4870
4871#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4873#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4874#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4875pub struct AlterTable {
4876 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
4878 pub name: ObjectName,
4879 pub if_exists: bool,
4881 pub only: bool,
4883 pub operations: Vec<AlterTableOperation>,
4885 pub location: Option<HiveSetLocation>,
4887 pub on_cluster: Option<Ident>,
4891 pub table_type: Option<AlterTableType>,
4893 pub end_token: AttachedToken,
4895}
4896
4897impl fmt::Display for AlterTable {
4898 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4899 match &self.table_type {
4900 Some(AlterTableType::Iceberg) => write!(f, "ALTER ICEBERG TABLE ")?,
4901 Some(AlterTableType::Dynamic) => write!(f, "ALTER DYNAMIC TABLE ")?,
4902 Some(AlterTableType::External) => write!(f, "ALTER EXTERNAL TABLE ")?,
4903 None => write!(f, "ALTER TABLE ")?,
4904 }
4905
4906 if self.if_exists {
4907 write!(f, "IF EXISTS ")?;
4908 }
4909 if self.only {
4910 write!(f, "ONLY ")?;
4911 }
4912 write!(f, "{} ", &self.name)?;
4913 if let Some(cluster) = &self.on_cluster {
4914 write!(f, "ON CLUSTER {cluster} ")?;
4915 }
4916 write!(f, "{}", display_comma_separated(&self.operations))?;
4917 if let Some(loc) = &self.location {
4918 write!(f, " {loc}")?
4919 }
4920 Ok(())
4921 }
4922}
4923
4924#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4926#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4927#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4928pub struct DropFunction {
4929 pub if_exists: bool,
4931 pub func_desc: Vec<FunctionDesc>,
4933 pub drop_behavior: Option<DropBehavior>,
4935}
4936
4937impl fmt::Display for DropFunction {
4938 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4939 write!(
4940 f,
4941 "DROP FUNCTION{} {}",
4942 if self.if_exists { " IF EXISTS" } else { "" },
4943 display_comma_separated(&self.func_desc),
4944 )?;
4945 if let Some(op) = &self.drop_behavior {
4946 write!(f, " {op}")?;
4947 }
4948 Ok(())
4949 }
4950}
4951
4952impl Spanned for DropFunction {
4953 fn span(&self) -> Span {
4954 Span::empty()
4955 }
4956}
4957
4958#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4961#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4962#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4963pub struct CreateOperator {
4964 pub name: ObjectName,
4966 pub function: ObjectName,
4968 pub is_procedure: bool,
4970 pub left_arg: Option<DataType>,
4972 pub right_arg: Option<DataType>,
4974 pub options: Vec<OperatorOption>,
4976}
4977
4978#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4981#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4982#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4983pub struct CreateOperatorFamily {
4984 pub name: ObjectName,
4986 pub using: Ident,
4988}
4989
4990#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4993#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4994#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
4995pub struct CreateOperatorClass {
4996 pub name: ObjectName,
4998 pub default: bool,
5000 pub for_type: DataType,
5002 pub using: Ident,
5004 pub family: Option<ObjectName>,
5006 pub items: Vec<OperatorClassItem>,
5008}
5009
5010impl fmt::Display for CreateOperator {
5011 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5012 write!(f, "CREATE OPERATOR {} (", self.name)?;
5013
5014 let function_keyword = if self.is_procedure {
5015 "PROCEDURE"
5016 } else {
5017 "FUNCTION"
5018 };
5019 let mut params = vec![format!("{} = {}", function_keyword, self.function)];
5020
5021 if let Some(left_arg) = &self.left_arg {
5022 params.push(format!("LEFTARG = {}", left_arg));
5023 }
5024 if let Some(right_arg) = &self.right_arg {
5025 params.push(format!("RIGHTARG = {}", right_arg));
5026 }
5027
5028 for option in &self.options {
5029 params.push(option.to_string());
5030 }
5031
5032 write!(f, "{}", params.join(", "))?;
5033 write!(f, ")")
5034 }
5035}
5036
5037impl fmt::Display for CreateOperatorFamily {
5038 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5039 write!(
5040 f,
5041 "CREATE OPERATOR FAMILY {} USING {}",
5042 self.name, self.using
5043 )
5044 }
5045}
5046
5047impl fmt::Display for CreateOperatorClass {
5048 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5049 write!(f, "CREATE OPERATOR CLASS {}", self.name)?;
5050 if self.default {
5051 write!(f, " DEFAULT")?;
5052 }
5053 write!(f, " FOR TYPE {} USING {}", self.for_type, self.using)?;
5054 if let Some(family) = &self.family {
5055 write!(f, " FAMILY {}", family)?;
5056 }
5057 write!(f, " AS {}", display_comma_separated(&self.items))
5058 }
5059}
5060
5061#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5063#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5064#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5065pub struct OperatorArgTypes {
5066 pub left: DataType,
5068 pub right: DataType,
5070}
5071
5072impl fmt::Display for OperatorArgTypes {
5073 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5074 write!(f, "{}, {}", self.left, self.right)
5075 }
5076}
5077
5078#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5080#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5081#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5082pub enum OperatorClassItem {
5083 Operator {
5085 strategy_number: u64,
5087 operator_name: ObjectName,
5089 op_types: Option<OperatorArgTypes>,
5091 purpose: Option<OperatorPurpose>,
5093 },
5094 Function {
5096 support_number: u64,
5098 op_types: Option<Vec<DataType>>,
5100 function_name: ObjectName,
5102 argument_types: Vec<DataType>,
5104 },
5105 Storage {
5107 storage_type: DataType,
5109 },
5110}
5111
5112#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5114#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5115#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5116pub enum OperatorPurpose {
5117 ForSearch,
5119 ForOrderBy {
5121 sort_family: ObjectName,
5123 },
5124}
5125
5126impl fmt::Display for OperatorClassItem {
5127 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5128 match self {
5129 OperatorClassItem::Operator {
5130 strategy_number,
5131 operator_name,
5132 op_types,
5133 purpose,
5134 } => {
5135 write!(f, "OPERATOR {strategy_number} {operator_name}")?;
5136 if let Some(types) = op_types {
5137 write!(f, " ({types})")?;
5138 }
5139 if let Some(purpose) = purpose {
5140 write!(f, " {purpose}")?;
5141 }
5142 Ok(())
5143 }
5144 OperatorClassItem::Function {
5145 support_number,
5146 op_types,
5147 function_name,
5148 argument_types,
5149 } => {
5150 write!(f, "FUNCTION {support_number}")?;
5151 if let Some(types) = op_types {
5152 write!(f, " ({})", display_comma_separated(types))?;
5153 }
5154 write!(f, " {function_name}")?;
5155 if !argument_types.is_empty() {
5156 write!(f, "({})", display_comma_separated(argument_types))?;
5157 }
5158 Ok(())
5159 }
5160 OperatorClassItem::Storage { storage_type } => {
5161 write!(f, "STORAGE {storage_type}")
5162 }
5163 }
5164 }
5165}
5166
5167impl fmt::Display for OperatorPurpose {
5168 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5169 match self {
5170 OperatorPurpose::ForSearch => write!(f, "FOR SEARCH"),
5171 OperatorPurpose::ForOrderBy { sort_family } => {
5172 write!(f, "FOR ORDER BY {sort_family}")
5173 }
5174 }
5175 }
5176}
5177
5178#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5181#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5182#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5183pub struct DropOperator {
5184 pub if_exists: bool,
5186 pub operators: Vec<DropOperatorSignature>,
5188 pub drop_behavior: Option<DropBehavior>,
5190}
5191
5192#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5194#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5195#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5196pub struct DropOperatorSignature {
5197 pub name: ObjectName,
5199 pub left_type: Option<DataType>,
5201 pub right_type: DataType,
5203}
5204
5205impl fmt::Display for DropOperatorSignature {
5206 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5207 write!(f, "{} (", self.name)?;
5208 if let Some(left_type) = &self.left_type {
5209 write!(f, "{}", left_type)?;
5210 } else {
5211 write!(f, "NONE")?;
5212 }
5213 write!(f, ", {})", self.right_type)
5214 }
5215}
5216
5217impl fmt::Display for DropOperator {
5218 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5219 write!(f, "DROP OPERATOR")?;
5220 if self.if_exists {
5221 write!(f, " IF EXISTS")?;
5222 }
5223 write!(f, " {}", display_comma_separated(&self.operators))?;
5224 if let Some(drop_behavior) = &self.drop_behavior {
5225 write!(f, " {}", drop_behavior)?;
5226 }
5227 Ok(())
5228 }
5229}
5230
5231impl Spanned for DropOperator {
5232 fn span(&self) -> Span {
5233 Span::empty()
5234 }
5235}
5236
5237#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5240#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5241#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5242pub struct DropOperatorFamily {
5243 pub if_exists: bool,
5245 pub names: Vec<ObjectName>,
5247 pub using: Ident,
5249 pub drop_behavior: Option<DropBehavior>,
5251}
5252
5253impl fmt::Display for DropOperatorFamily {
5254 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5255 write!(f, "DROP OPERATOR FAMILY")?;
5256 if self.if_exists {
5257 write!(f, " IF EXISTS")?;
5258 }
5259 write!(f, " {}", display_comma_separated(&self.names))?;
5260 write!(f, " USING {}", self.using)?;
5261 if let Some(drop_behavior) = &self.drop_behavior {
5262 write!(f, " {}", drop_behavior)?;
5263 }
5264 Ok(())
5265 }
5266}
5267
5268impl Spanned for DropOperatorFamily {
5269 fn span(&self) -> Span {
5270 Span::empty()
5271 }
5272}
5273
5274#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5277#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5278#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5279pub struct DropOperatorClass {
5280 pub if_exists: bool,
5282 pub names: Vec<ObjectName>,
5284 pub using: Ident,
5286 pub drop_behavior: Option<DropBehavior>,
5288}
5289
5290impl fmt::Display for DropOperatorClass {
5291 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5292 write!(f, "DROP OPERATOR CLASS")?;
5293 if self.if_exists {
5294 write!(f, " IF EXISTS")?;
5295 }
5296 write!(f, " {}", display_comma_separated(&self.names))?;
5297 write!(f, " USING {}", self.using)?;
5298 if let Some(drop_behavior) = &self.drop_behavior {
5299 write!(f, " {}", drop_behavior)?;
5300 }
5301 Ok(())
5302 }
5303}
5304
5305impl Spanned for DropOperatorClass {
5306 fn span(&self) -> Span {
5307 Span::empty()
5308 }
5309}
5310
5311#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5313#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5314#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5315pub enum OperatorFamilyItem {
5316 Operator {
5318 strategy_number: u64,
5320 operator_name: ObjectName,
5322 op_types: Vec<DataType>,
5324 purpose: Option<OperatorPurpose>,
5326 },
5327 Function {
5329 support_number: u64,
5331 op_types: Option<Vec<DataType>>,
5333 function_name: ObjectName,
5335 argument_types: Vec<DataType>,
5337 },
5338}
5339
5340#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5342#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5343#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5344pub enum OperatorFamilyDropItem {
5345 Operator {
5347 strategy_number: u64,
5349 op_types: Vec<DataType>,
5351 },
5352 Function {
5354 support_number: u64,
5356 op_types: Vec<DataType>,
5358 },
5359}
5360
5361impl fmt::Display for OperatorFamilyItem {
5362 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5363 match self {
5364 OperatorFamilyItem::Operator {
5365 strategy_number,
5366 operator_name,
5367 op_types,
5368 purpose,
5369 } => {
5370 write!(
5371 f,
5372 "OPERATOR {strategy_number} {operator_name} ({})",
5373 display_comma_separated(op_types)
5374 )?;
5375 if let Some(purpose) = purpose {
5376 write!(f, " {purpose}")?;
5377 }
5378 Ok(())
5379 }
5380 OperatorFamilyItem::Function {
5381 support_number,
5382 op_types,
5383 function_name,
5384 argument_types,
5385 } => {
5386 write!(f, "FUNCTION {support_number}")?;
5387 if let Some(types) = op_types {
5388 write!(f, " ({})", display_comma_separated(types))?;
5389 }
5390 write!(f, " {function_name}")?;
5391 if !argument_types.is_empty() {
5392 write!(f, "({})", display_comma_separated(argument_types))?;
5393 }
5394 Ok(())
5395 }
5396 }
5397 }
5398}
5399
5400impl fmt::Display for OperatorFamilyDropItem {
5401 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5402 match self {
5403 OperatorFamilyDropItem::Operator {
5404 strategy_number,
5405 op_types,
5406 } => {
5407 write!(
5408 f,
5409 "OPERATOR {strategy_number} ({})",
5410 display_comma_separated(op_types)
5411 )
5412 }
5413 OperatorFamilyDropItem::Function {
5414 support_number,
5415 op_types,
5416 } => {
5417 write!(
5418 f,
5419 "FUNCTION {support_number} ({})",
5420 display_comma_separated(op_types)
5421 )
5422 }
5423 }
5424 }
5425}
5426
5427#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5430#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5431#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5432pub struct AlterOperatorFamily {
5433 pub name: ObjectName,
5435 pub using: Ident,
5437 pub operation: AlterOperatorFamilyOperation,
5439}
5440
5441#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5443#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5444#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5445pub enum AlterOperatorFamilyOperation {
5446 Add {
5448 items: Vec<OperatorFamilyItem>,
5450 },
5451 Drop {
5453 items: Vec<OperatorFamilyDropItem>,
5455 },
5456 RenameTo {
5458 new_name: ObjectName,
5460 },
5461 OwnerTo(Owner),
5463 SetSchema {
5465 schema_name: ObjectName,
5467 },
5468}
5469
5470impl fmt::Display for AlterOperatorFamily {
5471 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5472 write!(
5473 f,
5474 "ALTER OPERATOR FAMILY {} USING {}",
5475 self.name, self.using
5476 )?;
5477 write!(f, " {}", self.operation)
5478 }
5479}
5480
5481impl fmt::Display for AlterOperatorFamilyOperation {
5482 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5483 match self {
5484 AlterOperatorFamilyOperation::Add { items } => {
5485 write!(f, "ADD {}", display_comma_separated(items))
5486 }
5487 AlterOperatorFamilyOperation::Drop { items } => {
5488 write!(f, "DROP {}", display_comma_separated(items))
5489 }
5490 AlterOperatorFamilyOperation::RenameTo { new_name } => {
5491 write!(f, "RENAME TO {new_name}")
5492 }
5493 AlterOperatorFamilyOperation::OwnerTo(owner) => {
5494 write!(f, "OWNER TO {owner}")
5495 }
5496 AlterOperatorFamilyOperation::SetSchema { schema_name } => {
5497 write!(f, "SET SCHEMA {schema_name}")
5498 }
5499 }
5500 }
5501}
5502
5503impl Spanned for AlterOperatorFamily {
5504 fn span(&self) -> Span {
5505 Span::empty()
5506 }
5507}
5508
5509#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5512#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5513#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5514pub struct AlterOperatorClass {
5515 pub name: ObjectName,
5517 pub using: Ident,
5519 pub operation: AlterOperatorClassOperation,
5521}
5522
5523#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5525#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5526#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5527pub enum AlterOperatorClassOperation {
5528 RenameTo {
5531 new_name: ObjectName,
5533 },
5534 OwnerTo(Owner),
5536 SetSchema {
5539 schema_name: ObjectName,
5541 },
5542}
5543
5544impl fmt::Display for AlterOperatorClass {
5545 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5546 write!(f, "ALTER OPERATOR CLASS {} USING {}", self.name, self.using)?;
5547 write!(f, " {}", self.operation)
5548 }
5549}
5550
5551impl fmt::Display for AlterOperatorClassOperation {
5552 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5553 match self {
5554 AlterOperatorClassOperation::RenameTo { new_name } => {
5555 write!(f, "RENAME TO {new_name}")
5556 }
5557 AlterOperatorClassOperation::OwnerTo(owner) => {
5558 write!(f, "OWNER TO {owner}")
5559 }
5560 AlterOperatorClassOperation::SetSchema { schema_name } => {
5561 write!(f, "SET SCHEMA {schema_name}")
5562 }
5563 }
5564 }
5565}
5566
5567impl Spanned for AlterOperatorClass {
5568 fn span(&self) -> Span {
5569 Span::empty()
5570 }
5571}
5572
5573#[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 AlterFunction {
5578 pub kind: AlterFunctionKind,
5580 pub function: FunctionDesc,
5582 pub aggregate_order_by: Option<Vec<OperateFunctionArg>>,
5586 pub aggregate_star: bool,
5590 pub operation: AlterFunctionOperation,
5592}
5593
5594#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5596#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5597#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5598pub enum AlterFunctionKind {
5599 Function,
5601 Aggregate,
5603 Procedure,
5605}
5606
5607impl fmt::Display for AlterFunctionKind {
5608 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5609 match self {
5610 Self::Function => write!(f, "FUNCTION"),
5611 Self::Aggregate => write!(f, "AGGREGATE"),
5612 Self::Procedure => write!(f, "PROCEDURE"),
5613 }
5614 }
5615}
5616
5617#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5619#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5620#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5621pub enum AlterFunctionOperation {
5622 RenameTo {
5624 new_name: Ident,
5626 },
5627 OwnerTo(Owner),
5629 SetSchema {
5631 schema_name: ObjectName,
5633 },
5634 DependsOnExtension {
5636 no: bool,
5638 extension_name: ObjectName,
5640 },
5641 Actions {
5643 actions: Vec<AlterFunctionAction>,
5645 restrict: bool,
5647 },
5648}
5649
5650#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5652#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5653#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5654pub enum AlterFunctionAction {
5655 CalledOnNull(FunctionCalledOnNull),
5657 Behavior(FunctionBehavior),
5659 Leakproof(bool),
5661 Security {
5663 external: bool,
5665 security: FunctionSecurity,
5667 },
5668 Parallel(FunctionParallel),
5670 Cost(Expr),
5672 Rows(Expr),
5674 Support(ObjectName),
5676 Set(FunctionDefinitionSetParam),
5679 Reset(ResetConfig),
5681}
5682
5683impl fmt::Display for AlterFunction {
5684 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5685 write!(f, "ALTER {} ", self.kind)?;
5686 match self.kind {
5687 AlterFunctionKind::Function | AlterFunctionKind::Procedure => {
5688 write!(f, "{} ", self.function)?;
5689 }
5690 AlterFunctionKind::Aggregate => {
5691 write!(f, "{}(", self.function.name)?;
5692 if self.aggregate_star {
5693 write!(f, "*")?;
5694 } else {
5695 if let Some(args) = &self.function.args {
5696 write!(f, "{}", display_comma_separated(args))?;
5697 }
5698 if let Some(order_by_args) = &self.aggregate_order_by {
5699 if self
5700 .function
5701 .args
5702 .as_ref()
5703 .is_some_and(|args| !args.is_empty())
5704 {
5705 write!(f, " ")?;
5706 }
5707 write!(f, "ORDER BY {}", display_comma_separated(order_by_args))?;
5708 }
5709 }
5710 write!(f, ") ")?;
5711 }
5712 }
5713 write!(f, "{}", self.operation)
5714 }
5715}
5716
5717impl fmt::Display for AlterFunctionOperation {
5718 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5719 match self {
5720 AlterFunctionOperation::RenameTo { new_name } => {
5721 write!(f, "RENAME TO {new_name}")
5722 }
5723 AlterFunctionOperation::OwnerTo(owner) => write!(f, "OWNER TO {owner}"),
5724 AlterFunctionOperation::SetSchema { schema_name } => {
5725 write!(f, "SET SCHEMA {schema_name}")
5726 }
5727 AlterFunctionOperation::DependsOnExtension { no, extension_name } => {
5728 if *no {
5729 write!(f, "NO DEPENDS ON EXTENSION {extension_name}")
5730 } else {
5731 write!(f, "DEPENDS ON EXTENSION {extension_name}")
5732 }
5733 }
5734 AlterFunctionOperation::Actions { actions, restrict } => {
5735 write!(f, "{}", display_separated(actions, " "))?;
5736 if *restrict {
5737 write!(f, " RESTRICT")?;
5738 }
5739 Ok(())
5740 }
5741 }
5742 }
5743}
5744
5745impl fmt::Display for AlterFunctionAction {
5746 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5747 match self {
5748 AlterFunctionAction::CalledOnNull(called_on_null) => write!(f, "{called_on_null}"),
5749 AlterFunctionAction::Behavior(behavior) => write!(f, "{behavior}"),
5750 AlterFunctionAction::Leakproof(leakproof) => {
5751 if *leakproof {
5752 write!(f, "LEAKPROOF")
5753 } else {
5754 write!(f, "NOT LEAKPROOF")
5755 }
5756 }
5757 AlterFunctionAction::Security { external, security } => {
5758 if *external {
5759 write!(f, "EXTERNAL ")?;
5760 }
5761 write!(f, "{security}")
5762 }
5763 AlterFunctionAction::Parallel(parallel) => write!(f, "{parallel}"),
5764 AlterFunctionAction::Cost(execution_cost) => write!(f, "COST {execution_cost}"),
5765 AlterFunctionAction::Rows(result_rows) => write!(f, "ROWS {result_rows}"),
5766 AlterFunctionAction::Support(support_function) => {
5767 write!(f, "SUPPORT {support_function}")
5768 }
5769 AlterFunctionAction::Set(set_param) => write!(f, "{set_param}"),
5770 AlterFunctionAction::Reset(reset_config) => match reset_config {
5771 ResetConfig::ALL => write!(f, "RESET ALL"),
5772 ResetConfig::ConfigName(name) => write!(f, "RESET {name}"),
5773 },
5774 }
5775 }
5776}
5777
5778impl Spanned for AlterFunction {
5779 fn span(&self) -> Span {
5780 Span::empty()
5781 }
5782}
5783
5784#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5788#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5789#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5790pub struct CreatePolicy {
5791 pub name: Ident,
5793 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
5795 pub table_name: ObjectName,
5796 pub policy_type: Option<CreatePolicyType>,
5798 pub command: Option<CreatePolicyCommand>,
5800 pub to: Option<Vec<Owner>>,
5802 pub using: Option<Expr>,
5804 pub with_check: Option<Expr>,
5806}
5807
5808impl fmt::Display for CreatePolicy {
5809 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5810 write!(
5811 f,
5812 "CREATE POLICY {name} ON {table_name}",
5813 name = self.name,
5814 table_name = self.table_name,
5815 )?;
5816 if let Some(ref policy_type) = self.policy_type {
5817 write!(f, " AS {policy_type}")?;
5818 }
5819 if let Some(ref command) = self.command {
5820 write!(f, " FOR {command}")?;
5821 }
5822 if let Some(ref to) = self.to {
5823 write!(f, " TO {}", display_comma_separated(to))?;
5824 }
5825 if let Some(ref using) = self.using {
5826 write!(f, " USING ({using})")?;
5827 }
5828 if let Some(ref with_check) = self.with_check {
5829 write!(f, " WITH CHECK ({with_check})")?;
5830 }
5831 Ok(())
5832 }
5833}
5834
5835#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
5841#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5842#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5843pub enum CreatePolicyType {
5844 Permissive,
5846 Restrictive,
5848}
5849
5850impl fmt::Display for CreatePolicyType {
5851 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5852 match self {
5853 CreatePolicyType::Permissive => write!(f, "PERMISSIVE"),
5854 CreatePolicyType::Restrictive => write!(f, "RESTRICTIVE"),
5855 }
5856 }
5857}
5858
5859#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
5865#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5866#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5867pub enum CreatePolicyCommand {
5868 All,
5870 Select,
5872 Insert,
5874 Update,
5876 Delete,
5878}
5879
5880impl fmt::Display for CreatePolicyCommand {
5881 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5882 match self {
5883 CreatePolicyCommand::All => write!(f, "ALL"),
5884 CreatePolicyCommand::Select => write!(f, "SELECT"),
5885 CreatePolicyCommand::Insert => write!(f, "INSERT"),
5886 CreatePolicyCommand::Update => write!(f, "UPDATE"),
5887 CreatePolicyCommand::Delete => write!(f, "DELETE"),
5888 }
5889 }
5890}
5891
5892#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5896#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5897#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5898pub struct DropPolicy {
5899 pub if_exists: bool,
5901 pub name: Ident,
5903 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
5905 pub table_name: ObjectName,
5906 pub drop_behavior: Option<DropBehavior>,
5908}
5909
5910impl fmt::Display for DropPolicy {
5911 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5912 write!(
5913 f,
5914 "DROP POLICY {if_exists}{name} ON {table_name}",
5915 if_exists = if self.if_exists { "IF EXISTS " } else { "" },
5916 name = self.name,
5917 table_name = self.table_name
5918 )?;
5919 if let Some(ref behavior) = self.drop_behavior {
5920 write!(f, " {behavior}")?;
5921 }
5922 Ok(())
5923 }
5924}
5925
5926impl From<CreatePolicy> for crate::ast::Statement {
5927 fn from(v: CreatePolicy) -> Self {
5928 crate::ast::Statement::CreatePolicy(v)
5929 }
5930}
5931
5932impl From<DropPolicy> for crate::ast::Statement {
5933 fn from(v: DropPolicy) -> Self {
5934 crate::ast::Statement::DropPolicy(v)
5935 }
5936}
5937
5938#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5945#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5946#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5947pub struct AlterPolicy {
5948 pub name: Ident,
5950 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
5952 pub table_name: ObjectName,
5953 pub operation: AlterPolicyOperation,
5955}
5956
5957impl fmt::Display for AlterPolicy {
5958 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5959 write!(
5960 f,
5961 "ALTER POLICY {name} ON {table_name}{operation}",
5962 name = self.name,
5963 table_name = self.table_name,
5964 operation = self.operation
5965 )
5966 }
5967}
5968
5969impl From<AlterPolicy> for crate::ast::Statement {
5970 fn from(v: AlterPolicy) -> Self {
5971 crate::ast::Statement::AlterPolicy(v)
5972 }
5973}
5974
5975#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5979#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5980#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5981pub enum FdwRoutineClause {
5982 Function(ObjectName),
5984 NoFunction,
5986}
5987
5988#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
5992#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5993#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
5994pub struct CreateForeignDataWrapper {
5995 pub name: Ident,
5997 pub handler: Option<FdwRoutineClause>,
5999 pub validator: Option<FdwRoutineClause>,
6001 pub options: Option<Vec<CreateServerOption>>,
6003}
6004
6005impl fmt::Display for CreateForeignDataWrapper {
6006 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6007 write!(f, "CREATE FOREIGN DATA WRAPPER {}", self.name)?;
6008 if let Some(handler) = &self.handler {
6009 match handler {
6010 FdwRoutineClause::Function(name) => write!(f, " HANDLER {name}")?,
6011 FdwRoutineClause::NoFunction => write!(f, " NO HANDLER")?,
6012 }
6013 }
6014 if let Some(validator) = &self.validator {
6015 match validator {
6016 FdwRoutineClause::Function(name) => write!(f, " VALIDATOR {name}")?,
6017 FdwRoutineClause::NoFunction => write!(f, " NO VALIDATOR")?,
6018 }
6019 }
6020 if let Some(options) = &self.options {
6021 write!(f, " OPTIONS ({})", display_comma_separated(options))?;
6022 }
6023 Ok(())
6024 }
6025}
6026
6027impl From<CreateForeignDataWrapper> for crate::ast::Statement {
6028 fn from(v: CreateForeignDataWrapper) -> Self {
6029 crate::ast::Statement::CreateForeignDataWrapper(v)
6030 }
6031}
6032
6033#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6037#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6038#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6039pub struct CreateForeignTable {
6040 #[cfg_attr(feature = "visitor", visit(with = "visit_relation"))]
6042 pub name: ObjectName,
6043 pub if_not_exists: bool,
6045 pub columns: Vec<ColumnDef>,
6047 pub server_name: Ident,
6049 pub options: Option<Vec<CreateServerOption>>,
6051}
6052
6053impl fmt::Display for CreateForeignTable {
6054 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6055 write!(
6056 f,
6057 "CREATE FOREIGN TABLE {if_not_exists}{name} ({columns}) SERVER {server_name}",
6058 if_not_exists = if self.if_not_exists {
6059 "IF NOT EXISTS "
6060 } else {
6061 ""
6062 },
6063 name = self.name,
6064 columns = display_comma_separated(&self.columns),
6065 server_name = self.server_name,
6066 )?;
6067 if let Some(options) = &self.options {
6068 write!(f, " OPTIONS ({})", display_comma_separated(options))?;
6069 }
6070 Ok(())
6071 }
6072}
6073
6074impl From<CreateForeignTable> for crate::ast::Statement {
6075 fn from(v: CreateForeignTable) -> Self {
6076 crate::ast::Statement::CreateForeignTable(v)
6077 }
6078}
6079
6080#[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 CreateAggregate {
6086 pub or_replace: bool,
6088 pub name: ObjectName,
6090 pub args: Vec<DataType>,
6092 pub options: Vec<CreateAggregateOption>,
6095}
6096
6097impl fmt::Display for CreateAggregate {
6098 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6099 write!(f, "CREATE")?;
6100 if self.or_replace {
6101 write!(f, " OR REPLACE")?;
6102 }
6103 write!(f, " AGGREGATE {}", self.name)?;
6104 write!(f, " ({})", display_comma_separated(&self.args))?;
6105 write!(f, " (")?;
6106 for (i, option) in self.options.iter().enumerate() {
6107 if i > 0 {
6108 write!(f, ", ")?;
6109 }
6110 write!(f, "{option}")?;
6111 }
6112 write!(f, ")")
6113 }
6114}
6115
6116impl From<CreateAggregate> for crate::ast::Statement {
6117 fn from(v: CreateAggregate) -> Self {
6118 crate::ast::Statement::CreateAggregate(v)
6119 }
6120}
6121
6122#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6126#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6127#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6128pub enum CreateAggregateOption {
6129 Sfunc(ObjectName),
6131 Stype(DataType),
6133 Sspace(u64),
6135 Finalfunc(ObjectName),
6137 FinalfuncExtra,
6139 FinalfuncModify(AggregateModifyKind),
6141 Combinefunc(ObjectName),
6143 Serialfunc(ObjectName),
6145 Deserialfunc(ObjectName),
6147 Initcond(Value),
6149 Msfunc(ObjectName),
6151 Minvfunc(ObjectName),
6153 Mstype(DataType),
6155 Msspace(u64),
6157 Mfinalfunc(ObjectName),
6159 MfinalfuncExtra,
6161 MfinalfuncModify(AggregateModifyKind),
6163 Minitcond(Value),
6165 Sortop(ObjectName),
6167 Parallel(FunctionParallel),
6169 Hypothetical,
6171}
6172
6173impl fmt::Display for CreateAggregateOption {
6174 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6175 match self {
6176 Self::Sfunc(name) => write!(f, "SFUNC = {name}"),
6177 Self::Stype(data_type) => write!(f, "STYPE = {data_type}"),
6178 Self::Sspace(size) => write!(f, "SSPACE = {size}"),
6179 Self::Finalfunc(name) => write!(f, "FINALFUNC = {name}"),
6180 Self::FinalfuncExtra => write!(f, "FINALFUNC_EXTRA"),
6181 Self::FinalfuncModify(kind) => write!(f, "FINALFUNC_MODIFY = {kind}"),
6182 Self::Combinefunc(name) => write!(f, "COMBINEFUNC = {name}"),
6183 Self::Serialfunc(name) => write!(f, "SERIALFUNC = {name}"),
6184 Self::Deserialfunc(name) => write!(f, "DESERIALFUNC = {name}"),
6185 Self::Initcond(cond) => write!(f, "INITCOND = {cond}"),
6186 Self::Msfunc(name) => write!(f, "MSFUNC = {name}"),
6187 Self::Minvfunc(name) => write!(f, "MINVFUNC = {name}"),
6188 Self::Mstype(data_type) => write!(f, "MSTYPE = {data_type}"),
6189 Self::Msspace(size) => write!(f, "MSSPACE = {size}"),
6190 Self::Mfinalfunc(name) => write!(f, "MFINALFUNC = {name}"),
6191 Self::MfinalfuncExtra => write!(f, "MFINALFUNC_EXTRA"),
6192 Self::MfinalfuncModify(kind) => write!(f, "MFINALFUNC_MODIFY = {kind}"),
6193 Self::Minitcond(cond) => write!(f, "MINITCOND = {cond}"),
6194 Self::Sortop(name) => write!(f, "SORTOP = {name}"),
6195 Self::Parallel(parallel) => {
6196 let kind = match parallel {
6197 FunctionParallel::Safe => "SAFE",
6198 FunctionParallel::Restricted => "RESTRICTED",
6199 FunctionParallel::Unsafe => "UNSAFE",
6200 };
6201 write!(f, "PARALLEL = {kind}")
6202 }
6203 Self::Hypothetical => write!(f, "HYPOTHETICAL"),
6204 }
6205 }
6206}
6207
6208#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6212#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6213#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6214pub enum AggregateModifyKind {
6215 ReadOnly,
6217 Shareable,
6219 ReadWrite,
6221}
6222
6223impl fmt::Display for AggregateModifyKind {
6224 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6225 match self {
6226 Self::ReadOnly => write!(f, "READ_ONLY"),
6227 Self::Shareable => write!(f, "SHAREABLE"),
6228 Self::ReadWrite => write!(f, "READ_WRITE"),
6229 }
6230 }
6231}
6232
6233#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6238#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6239#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6240pub struct CreateTextSearchConfiguration {
6241 pub name: ObjectName,
6243 pub options: Vec<SqlOption>,
6245}
6246
6247impl fmt::Display for CreateTextSearchConfiguration {
6248 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6249 write!(
6250 f,
6251 "CREATE TEXT SEARCH CONFIGURATION {name} ({options})",
6252 name = self.name,
6253 options = display_comma_separated(&self.options),
6254 )
6255 }
6256}
6257
6258impl From<CreateTextSearchConfiguration> for crate::ast::Statement {
6259 fn from(v: CreateTextSearchConfiguration) -> Self {
6260 crate::ast::Statement::CreateTextSearchConfiguration(v)
6261 }
6262}
6263
6264#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6269#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6270#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6271pub struct CreateTextSearchDictionary {
6272 pub name: ObjectName,
6274 pub options: Vec<SqlOption>,
6276}
6277
6278impl fmt::Display for CreateTextSearchDictionary {
6279 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6280 write!(
6281 f,
6282 "CREATE TEXT SEARCH DICTIONARY {name} ({options})",
6283 name = self.name,
6284 options = display_comma_separated(&self.options),
6285 )
6286 }
6287}
6288
6289impl From<CreateTextSearchDictionary> for crate::ast::Statement {
6290 fn from(v: CreateTextSearchDictionary) -> Self {
6291 crate::ast::Statement::CreateTextSearchDictionary(v)
6292 }
6293}
6294
6295#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6300#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6301#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6302pub struct CreateTextSearchParser {
6303 pub name: ObjectName,
6305 pub options: Vec<SqlOption>,
6307}
6308
6309impl fmt::Display for CreateTextSearchParser {
6310 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6311 write!(
6312 f,
6313 "CREATE TEXT SEARCH PARSER {name} ({options})",
6314 name = self.name,
6315 options = display_comma_separated(&self.options),
6316 )
6317 }
6318}
6319
6320impl From<CreateTextSearchParser> for crate::ast::Statement {
6321 fn from(v: CreateTextSearchParser) -> Self {
6322 crate::ast::Statement::CreateTextSearchParser(v)
6323 }
6324}
6325
6326#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6331#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6332#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6333pub struct CreateTextSearchTemplate {
6334 pub name: ObjectName,
6336 pub options: Vec<SqlOption>,
6338}
6339
6340impl fmt::Display for CreateTextSearchTemplate {
6341 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6342 write!(
6343 f,
6344 "CREATE TEXT SEARCH TEMPLATE {name} ({options})",
6345 name = self.name,
6346 options = display_comma_separated(&self.options),
6347 )
6348 }
6349}
6350
6351impl From<CreateTextSearchTemplate> for crate::ast::Statement {
6352 fn from(v: CreateTextSearchTemplate) -> Self {
6353 crate::ast::Statement::CreateTextSearchTemplate(v)
6354 }
6355}
6356
6357#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6361#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6362#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6363pub struct AlterDomain {
6364 pub name: ObjectName,
6366 pub operation: AlterDomainOperation,
6368}
6369
6370#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6372#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6373#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6374pub enum AlterDomainOperation {
6375 AddConstraint {
6377 constraint: TableConstraint,
6379 not_valid: bool,
6381 },
6382 DropConstraint {
6384 if_exists: bool,
6386 name: Ident,
6388 drop_behavior: Option<DropBehavior>,
6390 },
6391 RenameConstraint {
6393 old_name: Ident,
6395 new_name: Ident,
6397 },
6398 OwnerTo(Owner),
6400 RenameTo {
6402 new_name: Ident,
6404 },
6405 SetSchema {
6407 schema_name: ObjectName,
6409 },
6410 SetDefault {
6412 default: Expr,
6414 },
6415 DropDefault,
6417 ValidateConstraint {
6419 name: Ident,
6421 },
6422}
6423
6424impl fmt::Display for AlterDomain {
6425 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6426 write!(f, "ALTER DOMAIN {} {}", self.name, self.operation)
6427 }
6428}
6429
6430impl fmt::Display for AlterDomainOperation {
6431 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6432 match self {
6433 AlterDomainOperation::AddConstraint {
6434 constraint,
6435 not_valid,
6436 } => {
6437 write!(f, "ADD {constraint}")?;
6438 if *not_valid {
6439 write!(f, " NOT VALID")?;
6440 }
6441 Ok(())
6442 }
6443 AlterDomainOperation::DropConstraint {
6444 if_exists,
6445 name,
6446 drop_behavior,
6447 } => {
6448 write!(f, "DROP CONSTRAINT")?;
6449 if *if_exists {
6450 write!(f, " IF EXISTS")?;
6451 }
6452 write!(f, " {name}")?;
6453 if let Some(behavior) = drop_behavior {
6454 write!(f, " {behavior}")?;
6455 }
6456 Ok(())
6457 }
6458 AlterDomainOperation::RenameConstraint { old_name, new_name } => {
6459 write!(f, "RENAME CONSTRAINT {old_name} TO {new_name}")
6460 }
6461 AlterDomainOperation::OwnerTo(owner) => write!(f, "OWNER TO {owner}"),
6462 AlterDomainOperation::RenameTo { new_name } => write!(f, "RENAME TO {new_name}"),
6463 AlterDomainOperation::SetSchema { schema_name } => {
6464 write!(f, "SET SCHEMA {schema_name}")
6465 }
6466 AlterDomainOperation::SetDefault { default } => write!(f, "SET DEFAULT {default}"),
6467 AlterDomainOperation::DropDefault => write!(f, "DROP DEFAULT"),
6468 AlterDomainOperation::ValidateConstraint { name } => {
6469 write!(f, "VALIDATE CONSTRAINT {name}")
6470 }
6471 }
6472 }
6473}
6474
6475#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6479#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6480#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6481pub enum PublicationTarget {
6482 AllTables,
6484 Tables(Vec<ObjectName>),
6486 TablesInSchema(Vec<Ident>),
6488}
6489
6490impl fmt::Display for PublicationTarget {
6491 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6492 match self {
6493 PublicationTarget::AllTables => write!(f, "FOR ALL TABLES"),
6494 PublicationTarget::Tables(tables) => {
6495 write!(f, "FOR TABLE {}", display_comma_separated(tables))
6496 }
6497 PublicationTarget::TablesInSchema(schemas) => {
6498 write!(
6499 f,
6500 "FOR TABLES IN SCHEMA {}",
6501 display_comma_separated(schemas)
6502 )
6503 }
6504 }
6505 }
6506}
6507
6508impl From<AlterDomain> for crate::ast::Statement {
6509 fn from(a: AlterDomain) -> Self {
6510 crate::ast::Statement::AlterDomain(a)
6511 }
6512}
6513
6514#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6518#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6519#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6520pub struct AlterTrigger {
6521 pub name: Ident,
6523 pub table_name: ObjectName,
6525 pub operation: AlterTriggerOperation,
6527}
6528
6529#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6531#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6532#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6533pub enum AlterTriggerOperation {
6534 RenameTo {
6536 new_name: Ident,
6538 },
6539}
6540
6541impl fmt::Display for AlterTrigger {
6542 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6543 write!(
6544 f,
6545 "ALTER TRIGGER {} ON {} {}",
6546 self.name, self.table_name, self.operation
6547 )
6548 }
6549}
6550
6551impl fmt::Display for AlterTriggerOperation {
6552 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6553 match self {
6554 AlterTriggerOperation::RenameTo { new_name } => write!(f, "RENAME TO {new_name}"),
6555 }
6556 }
6557}
6558
6559impl From<AlterTrigger> for crate::ast::Statement {
6560 fn from(a: AlterTrigger) -> Self {
6561 crate::ast::Statement::AlterTrigger(a)
6562 }
6563}
6564
6565#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6569#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6570#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6571pub struct AlterExtension {
6572 pub name: Ident,
6574 pub operation: AlterExtensionOperation,
6576}
6577
6578#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6580#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6581#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6582pub enum AlterExtensionOperation {
6583 UpdateTo {
6585 version: Option<Ident>,
6587 },
6588 SetSchema {
6590 schema_name: ObjectName,
6592 },
6593 OwnerTo(Owner),
6595 RenameTo {
6597 new_name: Ident,
6599 },
6600}
6601
6602impl fmt::Display for AlterExtension {
6603 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6604 write!(f, "ALTER EXTENSION {} {}", self.name, self.operation)
6605 }
6606}
6607
6608impl fmt::Display for AlterExtensionOperation {
6609 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6610 match self {
6611 AlterExtensionOperation::UpdateTo { version } => {
6612 write!(f, "UPDATE")?;
6613 if let Some(v) = version {
6614 write!(f, " TO {v}")?;
6615 }
6616 Ok(())
6617 }
6618 AlterExtensionOperation::SetSchema { schema_name } => {
6619 write!(f, "SET SCHEMA {schema_name}")
6620 }
6621 AlterExtensionOperation::OwnerTo(owner) => write!(f, "OWNER TO {owner}"),
6622 AlterExtensionOperation::RenameTo { new_name } => write!(f, "RENAME TO {new_name}"),
6623 }
6624 }
6625}
6626
6627impl From<AlterExtension> for crate::ast::Statement {
6628 fn from(a: AlterExtension) -> Self {
6629 crate::ast::Statement::AlterExtension(a)
6630 }
6631}
6632
6633#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6638#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6639#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6640pub struct CreatePublication {
6641 pub name: Ident,
6643 pub target: Option<PublicationTarget>,
6645 pub with_options: Vec<SqlOption>,
6647}
6648
6649impl fmt::Display for CreatePublication {
6650 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6651 write!(f, "CREATE PUBLICATION {}", self.name)?;
6652 if let Some(target) = &self.target {
6653 write!(f, " {target}")?;
6654 }
6655 if !self.with_options.is_empty() {
6656 write!(f, " WITH ({})", display_comma_separated(&self.with_options))?;
6657 }
6658 Ok(())
6659 }
6660}
6661
6662impl From<CreatePublication> for crate::ast::Statement {
6663 fn from(v: CreatePublication) -> Self {
6664 crate::ast::Statement::CreatePublication(v)
6665 }
6666}
6667
6668#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6673#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6674#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6675pub struct CreateSubscription {
6676 pub name: Ident,
6678 pub connection: Value,
6680 pub publications: Vec<Ident>,
6682 pub with_options: Vec<SqlOption>,
6684}
6685
6686impl fmt::Display for CreateSubscription {
6687 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6688 write!(
6689 f,
6690 "CREATE SUBSCRIPTION {name} CONNECTION {connection} PUBLICATION {publications}",
6691 name = self.name,
6692 connection = self.connection,
6693 publications = display_comma_separated(&self.publications),
6694 )?;
6695 if !self.with_options.is_empty() {
6696 write!(f, " WITH ({})", display_comma_separated(&self.with_options))?;
6697 }
6698 Ok(())
6699 }
6700}
6701
6702impl From<CreateSubscription> for crate::ast::Statement {
6703 fn from(v: CreateSubscription) -> Self {
6704 crate::ast::Statement::CreateSubscription(v)
6705 }
6706}
6707
6708#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6712#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6713#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6714pub enum CastFunctionKind {
6715 WithFunction {
6717 function_name: ObjectName,
6719 argument_types: Vec<DataType>,
6722 },
6723 WithoutFunction,
6725 WithInout,
6727}
6728
6729impl fmt::Display for CastFunctionKind {
6730 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6731 match self {
6732 CastFunctionKind::WithFunction {
6733 function_name,
6734 argument_types,
6735 } => {
6736 write!(f, "WITH FUNCTION {function_name}")?;
6737 if !argument_types.is_empty() {
6738 write!(f, "({})", display_comma_separated(argument_types))?;
6739 }
6740 Ok(())
6741 }
6742 CastFunctionKind::WithoutFunction => write!(f, "WITHOUT FUNCTION"),
6743 CastFunctionKind::WithInout => write!(f, "WITH INOUT"),
6744 }
6745 }
6746}
6747
6748#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6753#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6754#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6755pub enum StatisticsKind {
6756 NDistinct,
6758 Dependencies,
6760 Mcv,
6762}
6763
6764impl fmt::Display for StatisticsKind {
6765 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6766 match self {
6767 StatisticsKind::NDistinct => write!(f, "ndistinct"),
6768 StatisticsKind::Dependencies => write!(f, "dependencies"),
6769 StatisticsKind::Mcv => write!(f, "mcv"),
6770 }
6771 }
6772}
6773
6774#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6778#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6779#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6780pub enum SecurityLabelObjectKind {
6781 Table,
6783 Column,
6785 Database,
6787 Domain,
6789 Function,
6791 Role,
6793 Schema,
6795 Sequence,
6797 Type,
6799 View,
6801 MaterializedView,
6803}
6804
6805impl fmt::Display for SecurityLabelObjectKind {
6806 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6807 match self {
6808 SecurityLabelObjectKind::Table => write!(f, "TABLE"),
6809 SecurityLabelObjectKind::Column => write!(f, "COLUMN"),
6810 SecurityLabelObjectKind::Database => write!(f, "DATABASE"),
6811 SecurityLabelObjectKind::Domain => write!(f, "DOMAIN"),
6812 SecurityLabelObjectKind::Function => write!(f, "FUNCTION"),
6813 SecurityLabelObjectKind::Role => write!(f, "ROLE"),
6814 SecurityLabelObjectKind::Schema => write!(f, "SCHEMA"),
6815 SecurityLabelObjectKind::Sequence => write!(f, "SEQUENCE"),
6816 SecurityLabelObjectKind::Type => write!(f, "TYPE"),
6817 SecurityLabelObjectKind::View => write!(f, "VIEW"),
6818 SecurityLabelObjectKind::MaterializedView => write!(f, "MATERIALIZED VIEW"),
6819 }
6820 }
6821}
6822
6823#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6827#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6828#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6829pub enum CastContext {
6830 Explicit,
6832 Assignment,
6834 Implicit,
6836}
6837
6838impl fmt::Display for CastContext {
6839 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6840 match self {
6841 CastContext::Explicit => Ok(()),
6842 CastContext::Assignment => write!(f, " AS ASSIGNMENT"),
6843 CastContext::Implicit => write!(f, " AS IMPLICIT"),
6844 }
6845 }
6846}
6847
6848#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6853#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6854#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6855pub struct CreateCast {
6856 pub source_type: DataType,
6858 pub target_type: DataType,
6860 pub function_kind: CastFunctionKind,
6862 pub cast_context: CastContext,
6864}
6865
6866impl fmt::Display for CreateCast {
6867 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6868 write!(
6869 f,
6870 "CREATE CAST ({source} AS {target}) {function_kind}{context}",
6871 source = self.source_type,
6872 target = self.target_type,
6873 function_kind = self.function_kind,
6874 context = self.cast_context,
6875 )
6876 }
6877}
6878
6879impl From<CreateCast> for crate::ast::Statement {
6880 fn from(v: CreateCast) -> Self {
6881 crate::ast::Statement::CreateCast(v)
6882 }
6883}
6884
6885#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6890#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6891#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6892pub struct CreateConversion {
6893 pub name: ObjectName,
6895 pub is_default: bool,
6897 pub source_encoding: String,
6899 pub destination_encoding: String,
6901 pub function_name: ObjectName,
6903}
6904
6905impl fmt::Display for CreateConversion {
6906 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6907 write!(f, "CREATE")?;
6908 if self.is_default {
6909 write!(f, " DEFAULT")?;
6910 }
6911 write!(
6912 f,
6913 " CONVERSION {name} FOR '{source}' TO '{destination}' FROM {function}",
6914 name = self.name,
6915 source = self.source_encoding,
6916 destination = self.destination_encoding,
6917 function = self.function_name,
6918 )
6919 }
6920}
6921
6922impl From<CreateConversion> for crate::ast::Statement {
6923 fn from(v: CreateConversion) -> Self {
6924 crate::ast::Statement::CreateConversion(v)
6925 }
6926}
6927
6928#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6933#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6934#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6935pub struct CreateLanguage {
6936 pub name: Ident,
6938 pub or_replace: bool,
6940 pub trusted: bool,
6942 pub procedural: bool,
6944 pub handler: Option<ObjectName>,
6946 pub inline_handler: Option<ObjectName>,
6948 pub validator: Option<ObjectName>,
6950}
6951
6952impl fmt::Display for CreateLanguage {
6953 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6954 write!(f, "CREATE")?;
6955 if self.or_replace {
6956 write!(f, " OR REPLACE")?;
6957 }
6958 if self.trusted {
6959 write!(f, " TRUSTED")?;
6960 }
6961 if self.procedural {
6962 write!(f, " PROCEDURAL")?;
6963 }
6964 write!(f, " LANGUAGE {}", self.name)?;
6965 if let Some(handler) = &self.handler {
6966 write!(f, " HANDLER {handler}")?;
6967 }
6968 if let Some(inline) = &self.inline_handler {
6969 write!(f, " INLINE {inline}")?;
6970 }
6971 if let Some(validator) = &self.validator {
6972 write!(f, " VALIDATOR {validator}")?;
6973 }
6974 Ok(())
6975 }
6976}
6977
6978#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
6983#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6984#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
6985pub struct CreateStatistics {
6986 pub if_not_exists: bool,
6988 pub name: ObjectName,
6990 pub kinds: Vec<StatisticsKind>,
6992 pub on: Vec<Expr>,
6994 pub from: ObjectName,
6996}
6997
6998impl fmt::Display for CreateStatistics {
6999 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7000 write!(f, "CREATE STATISTICS")?;
7001 if self.if_not_exists {
7002 write!(f, " IF NOT EXISTS")?;
7003 }
7004 write!(f, " {}", self.name)?;
7005 if !self.kinds.is_empty() {
7006 write!(f, " ({})", display_comma_separated(&self.kinds))?;
7007 }
7008 write!(f, " ON {}", display_comma_separated(&self.on))?;
7009 write!(f, " FROM {}", self.from)?;
7010 Ok(())
7011 }
7012}
7013
7014#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7019#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7020#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7021pub struct SecurityLabel {
7022 pub provider: Option<Ident>,
7024 pub object_kind: SecurityLabelObjectKind,
7026 pub object_name: ObjectName,
7028 pub label: Option<Value>,
7030}
7031
7032impl fmt::Display for SecurityLabel {
7033 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7034 write!(f, "SECURITY LABEL")?;
7035 if let Some(provider) = &self.provider {
7036 write!(f, " FOR {provider}")?;
7037 }
7038 write!(f, " ON {} {}", self.object_kind, self.object_name)?;
7039 write!(f, " IS ")?;
7040 match &self.label {
7041 Some(label) => write!(f, "{label}"),
7042 None => write!(f, "NULL"),
7043 }
7044 }
7045}
7046
7047impl From<SecurityLabel> for crate::ast::Statement {
7048 fn from(v: SecurityLabel) -> Self {
7049 crate::ast::Statement::SecurityLabel(v)
7050 }
7051}
7052
7053#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7057#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7058#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7059pub enum UserMappingUser {
7060 Ident(Ident),
7062 User,
7064 CurrentRole,
7066 CurrentUser,
7068 Public,
7070}
7071
7072impl fmt::Display for UserMappingUser {
7073 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7074 match self {
7075 UserMappingUser::Ident(ident) => write!(f, "{ident}"),
7076 UserMappingUser::User => write!(f, "USER"),
7077 UserMappingUser::CurrentRole => write!(f, "CURRENT_ROLE"),
7078 UserMappingUser::CurrentUser => write!(f, "CURRENT_USER"),
7079 UserMappingUser::Public => write!(f, "PUBLIC"),
7080 }
7081 }
7082}
7083
7084#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7089#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7090#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7091pub struct CreateUserMapping {
7092 pub if_not_exists: bool,
7094 pub user: UserMappingUser,
7096 pub server_name: Ident,
7098 pub options: Option<Vec<CreateServerOption>>,
7100}
7101
7102impl fmt::Display for CreateUserMapping {
7103 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7104 write!(f, "CREATE USER MAPPING")?;
7105 if self.if_not_exists {
7106 write!(f, " IF NOT EXISTS")?;
7107 }
7108 write!(f, " FOR {} SERVER {}", self.user, self.server_name)?;
7109 if let Some(options) = &self.options {
7110 write!(f, " OPTIONS ({})", display_comma_separated(options))?;
7111 }
7112 Ok(())
7113 }
7114}
7115
7116impl From<CreateLanguage> for crate::ast::Statement {
7117 fn from(v: CreateLanguage) -> Self {
7118 crate::ast::Statement::CreateLanguage(v)
7119 }
7120}
7121
7122#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7126#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7127#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7128pub enum RuleEvent {
7129 Select,
7131 Insert,
7133 Update,
7135 Delete,
7137}
7138
7139impl fmt::Display for RuleEvent {
7140 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7141 match self {
7142 RuleEvent::Select => write!(f, "SELECT"),
7143 RuleEvent::Insert => write!(f, "INSERT"),
7144 RuleEvent::Update => write!(f, "UPDATE"),
7145 RuleEvent::Delete => write!(f, "DELETE"),
7146 }
7147 }
7148}
7149
7150impl From<CreateStatistics> for crate::ast::Statement {
7151 fn from(v: CreateStatistics) -> Self {
7152 crate::ast::Statement::CreateStatistics(v)
7153 }
7154}
7155
7156#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7161#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7162#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7163pub enum AccessMethodType {
7164 Index,
7166 Table,
7168}
7169
7170impl fmt::Display for AccessMethodType {
7171 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7172 match self {
7173 AccessMethodType::Index => write!(f, "INDEX"),
7174 AccessMethodType::Table => write!(f, "TABLE"),
7175 }
7176 }
7177}
7178
7179#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7183#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7184#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7185pub enum RuleAction {
7186 Nothing,
7188 Statements(Vec<crate::ast::Statement>),
7190}
7191
7192impl fmt::Display for RuleAction {
7193 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7194 match self {
7195 RuleAction::Nothing => write!(f, "NOTHING"),
7196 RuleAction::Statements(stmts) => {
7197 if stmts.len() == 1 {
7198 write!(f, "{}", stmts[0])
7199 } else {
7200 write!(f, "(")?;
7201 for (i, stmt) in stmts.iter().enumerate() {
7202 if i > 0 {
7203 write!(f, "; ")?;
7204 }
7205 write!(f, "{stmt}")?;
7206 }
7207 write!(f, ")")
7208 }
7209 }
7210 }
7211 }
7212}
7213
7214#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7219#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7220#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7221pub struct CreateRule {
7222 pub name: Ident,
7224 pub event: RuleEvent,
7226 pub table: ObjectName,
7228 pub condition: Option<Expr>,
7230 pub instead: bool,
7232 pub action: RuleAction,
7234}
7235
7236impl fmt::Display for CreateRule {
7237 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7238 write!(
7239 f,
7240 "CREATE RULE {name} AS ON {event} TO {table}",
7241 name = self.name,
7242 event = self.event,
7243 table = self.table,
7244 )?;
7245 if let Some(condition) = &self.condition {
7246 write!(f, " WHERE {condition}")?;
7247 }
7248 write!(f, " DO")?;
7249 if self.instead {
7250 write!(f, " INSTEAD")?;
7251 } else {
7252 write!(f, " ALSO")?;
7253 }
7254 write!(f, " {}", self.action)
7255 }
7256}
7257
7258impl From<CreateRule> for crate::ast::Statement {
7259 fn from(v: CreateRule) -> Self {
7260 crate::ast::Statement::CreateRule(v)
7261 }
7262}
7263
7264#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7269#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7270#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7271pub struct CreateAccessMethod {
7272 pub name: Ident,
7274 pub method_type: AccessMethodType,
7276 pub handler: ObjectName,
7278}
7279
7280impl fmt::Display for CreateAccessMethod {
7281 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7282 write!(
7283 f,
7284 "CREATE ACCESS METHOD {name} TYPE {method_type} HANDLER {handler}",
7285 name = self.name,
7286 method_type = self.method_type,
7287 handler = self.handler,
7288 )
7289 }
7290}
7291
7292impl From<CreateAccessMethod> for crate::ast::Statement {
7293 fn from(v: CreateAccessMethod) -> Self {
7294 crate::ast::Statement::CreateAccessMethod(v)
7295 }
7296}
7297
7298#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7303#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7304#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7305pub enum EventTriggerEvent {
7306 DdlCommandStart,
7308 DdlCommandEnd,
7310 TableRewrite,
7312 SqlDrop,
7314}
7315
7316impl fmt::Display for EventTriggerEvent {
7317 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7318 match self {
7319 EventTriggerEvent::DdlCommandStart => write!(f, "ddl_command_start"),
7320 EventTriggerEvent::DdlCommandEnd => write!(f, "ddl_command_end"),
7321 EventTriggerEvent::TableRewrite => write!(f, "table_rewrite"),
7322 EventTriggerEvent::SqlDrop => write!(f, "sql_drop"),
7323 }
7324 }
7325}
7326
7327#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7332#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7333#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7334pub struct CreateEventTrigger {
7335 pub name: Ident,
7337 pub event: EventTriggerEvent,
7339 pub when_tags: Option<Vec<Value>>,
7341 pub execute: ObjectName,
7343 pub is_procedure: bool,
7345}
7346
7347impl fmt::Display for CreateEventTrigger {
7348 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7349 write!(f, "CREATE EVENT TRIGGER {} ON {}", self.name, self.event)?;
7350 if let Some(tags) = &self.when_tags {
7351 write!(f, " WHEN TAG IN ({})", display_comma_separated(tags))?;
7352 }
7353 let func_kw = if self.is_procedure {
7354 "PROCEDURE"
7355 } else {
7356 "FUNCTION"
7357 };
7358 write!(f, " EXECUTE {func_kw} {}()", self.execute)?;
7359 Ok(())
7360 }
7361}
7362
7363impl From<CreateUserMapping> for crate::ast::Statement {
7364 fn from(v: CreateUserMapping) -> Self {
7365 crate::ast::Statement::CreateUserMapping(v)
7366 }
7367}
7368
7369#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7374#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7375#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7376pub struct CreateTablespace {
7377 pub name: Ident,
7379 pub owner: Option<Ident>,
7381 pub location: Value,
7383 pub with_options: Vec<SqlOption>,
7385}
7386
7387impl fmt::Display for CreateTablespace {
7388 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7389 write!(f, "CREATE TABLESPACE {}", self.name)?;
7390 if let Some(owner) = &self.owner {
7391 write!(f, " OWNER {owner}")?;
7392 }
7393 write!(f, " LOCATION {}", self.location)?;
7394 if !self.with_options.is_empty() {
7395 write!(f, " WITH ({})", display_comma_separated(&self.with_options))?;
7396 }
7397 Ok(())
7398 }
7399}
7400
7401impl From<CreateEventTrigger> for crate::ast::Statement {
7402 fn from(v: CreateEventTrigger) -> Self {
7403 crate::ast::Statement::CreateEventTrigger(v)
7404 }
7405}
7406
7407#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7414#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7415#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7416pub struct TransformElement {
7417 pub is_from: bool,
7419 pub function: ObjectName,
7421 pub arg_types: Vec<DataType>,
7423}
7424
7425impl fmt::Display for TransformElement {
7426 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7427 let direction = if self.is_from { "FROM" } else { "TO" };
7428 write!(
7429 f,
7430 "{direction} SQL WITH FUNCTION {}({})",
7431 self.function,
7432 display_comma_separated(&self.arg_types),
7433 )
7434 }
7435}
7436
7437#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
7442#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7443#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
7444pub struct CreateTransform {
7445 pub or_replace: bool,
7447 pub type_name: DataType,
7449 pub language: Ident,
7451 pub elements: Vec<TransformElement>,
7453}
7454
7455impl fmt::Display for CreateTransform {
7456 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7457 write!(f, "CREATE")?;
7458 if self.or_replace {
7459 write!(f, " OR REPLACE")?;
7460 }
7461 write!(
7462 f,
7463 " TRANSFORM FOR {} LANGUAGE {} ({})",
7464 self.type_name,
7465 self.language,
7466 display_comma_separated(&self.elements),
7467 )
7468 }
7469}
7470
7471impl From<CreateTransform> for crate::ast::Statement {
7472 fn from(v: CreateTransform) -> Self {
7473 crate::ast::Statement::CreateTransform(v)
7474 }
7475}
7476
7477impl From<CreateTablespace> for crate::ast::Statement {
7478 fn from(v: CreateTablespace) -> Self {
7479 crate::ast::Statement::CreateTablespace(v)
7480 }
7481}