@@ -3032,6 +3032,8 @@ pub enum Statement {
3032
3032
statement : Box < Statement > ,
3033
3033
/// Optional output format of explain
3034
3034
format : Option < AnalyzeFormat > ,
3035
+ /// Postgres style utility options, `(analyze, verbose true)`
3036
+ options : Option < Vec < UtilityOption > > ,
3035
3037
} ,
3036
3038
/// ```sql
3037
3039
/// SAVEPOINT
@@ -3219,6 +3221,7 @@ impl fmt::Display for Statement {
3219
3221
analyze,
3220
3222
statement,
3221
3223
format,
3224
+ options,
3222
3225
} => {
3223
3226
write ! ( f, "{describe_alias} " ) ?;
3224
3227
@@ -3234,6 +3237,10 @@ impl fmt::Display for Statement {
3234
3237
write ! ( f, "FORMAT {format} " ) ?;
3235
3238
}
3236
3239
3240
+ if let Some ( options) = options {
3241
+ write ! ( f, "({}) " , display_comma_separated( options) ) ?;
3242
+ }
3243
+
3237
3244
write ! ( f, "{statement}" )
3238
3245
}
3239
3246
Statement :: Query ( s) => write ! ( f, "{s}" ) ,
@@ -7125,6 +7132,47 @@ where
7125
7132
}
7126
7133
}
7127
7134
7135
+ /// Represents a single PostgreSQL utility option.
7136
+ ///
7137
+ /// A utility option is a key-value pair where the key is an identifier (IDENT) and the value
7138
+ /// can be one of the following:
7139
+ /// - A number with an optional sign (`+` or `-`). Example: `+10`, `-10.2`, `3`
7140
+ /// - A non-keyword string. Example: `option1`, `'option2'`, `"option3"`
7141
+ /// - keyword: `TRUE`, `FALSE`, `ON` (`off` is also accept).
7142
+ /// - Empty. Example: `ANALYZE` (identifier only)
7143
+ ///
7144
+ /// Utility options are used in various PostgreSQL DDL statements, including statements such as
7145
+ /// `CLUSTER`, `EXPLAIN`, `VACUUM`, and `REINDEX`. These statements format options as `( option [, ...] )`.
7146
+ ///
7147
+ /// [CLUSTER](https://www.postgresql.org/docs/current/sql-cluster.html)
7148
+ /// [EXPLAIN](https://www.postgresql.org/docs/current/sql-explain.html)
7149
+ /// [VACUUM](https://www.postgresql.org/docs/current/sql-vacuum.html)
7150
+ /// [REINDEX](https://www.postgresql.org/docs/current/sql-reindex.html)
7151
+ ///
7152
+ /// For example, the `EXPLAIN` AND `VACUUM` statements with options might look like this:
7153
+ /// ```sql
7154
+ /// EXPLAIN (ANALYZE, VERBOSE TRUE, FORMAT TEXT) SELECT * FROM my_table;
7155
+ ///
7156
+ /// VACCUM (VERBOSE, ANALYZE ON, PARALLEL 10) my_table;
7157
+ /// ```
7158
+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
7159
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
7160
+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
7161
+ pub struct UtilityOption {
7162
+ pub name : Ident ,
7163
+ pub arg : Option < Expr > ,
7164
+ }
7165
+
7166
+ impl Display for UtilityOption {
7167
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
7168
+ if let Some ( ref arg) = self . arg {
7169
+ write ! ( f, "{} {}" , self . name, arg)
7170
+ } else {
7171
+ write ! ( f, "{}" , self . name)
7172
+ }
7173
+ }
7174
+ }
7175
+
7128
7176
#[ cfg( test) ]
7129
7177
mod tests {
7130
7178
use super :: * ;
0 commit comments