@@ -39,6 +39,29 @@ use crate::ast::{
3939use crate :: keywords:: Keyword ;
4040use crate :: tokenizer:: Token ;
4141
42+ /// ALTER TABLE operation REPLICA IDENTITY values
43+ /// See [Postgres ALTER TABLE docs](https://www.postgresql.org/docs/current/sql-altertable.html)
44+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
45+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
46+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
47+ pub enum ReplicaIdentity {
48+ None ,
49+ Full ,
50+ Default ,
51+ Index ( Ident ) ,
52+ }
53+
54+ impl fmt:: Display for ReplicaIdentity {
55+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
56+ match self {
57+ ReplicaIdentity :: None => f. write_str ( "NONE" ) ,
58+ ReplicaIdentity :: Full => f. write_str ( "FULL" ) ,
59+ ReplicaIdentity :: Default => f. write_str ( "DEFAULT" ) ,
60+ ReplicaIdentity :: Index ( idx) => write ! ( f, "USING INDEX {}" , idx) ,
61+ }
62+ }
63+ }
64+
4265/// An `ALTER TABLE` (`Statement::AlterTable`) operation
4366#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
4467#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
@@ -208,6 +231,13 @@ pub enum AlterTableOperation {
208231 old_partitions : Vec < Expr > ,
209232 new_partitions : Vec < Expr > ,
210233 } ,
234+ /// REPLICA IDENTITY { DEFAULT | USING INDEX index_name | FULL | NOTHING }
235+ ///
236+ /// Note: this is a PostgreSQL-specific operation.
237+ /// Please refer to [PostgreSQL documentation](https://www.postgresql.org/docs/current/sql-altertable.html)
238+ ReplicaIdentity {
239+ identity : ReplicaIdentity ,
240+ } ,
211241 /// Add Partitions
212242 AddPartitions {
213243 if_not_exists : bool ,
@@ -729,6 +759,9 @@ impl fmt::Display for AlterTableOperation {
729759 AlterTableOperation :: Lock { equals, lock } => {
730760 write ! ( f, "LOCK {}{}" , if * equals { "= " } else { "" } , lock)
731761 }
762+ AlterTableOperation :: ReplicaIdentity { identity } => {
763+ write ! ( f, "REPLICA IDENTITY {identity}" )
764+ }
732765 }
733766 }
734767}
0 commit comments