@@ -995,6 +995,103 @@ impl fmt::Display for AlterTypeOperation {
995995 }
996996}
997997
998+ /// `ALTER OPERATOR` statement
999+ /// See <https://www.postgresql.org/docs/current/sql-alteroperator.html>
1000+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1001+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1002+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1003+ pub struct AlterOperator {
1004+ /// Operator name (can be schema-qualified)
1005+ pub name : ObjectName ,
1006+ /// Left operand type (`None` if no left operand)
1007+ pub left_type : Option < DataType > ,
1008+ /// Right operand type
1009+ pub right_type : DataType ,
1010+ /// The operation to perform
1011+ pub operation : AlterOperatorOperation ,
1012+ }
1013+
1014+ /// An [AlterOperator] operation
1015+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1016+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1017+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1018+ pub enum AlterOperatorOperation {
1019+ /// `OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }`
1020+ OwnerTo ( Owner ) ,
1021+ /// `SET SCHEMA new_schema`
1022+ SetSchema { schema_name : ObjectName } ,
1023+ /// `SET ( options )`
1024+ Set {
1025+ /// List of operator options to set
1026+ options : Vec < OperatorOption > ,
1027+ } ,
1028+ }
1029+
1030+ /// Option for `ALTER OPERATOR SET` operation
1031+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
1032+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
1033+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
1034+ pub enum OperatorOption {
1035+ /// `RESTRICT = { res_proc | NONE }`
1036+ Restrict ( Option < ObjectName > ) ,
1037+ /// `JOIN = { join_proc | NONE }`
1038+ Join ( Option < ObjectName > ) ,
1039+ /// `COMMUTATOR = com_op`
1040+ Commutator ( ObjectName ) ,
1041+ /// `NEGATOR = neg_op`
1042+ Negator ( ObjectName ) ,
1043+ /// `HASHES`
1044+ Hashes ,
1045+ /// `MERGES`
1046+ Merges ,
1047+ }
1048+
1049+ impl fmt:: Display for AlterOperator {
1050+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1051+ write ! ( f, "ALTER OPERATOR {} (" , self . name) ?;
1052+ if let Some ( left_type) = & self . left_type {
1053+ write ! ( f, "{}" , left_type) ?;
1054+ } else {
1055+ write ! ( f, "NONE" ) ?;
1056+ }
1057+ write ! ( f, ", {}) {}" , self . right_type, self . operation)
1058+ }
1059+ }
1060+
1061+ impl fmt:: Display for AlterOperatorOperation {
1062+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1063+ match self {
1064+ Self :: OwnerTo ( owner) => write ! ( f, "OWNER TO {}" , owner) ,
1065+ Self :: SetSchema { schema_name } => write ! ( f, "SET SCHEMA {}" , schema_name) ,
1066+ Self :: Set { options } => {
1067+ write ! ( f, "SET (" ) ?;
1068+ for ( i, option) in options. iter ( ) . enumerate ( ) {
1069+ if i > 0 {
1070+ write ! ( f, ", " ) ?;
1071+ }
1072+ write ! ( f, "{}" , option) ?;
1073+ }
1074+ write ! ( f, ")" )
1075+ }
1076+ }
1077+ }
1078+ }
1079+
1080+ impl fmt:: Display for OperatorOption {
1081+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1082+ match self {
1083+ Self :: Restrict ( Some ( proc_name) ) => write ! ( f, "RESTRICT = {}" , proc_name) ,
1084+ Self :: Restrict ( None ) => write ! ( f, "RESTRICT = NONE" ) ,
1085+ Self :: Join ( Some ( proc_name) ) => write ! ( f, "JOIN = {}" , proc_name) ,
1086+ Self :: Join ( None ) => write ! ( f, "JOIN = NONE" ) ,
1087+ Self :: Commutator ( op_name) => write ! ( f, "COMMUTATOR = {}" , op_name) ,
1088+ Self :: Negator ( op_name) => write ! ( f, "NEGATOR = {}" , op_name) ,
1089+ Self :: Hashes => write ! ( f, "HASHES" ) ,
1090+ Self :: Merges => write ! ( f, "MERGES" ) ,
1091+ }
1092+ }
1093+ }
1094+
9981095/// An `ALTER COLUMN` (`Statement::AlterTable`) operation
9991096#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
10001097#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -1790,7 +1887,7 @@ impl fmt::Display for ColumnOption {
17901887 GeneratedAs :: Always => "ALWAYS" ,
17911888 GeneratedAs :: ByDefault => "BY DEFAULT" ,
17921889 // ExpStored goes with an expression, handled above
1793- GeneratedAs :: ExpStored => unreachable ! ( ) ,
1890+ GeneratedAs :: ExpStored => "" ,
17941891 } ;
17951892 write ! ( f, "GENERATED {when} AS IDENTITY" ) ?;
17961893 if sequence_options. is_some ( ) {
@@ -3981,18 +4078,8 @@ pub struct CreateOperator {
39814078 pub left_arg : Option < DataType > ,
39824079 /// RIGHTARG parameter (right operand type)
39834080 pub right_arg : Option < DataType > ,
3984- /// COMMUTATOR parameter (commutator operator)
3985- pub commutator : Option < ObjectName > ,
3986- /// NEGATOR parameter (negator operator)
3987- pub negator : Option < ObjectName > ,
3988- /// RESTRICT parameter (restriction selectivity function)
3989- pub restrict : Option < ObjectName > ,
3990- /// JOIN parameter (join selectivity function)
3991- pub join : Option < ObjectName > ,
3992- /// HASHES flag
3993- pub hashes : bool ,
3994- /// MERGES flag
3995- pub merges : bool ,
4081+ /// Operator options (COMMUTATOR, NEGATOR, RESTRICT, JOIN, HASHES, MERGES)
4082+ pub options : Vec < OperatorOption > ,
39964083}
39974084
39984085/// CREATE OPERATOR FAMILY statement
@@ -4044,23 +4131,9 @@ impl fmt::Display for CreateOperator {
40444131 if let Some ( right_arg) = & self . right_arg {
40454132 params. push ( format ! ( "RIGHTARG = {}" , right_arg) ) ;
40464133 }
4047- if let Some ( commutator) = & self . commutator {
4048- params. push ( format ! ( "COMMUTATOR = {}" , commutator) ) ;
4049- }
4050- if let Some ( negator) = & self . negator {
4051- params. push ( format ! ( "NEGATOR = {}" , negator) ) ;
4052- }
4053- if let Some ( restrict) = & self . restrict {
4054- params. push ( format ! ( "RESTRICT = {}" , restrict) ) ;
4055- }
4056- if let Some ( join) = & self . join {
4057- params. push ( format ! ( "JOIN = {}" , join) ) ;
4058- }
4059- if self . hashes {
4060- params. push ( "HASHES" . to_string ( ) ) ;
4061- }
4062- if self . merges {
4063- params. push ( "MERGES" . to_string ( ) ) ;
4134+
4135+ for option in & self . options {
4136+ params. push ( option. to_string ( ) ) ;
40644137 }
40654138
40664139 write ! ( f, "{}" , params. join( ", " ) ) ?;
0 commit comments