@@ -42,7 +42,8 @@ use crate::ast::{
4242 UniqueConstraint ,
4343 } ,
4444 ArgMode , AttachedToken , CommentDef , ConditionalStatements , CreateFunctionBody ,
45- CreateFunctionUsing , CreateTableLikeKind , CreateTableOptions , CreateViewParams , DataType , Expr ,
45+ CreateFunctionUsing , CreateServerOption , CreateTableLikeKind , CreateTableOptions ,
46+ CreateViewParams , DataType , Expr ,
4647 FileFormat , FunctionBehavior , FunctionCalledOnNull , FunctionDefinitionSetParam , FunctionDesc ,
4748 FunctionDeterminismSpecifier , FunctionParallel , FunctionSecurity , HiveDistributionStyle ,
4849 HiveFormat , HiveIOFormat , HiveRowFormat , HiveSetLocation , Ident , InitializeKind ,
@@ -5758,6 +5759,107 @@ impl From<AlterPolicy> for crate::ast::Statement {
57585759 }
57595760}
57605761
5762+ /// The handler/validator clause of a `CREATE FOREIGN DATA WRAPPER` statement.
5763+ ///
5764+ /// Specifies either a named function or the absence of a function.
5765+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5766+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5767+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5768+ pub enum FdwRoutineClause {
5769+ /// A named function, e.g. `HANDLER myhandler` or `VALIDATOR myvalidator`.
5770+ Function ( ObjectName ) ,
5771+ /// The `NO HANDLER` or `NO VALIDATOR` form.
5772+ NoFunction ,
5773+ }
5774+
5775+ /// A `CREATE FOREIGN DATA WRAPPER` statement.
5776+ ///
5777+ /// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createforeigndatawrapper.html)
5778+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5779+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5780+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5781+ pub struct CreateForeignDataWrapper {
5782+ /// The name of the foreign-data wrapper.
5783+ pub name : Ident ,
5784+ /// Optional `HANDLER handler_function` or `NO HANDLER` clause.
5785+ pub handler : Option < FdwRoutineClause > ,
5786+ /// Optional `VALIDATOR validator_function` or `NO VALIDATOR` clause.
5787+ pub validator : Option < FdwRoutineClause > ,
5788+ /// Optional `OPTIONS (key 'value', ...)` clause.
5789+ pub options : Option < Vec < CreateServerOption > > ,
5790+ }
5791+
5792+ impl fmt:: Display for CreateForeignDataWrapper {
5793+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
5794+ write ! ( f, "CREATE FOREIGN DATA WRAPPER {}" , self . name) ?;
5795+ if let Some ( handler) = & self . handler {
5796+ match handler {
5797+ FdwRoutineClause :: Function ( name) => write ! ( f, " HANDLER {name}" ) ?,
5798+ FdwRoutineClause :: NoFunction => write ! ( f, " NO HANDLER" ) ?,
5799+ }
5800+ }
5801+ if let Some ( validator) = & self . validator {
5802+ match validator {
5803+ FdwRoutineClause :: Function ( name) => write ! ( f, " VALIDATOR {name}" ) ?,
5804+ FdwRoutineClause :: NoFunction => write ! ( f, " NO VALIDATOR" ) ?,
5805+ }
5806+ }
5807+ if let Some ( options) = & self . options {
5808+ write ! ( f, " OPTIONS ({})" , display_comma_separated( options) ) ?;
5809+ }
5810+ Ok ( ( ) )
5811+ }
5812+ }
5813+
5814+ impl From < CreateForeignDataWrapper > for crate :: ast:: Statement {
5815+ fn from ( v : CreateForeignDataWrapper ) -> Self {
5816+ crate :: ast:: Statement :: CreateForeignDataWrapper ( v)
5817+ }
5818+ }
5819+
5820+ /// A `CREATE FOREIGN TABLE` statement.
5821+ ///
5822+ /// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createforeigntable.html)
5823+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
5824+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
5825+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
5826+ pub struct CreateForeignTable {
5827+ /// The foreign table name.
5828+ #[ cfg_attr( feature = "visitor" , visit( with = "visit_relation" ) ) ]
5829+ pub name : ObjectName ,
5830+ /// Whether `IF NOT EXISTS` was specified.
5831+ pub if_not_exists : bool ,
5832+ /// Column definitions.
5833+ pub columns : Vec < ColumnDef > ,
5834+ /// The `SERVER server_name` clause.
5835+ pub server_name : Ident ,
5836+ /// Optional `OPTIONS (key 'value', ...)` clause at the table level.
5837+ pub options : Option < Vec < CreateServerOption > > ,
5838+ }
5839+
5840+ impl fmt:: Display for CreateForeignTable {
5841+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
5842+ write ! (
5843+ f,
5844+ "CREATE FOREIGN TABLE {if_not_exists}{name} ({columns}) SERVER {server_name}" ,
5845+ if_not_exists = if self . if_not_exists { "IF NOT EXISTS " } else { "" } ,
5846+ name = self . name,
5847+ columns = display_comma_separated( & self . columns) ,
5848+ server_name = self . server_name,
5849+ ) ?;
5850+ if let Some ( options) = & self . options {
5851+ write ! ( f, " OPTIONS ({})" , display_comma_separated( options) ) ?;
5852+ }
5853+ Ok ( ( ) )
5854+ }
5855+ }
5856+
5857+ impl From < CreateForeignTable > for crate :: ast:: Statement {
5858+ fn from ( v : CreateForeignTable ) -> Self {
5859+ crate :: ast:: Statement :: CreateForeignTable ( v)
5860+ }
5861+ }
5862+
57615863/// CREATE AGGREGATE statement.
57625864/// See <https://www.postgresql.org/docs/current/sql-createaggregate.html>
57635865#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
0 commit comments