@@ -43,13 +43,14 @@ use crate::ast::{
4343 } ,
4444 ArgMode , AttachedToken , CommentDef , ConditionalStatements , CreateFunctionBody ,
4545 CreateFunctionUsing , CreateTableLikeKind , CreateTableOptions , CreateViewParams , DataType , Expr ,
46- FileFormat , FunctionBehavior , FunctionCalledOnNull , FunctionDesc , FunctionDeterminismSpecifier ,
47- FunctionParallel , HiveDistributionStyle , HiveFormat , HiveIOFormat , HiveRowFormat ,
48- HiveSetLocation , Ident , InitializeKind , MySQLColumnPosition , ObjectName , OnCommit ,
49- OneOrManyWithParens , OperateFunctionArg , OrderByExpr , ProjectionSelect , Query , RefreshModeKind ,
50- RowAccessPolicy , SequenceOptions , Spanned , SqlOption , StorageSerializationPolicy , TableVersion ,
51- Tag , TriggerEvent , TriggerExecBody , TriggerObject , TriggerPeriod , TriggerReferencing , Value ,
52- ValueWithSpan , WrappedCollection ,
46+ FileFormat , FunctionBehavior , FunctionCalledOnNull , FunctionDefinitionSetParam , FunctionDesc ,
47+ FunctionDeterminismSpecifier , FunctionParallel , FunctionSecurity , HiveDistributionStyle ,
48+ HiveFormat , HiveIOFormat , HiveRowFormat , HiveSetLocation , Ident , InitializeKind ,
49+ MySQLColumnPosition , ObjectName , OnCommit , OneOrManyWithParens , OperateFunctionArg ,
50+ OrderByExpr , ProjectionSelect , Query , RefreshModeKind , RowAccessPolicy , SequenceOptions ,
51+ Spanned , SqlOption , StorageSerializationPolicy , TableVersion , Tag , TriggerEvent ,
52+ TriggerExecBody , TriggerObject , TriggerPeriod , TriggerReferencing , Value , ValueWithSpan ,
53+ WrappedCollection ,
5354} ;
5455use crate :: display_utils:: { DisplayCommaSeparated , Indent , NewLine , SpaceOrNewline } ;
5556use crate :: keywords:: Keyword ;
@@ -2697,6 +2698,14 @@ pub struct CreateTable {
26972698 /// <https://www.postgresql.org/docs/current/ddl-inherit.html>
26982699 /// <https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-PARMS-INHERITS>
26992700 pub inherits : Option < Vec < ObjectName > > ,
2701+ /// PostgreSQL `PARTITION OF` clause to create a partition of a parent table.
2702+ /// Contains the parent table name.
2703+ /// <https://www.postgresql.org/docs/current/sql-createtable.html>
2704+ #[ cfg_attr( feature = "visitor" , visit( with = "visit_relation" ) ) ]
2705+ pub partition_of : Option < ObjectName > ,
2706+ /// PostgreSQL partition bound specification for PARTITION OF.
2707+ /// <https://www.postgresql.org/docs/current/sql-createtable.html>
2708+ pub for_values : Option < ForValues > ,
27002709 /// SQLite "STRICT" clause.
27012710 /// if the "STRICT" table-option keyword is added to the end, after the closing ")",
27022711 /// then strict typing rules apply to that table.
@@ -2792,6 +2801,9 @@ impl fmt::Display for CreateTable {
27922801 dynamic = if self . dynamic { "DYNAMIC " } else { "" } ,
27932802 name = self . name,
27942803 ) ?;
2804+ if let Some ( partition_of) = & self . partition_of {
2805+ write ! ( f, " PARTITION OF {partition_of}" ) ?;
2806+ }
27952807 if let Some ( on_cluster) = & self . on_cluster {
27962808 write ! ( f, " ON CLUSTER {on_cluster}" ) ?;
27972809 }
@@ -2806,12 +2818,19 @@ impl fmt::Display for CreateTable {
28062818 Indent ( DisplayCommaSeparated ( & self . constraints ) ) . fmt ( f) ?;
28072819 NewLine . fmt ( f) ?;
28082820 f. write_str ( ")" ) ?;
2809- } else if self . query . is_none ( ) && self . like . is_none ( ) && self . clone . is_none ( ) {
2821+ } else if self . query . is_none ( )
2822+ && self . like . is_none ( )
2823+ && self . clone . is_none ( )
2824+ && self . partition_of . is_none ( )
2825+ {
28102826 // PostgreSQL allows `CREATE TABLE t ();`, but requires empty parens
28112827 f. write_str ( " ()" ) ?;
28122828 } else if let Some ( CreateTableLikeKind :: Parenthesized ( like_in_columns_list) ) = & self . like {
28132829 write ! ( f, " ({like_in_columns_list})" ) ?;
28142830 }
2831+ if let Some ( for_values) = & self . for_values {
2832+ write ! ( f, " {for_values}" ) ?;
2833+ }
28152834
28162835 // Hive table comment should be after column definitions, please refer to:
28172836 // [Hive](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTable)
@@ -3053,6 +3072,76 @@ impl fmt::Display for CreateTable {
30533072 }
30543073}
30553074
3075+ /// PostgreSQL partition bound specification for `PARTITION OF`.
3076+ ///
3077+ /// Specifies partition bounds for a child partition table.
3078+ ///
3079+ /// See [PostgreSQL](https://www.postgresql.org/docs/current/sql-createtable.html)
3080+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
3081+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
3082+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
3083+ pub enum ForValues {
3084+ /// `FOR VALUES IN (expr, ...)`
3085+ In ( Vec < Expr > ) ,
3086+ /// `FOR VALUES FROM (expr|MINVALUE|MAXVALUE, ...) TO (expr|MINVALUE|MAXVALUE, ...)`
3087+ From {
3088+ from : Vec < PartitionBoundValue > ,
3089+ to : Vec < PartitionBoundValue > ,
3090+ } ,
3091+ /// `FOR VALUES WITH (MODULUS n, REMAINDER r)`
3092+ With { modulus : u64 , remainder : u64 } ,
3093+ /// `DEFAULT`
3094+ Default ,
3095+ }
3096+
3097+ impl fmt:: Display for ForValues {
3098+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
3099+ match self {
3100+ ForValues :: In ( values) => {
3101+ write ! ( f, "FOR VALUES IN ({})" , display_comma_separated( values) )
3102+ }
3103+ ForValues :: From { from, to } => {
3104+ write ! (
3105+ f,
3106+ "FOR VALUES FROM ({}) TO ({})" ,
3107+ display_comma_separated( from) ,
3108+ display_comma_separated( to)
3109+ )
3110+ }
3111+ ForValues :: With { modulus, remainder } => {
3112+ write ! (
3113+ f,
3114+ "FOR VALUES WITH (MODULUS {modulus}, REMAINDER {remainder})"
3115+ )
3116+ }
3117+ ForValues :: Default => write ! ( f, "DEFAULT" ) ,
3118+ }
3119+ }
3120+ }
3121+
3122+ /// A value in a partition bound specification.
3123+ ///
3124+ /// Used in RANGE partition bounds where values can be expressions,
3125+ /// MINVALUE (negative infinity), or MAXVALUE (positive infinity).
3126+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
3127+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
3128+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
3129+ pub enum PartitionBoundValue {
3130+ Expr ( Expr ) ,
3131+ MinValue ,
3132+ MaxValue ,
3133+ }
3134+
3135+ impl fmt:: Display for PartitionBoundValue {
3136+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
3137+ match self {
3138+ PartitionBoundValue :: Expr ( expr) => write ! ( f, "{expr}" ) ,
3139+ PartitionBoundValue :: MinValue => write ! ( f, "MINVALUE" ) ,
3140+ PartitionBoundValue :: MaxValue => write ! ( f, "MAXVALUE" ) ,
3141+ }
3142+ }
3143+ }
3144+
30563145#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
30573146#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
30583147#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -3138,6 +3227,14 @@ pub struct CreateFunction {
31383227 ///
31393228 /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-createfunction.html)
31403229 pub parallel : Option < FunctionParallel > ,
3230+ /// SECURITY { DEFINER | INVOKER }
3231+ ///
3232+ /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-createfunction.html)
3233+ pub security : Option < FunctionSecurity > ,
3234+ /// SET configuration_parameter clauses
3235+ ///
3236+ /// [PostgreSQL](https://www.postgresql.org/docs/current/sql-createfunction.html)
3237+ pub set_params : Vec < FunctionDefinitionSetParam > ,
31413238 /// USING ... (Hive only)
31423239 pub using : Option < CreateFunctionUsing > ,
31433240 /// Language used in a UDF definition.
@@ -3204,6 +3301,12 @@ impl fmt::Display for CreateFunction {
32043301 if let Some ( parallel) = & self . parallel {
32053302 write ! ( f, " {parallel}" ) ?;
32063303 }
3304+ if let Some ( security) = & self . security {
3305+ write ! ( f, " {security}" ) ?;
3306+ }
3307+ for set_param in & self . set_params {
3308+ write ! ( f, " {set_param}" ) ?;
3309+ }
32073310 if let Some ( remote_connection) = & self . remote_connection {
32083311 write ! ( f, " REMOTE WITH CONNECTION {remote_connection}" ) ?;
32093312 }
0 commit comments