@@ -6280,6 +6280,39 @@ impl fmt::Display for AlterDomainOperation {
62806280 }
62816281}
62826282
6283+ /// The target of a `CREATE PUBLICATION` statement: which rows to publish.
6284+ ///
6285+ /// See <https://www.postgresql.org/docs/current/sql-createpublication.html>
6286+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6287+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6288+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6289+ pub enum PublicationTarget {
6290+ /// `FOR ALL TABLES`
6291+ AllTables ,
6292+ /// `FOR TABLE table [, ...]`
6293+ Tables ( Vec < ObjectName > ) ,
6294+ /// `FOR TABLES IN SCHEMA schema [, ...]`
6295+ TablesInSchema ( Vec < Ident > ) ,
6296+ }
6297+
6298+ impl fmt:: Display for PublicationTarget {
6299+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6300+ match self {
6301+ PublicationTarget :: AllTables => write ! ( f, "FOR ALL TABLES" ) ,
6302+ PublicationTarget :: Tables ( tables) => {
6303+ write ! ( f, "FOR TABLE {}" , display_comma_separated( tables) )
6304+ }
6305+ PublicationTarget :: TablesInSchema ( schemas) => {
6306+ write ! (
6307+ f,
6308+ "FOR TABLES IN SCHEMA {}" ,
6309+ display_comma_separated( schemas)
6310+ )
6311+ }
6312+ }
6313+ }
6314+ }
6315+
62836316impl From < AlterDomain > for crate :: ast:: Statement {
62846317 fn from ( a : AlterDomain ) -> Self {
62856318 crate :: ast:: Statement :: AlterDomain ( a)
@@ -6404,3 +6437,78 @@ impl From<AlterExtension> for crate::ast::Statement {
64046437 crate :: ast:: Statement :: AlterExtension ( a)
64056438 }
64066439}
6440+
6441+ /// A `CREATE PUBLICATION` statement.
6442+ ///
6443+ /// Note: this is a PostgreSQL-specific statement.
6444+ /// <https://www.postgresql.org/docs/current/sql-createpublication.html>
6445+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6446+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6447+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6448+ pub struct CreatePublication {
6449+ /// The publication name.
6450+ pub name : Ident ,
6451+ /// Optional target specification (`FOR ALL TABLES`, `FOR TABLE ...`, or `FOR TABLES IN SCHEMA ...`).
6452+ pub target : Option < PublicationTarget > ,
6453+ /// Optional `WITH (key = value, ...)` clause.
6454+ pub with_options : Vec < SqlOption > ,
6455+ }
6456+
6457+ impl fmt:: Display for CreatePublication {
6458+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6459+ write ! ( f, "CREATE PUBLICATION {}" , self . name) ?;
6460+ if let Some ( target) = & self . target {
6461+ write ! ( f, " {target}" ) ?;
6462+ }
6463+ if !self . with_options . is_empty ( ) {
6464+ write ! ( f, " WITH ({})" , display_comma_separated( & self . with_options) ) ?;
6465+ }
6466+ Ok ( ( ) )
6467+ }
6468+ }
6469+
6470+ impl From < CreatePublication > for crate :: ast:: Statement {
6471+ fn from ( v : CreatePublication ) -> Self {
6472+ crate :: ast:: Statement :: CreatePublication ( v)
6473+ }
6474+ }
6475+
6476+ /// A `CREATE SUBSCRIPTION` statement.
6477+ ///
6478+ /// Note: this is a PostgreSQL-specific statement.
6479+ /// <https://www.postgresql.org/docs/current/sql-createsubscription.html>
6480+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
6481+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
6482+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
6483+ pub struct CreateSubscription {
6484+ /// The subscription name.
6485+ pub name : Ident ,
6486+ /// The `CONNECTION 'conninfo'` string.
6487+ pub connection : Value ,
6488+ /// The `PUBLICATION publication_name [, ...]` list.
6489+ pub publications : Vec < Ident > ,
6490+ /// Optional `WITH (key = value, ...)` clause.
6491+ pub with_options : Vec < SqlOption > ,
6492+ }
6493+
6494+ impl fmt:: Display for CreateSubscription {
6495+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6496+ write ! (
6497+ f,
6498+ "CREATE SUBSCRIPTION {name} CONNECTION {connection} PUBLICATION {publications}" ,
6499+ name = self . name,
6500+ connection = self . connection,
6501+ publications = display_comma_separated( & self . publications) ,
6502+ ) ?;
6503+ if !self . with_options . is_empty ( ) {
6504+ write ! ( f, " WITH ({})" , display_comma_separated( & self . with_options) ) ?;
6505+ }
6506+ Ok ( ( ) )
6507+ }
6508+ }
6509+
6510+ impl From < CreateSubscription > for crate :: ast:: Statement {
6511+ fn from ( v : CreateSubscription ) -> Self {
6512+ crate :: ast:: Statement :: CreateSubscription ( v)
6513+ }
6514+ }
0 commit comments