@@ -535,6 +535,14 @@ pub enum AlterTableOperation {
535535 /// Parenthesized options supplied to `SET (...)`.
536536 options : Vec < SqlOption > ,
537537 } ,
538+ /// `SET TABLESPACE tablespace_name`
539+ ///
540+ /// Note: this is a PostgreSQL-specific operation.
541+ /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-altertable.html)
542+ SetTablespace {
543+ /// The target tablespace name.
544+ tablespace_name : Ident ,
545+ } ,
538546}
539547
540548/// An `ALTER Policy` (`Statement::AlterPolicy`) operation
@@ -700,6 +708,14 @@ pub enum AlterIndexOperation {
700708 /// The new name for the index.
701709 index_name : ObjectName ,
702710 } ,
711+ /// `SET TABLESPACE tablespace_name`
712+ ///
713+ /// Note: this is a PostgreSQL-specific operation.
714+ /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-alterindex.html)
715+ SetTablespace {
716+ /// The target tablespace name.
717+ tablespace_name : Ident ,
718+ } ,
703719}
704720
705721impl fmt:: Display for AlterTableOperation {
@@ -1045,6 +1061,9 @@ impl fmt::Display for AlterTableOperation {
10451061 AlterTableOperation :: SetOptionsParens { options } => {
10461062 write ! ( f, "SET ({})" , display_comma_separated( options) )
10471063 }
1064+ AlterTableOperation :: SetTablespace { tablespace_name } => {
1065+ write ! ( f, "SET TABLESPACE {tablespace_name}" )
1066+ }
10481067 }
10491068 }
10501069}
@@ -1055,6 +1074,9 @@ impl fmt::Display for AlterIndexOperation {
10551074 AlterIndexOperation :: RenameIndex { index_name } => {
10561075 write ! ( f, "RENAME TO {index_name}" )
10571076 }
1077+ AlterIndexOperation :: SetTablespace { tablespace_name } => {
1078+ write ! ( f, "SET TABLESPACE {tablespace_name}" )
1079+ }
10581080 }
10591081 }
10601082}
@@ -5390,13 +5412,16 @@ pub enum AlterFunctionKind {
53905412 Function ,
53915413 /// `AGGREGATE`
53925414 Aggregate ,
5415+ /// `PROCEDURE`
5416+ Procedure ,
53935417}
53945418
53955419impl fmt:: Display for AlterFunctionKind {
53965420 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
53975421 match self {
53985422 Self :: Function => write ! ( f, "FUNCTION" ) ,
53995423 Self :: Aggregate => write ! ( f, "AGGREGATE" ) ,
5424+ Self :: Procedure => write ! ( f, "PROCEDURE" ) ,
54005425 }
54015426 }
54025427}
@@ -5471,7 +5496,7 @@ impl fmt::Display for AlterFunction {
54715496 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
54725497 write ! ( f, "ALTER {} " , self . kind) ?;
54735498 match self . kind {
5474- AlterFunctionKind :: Function => {
5499+ AlterFunctionKind :: Function | AlterFunctionKind :: Procedure => {
54755500 write ! ( f, "{} " , self . function) ?;
54765501 }
54775502 AlterFunctionKind :: Aggregate => {
@@ -6136,3 +6161,246 @@ impl From<CreateTextSearchTemplate> for crate::ast::Statement {
61366161 crate :: ast:: Statement :: CreateTextSearchTemplate ( v)
61376162 }
61386163}
6164+
6165+ /// `ALTER DOMAIN` statement.
6166+ ///
6167+ /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-alterdomain.html)
6168+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6169+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6170+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6171+ pub struct AlterDomain {
6172+ /// Name of the domain being altered.
6173+ pub name : ObjectName ,
6174+ /// The operation to perform.
6175+ pub operation : AlterDomainOperation ,
6176+ }
6177+
6178+ /// An [AlterDomain] operation.
6179+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6180+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6181+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6182+ pub enum AlterDomainOperation {
6183+ /// `ADD CONSTRAINT constraint_name CHECK (expr) [NOT VALID]`
6184+ AddConstraint {
6185+ /// The constraint to add.
6186+ constraint : TableConstraint ,
6187+ /// Whether `NOT VALID` was specified.
6188+ not_valid : bool ,
6189+ } ,
6190+ /// `DROP CONSTRAINT [IF EXISTS] constraint_name [CASCADE | RESTRICT]`
6191+ DropConstraint {
6192+ /// Whether `IF EXISTS` was specified.
6193+ if_exists : bool ,
6194+ /// Name of the constraint to drop.
6195+ name : Ident ,
6196+ /// Optional drop behavior.
6197+ drop_behavior : Option < DropBehavior > ,
6198+ } ,
6199+ /// `RENAME CONSTRAINT old_name TO new_name`
6200+ RenameConstraint {
6201+ /// Existing constraint name.
6202+ old_name : Ident ,
6203+ /// New constraint name.
6204+ new_name : Ident ,
6205+ } ,
6206+ /// `OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }`
6207+ OwnerTo ( Owner ) ,
6208+ /// `RENAME TO new_name`
6209+ RenameTo {
6210+ /// New name for the domain.
6211+ new_name : Ident ,
6212+ } ,
6213+ /// `SET SCHEMA schema_name`
6214+ SetSchema {
6215+ /// The target schema name.
6216+ schema_name : ObjectName ,
6217+ } ,
6218+ /// `SET DEFAULT expr`
6219+ SetDefault {
6220+ /// Default value expression.
6221+ default : Expr ,
6222+ } ,
6223+ /// `DROP DEFAULT`
6224+ DropDefault ,
6225+ /// `VALIDATE CONSTRAINT constraint_name`
6226+ ValidateConstraint {
6227+ /// Name of the constraint to validate.
6228+ name : Ident ,
6229+ } ,
6230+ }
6231+
6232+ impl fmt:: Display for AlterDomain {
6233+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6234+ write ! ( f, "ALTER DOMAIN {} {}" , self . name, self . operation)
6235+ }
6236+ }
6237+
6238+ impl fmt:: Display for AlterDomainOperation {
6239+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6240+ match self {
6241+ AlterDomainOperation :: AddConstraint {
6242+ constraint,
6243+ not_valid,
6244+ } => {
6245+ write ! ( f, "ADD {constraint}" ) ?;
6246+ if * not_valid {
6247+ write ! ( f, " NOT VALID" ) ?;
6248+ }
6249+ Ok ( ( ) )
6250+ }
6251+ AlterDomainOperation :: DropConstraint {
6252+ if_exists,
6253+ name,
6254+ drop_behavior,
6255+ } => {
6256+ write ! ( f, "DROP CONSTRAINT" ) ?;
6257+ if * if_exists {
6258+ write ! ( f, " IF EXISTS" ) ?;
6259+ }
6260+ write ! ( f, " {name}" ) ?;
6261+ if let Some ( behavior) = drop_behavior {
6262+ write ! ( f, " {behavior}" ) ?;
6263+ }
6264+ Ok ( ( ) )
6265+ }
6266+ AlterDomainOperation :: RenameConstraint { old_name, new_name } => {
6267+ write ! ( f, "RENAME CONSTRAINT {old_name} TO {new_name}" )
6268+ }
6269+ AlterDomainOperation :: OwnerTo ( owner) => write ! ( f, "OWNER TO {owner}" ) ,
6270+ AlterDomainOperation :: RenameTo { new_name } => write ! ( f, "RENAME TO {new_name}" ) ,
6271+ AlterDomainOperation :: SetSchema { schema_name } => {
6272+ write ! ( f, "SET SCHEMA {schema_name}" )
6273+ }
6274+ AlterDomainOperation :: SetDefault { default } => write ! ( f, "SET DEFAULT {default}" ) ,
6275+ AlterDomainOperation :: DropDefault => write ! ( f, "DROP DEFAULT" ) ,
6276+ AlterDomainOperation :: ValidateConstraint { name } => {
6277+ write ! ( f, "VALIDATE CONSTRAINT {name}" )
6278+ }
6279+ }
6280+ }
6281+ }
6282+
6283+ impl From < AlterDomain > for crate :: ast:: Statement {
6284+ fn from ( a : AlterDomain ) -> Self {
6285+ crate :: ast:: Statement :: AlterDomain ( a)
6286+ }
6287+ }
6288+
6289+ /// `ALTER TRIGGER name ON table_name RENAME TO new_name` statement.
6290+ ///
6291+ /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-altertrigger.html)
6292+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6293+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6294+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6295+ pub struct AlterTrigger {
6296+ /// Name of the trigger being altered.
6297+ pub name : Ident ,
6298+ /// Name of the table the trigger is defined on.
6299+ pub table_name : ObjectName ,
6300+ /// The operation to perform.
6301+ pub operation : AlterTriggerOperation ,
6302+ }
6303+
6304+ /// An [AlterTrigger] operation.
6305+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6306+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6307+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6308+ pub enum AlterTriggerOperation {
6309+ /// `RENAME TO new_name`
6310+ RenameTo {
6311+ /// New name for the trigger.
6312+ new_name : Ident ,
6313+ } ,
6314+ }
6315+
6316+ impl fmt:: Display for AlterTrigger {
6317+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6318+ write ! (
6319+ f,
6320+ "ALTER TRIGGER {} ON {} {}" ,
6321+ self . name, self . table_name, self . operation
6322+ )
6323+ }
6324+ }
6325+
6326+ impl fmt:: Display for AlterTriggerOperation {
6327+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6328+ match self {
6329+ AlterTriggerOperation :: RenameTo { new_name } => write ! ( f, "RENAME TO {new_name}" ) ,
6330+ }
6331+ }
6332+ }
6333+
6334+ impl From < AlterTrigger > for crate :: ast:: Statement {
6335+ fn from ( a : AlterTrigger ) -> Self {
6336+ crate :: ast:: Statement :: AlterTrigger ( a)
6337+ }
6338+ }
6339+
6340+ /// `ALTER EXTENSION` statement.
6341+ ///
6342+ /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-alterextension.html)
6343+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6344+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6345+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6346+ pub struct AlterExtension {
6347+ /// Name of the extension being altered.
6348+ pub name : Ident ,
6349+ /// The operation to perform.
6350+ pub operation : AlterExtensionOperation ,
6351+ }
6352+
6353+ /// An [AlterExtension] operation.
6354+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6355+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6356+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6357+ pub enum AlterExtensionOperation {
6358+ /// `UPDATE [ TO new_version ]`
6359+ UpdateTo {
6360+ /// Optional target version string or identifier.
6361+ version : Option < Ident > ,
6362+ } ,
6363+ /// `SET SCHEMA schema_name`
6364+ SetSchema {
6365+ /// The target schema name.
6366+ schema_name : ObjectName ,
6367+ } ,
6368+ /// `OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }`
6369+ OwnerTo ( Owner ) ,
6370+ /// `RENAME TO new_name`
6371+ RenameTo {
6372+ /// New name for the extension.
6373+ new_name : Ident ,
6374+ } ,
6375+ }
6376+
6377+ impl fmt:: Display for AlterExtension {
6378+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6379+ write ! ( f, "ALTER EXTENSION {} {}" , self . name, self . operation)
6380+ }
6381+ }
6382+
6383+ impl fmt:: Display for AlterExtensionOperation {
6384+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6385+ match self {
6386+ AlterExtensionOperation :: UpdateTo { version } => {
6387+ write ! ( f, "UPDATE" ) ?;
6388+ if let Some ( v) = version {
6389+ write ! ( f, " TO {v}" ) ?;
6390+ }
6391+ Ok ( ( ) )
6392+ }
6393+ AlterExtensionOperation :: SetSchema { schema_name } => {
6394+ write ! ( f, "SET SCHEMA {schema_name}" )
6395+ }
6396+ AlterExtensionOperation :: OwnerTo ( owner) => write ! ( f, "OWNER TO {owner}" ) ,
6397+ AlterExtensionOperation :: RenameTo { new_name } => write ! ( f, "RENAME TO {new_name}" ) ,
6398+ }
6399+ }
6400+ }
6401+
6402+ impl From < AlterExtension > for crate :: ast:: Statement {
6403+ fn from ( a : AlterExtension ) -> Self {
6404+ crate :: ast:: Statement :: AlterExtension ( a)
6405+ }
6406+ }
0 commit comments