@@ -348,6 +348,8 @@ pub enum Expr {
348
348
ListAgg ( ListAgg ) ,
349
349
/// The `ARRAY_AGG` function `SELECT ARRAY_AGG(... ORDER BY ...)`
350
350
ArrayAgg ( ArrayAgg ) ,
351
+ /// The `WITHIN GROUP` expr `... WITHIN GROUP (ORDER BY ...)`
352
+ WithinGroup ( WithinGroup ) ,
351
353
/// The `GROUPING SETS` expr.
352
354
GroupingSets ( Vec < Vec < Expr > > ) ,
353
355
/// The `CUBE` expr.
@@ -549,6 +551,7 @@ impl fmt::Display for Expr {
549
551
Expr :: ArraySubquery ( s) => write ! ( f, "ARRAY({})" , s) ,
550
552
Expr :: ListAgg ( listagg) => write ! ( f, "{}" , listagg) ,
551
553
Expr :: ArrayAgg ( arrayagg) => write ! ( f, "{}" , arrayagg) ,
554
+ Expr :: WithinGroup ( withingroup) => write ! ( f, "{}" , withingroup) ,
552
555
Expr :: GroupingSets ( sets) => {
553
556
write ! ( f, "GROUPING SETS (" ) ?;
554
557
let mut sep = "" ;
@@ -2523,6 +2526,26 @@ impl fmt::Display for ArrayAgg {
2523
2526
}
2524
2527
}
2525
2528
2529
+ /// A `WITHIN GROUP` invocation `<expr> WITHIN GROUP (ORDER BY <sort_expr> )`
2530
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2531
+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2532
+ pub struct WithinGroup {
2533
+ pub expr : Box < Expr > ,
2534
+ pub order_by : Vec < OrderByExpr > ,
2535
+ }
2536
+
2537
+ impl fmt:: Display for WithinGroup {
2538
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2539
+ write ! (
2540
+ f,
2541
+ "{} WITHIN GROUP (ORDER BY {})" ,
2542
+ self . expr,
2543
+ display_comma_separated( & self . order_by) ,
2544
+ ) ?;
2545
+ Ok ( ( ) )
2546
+ }
2547
+ }
2548
+
2526
2549
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2527
2550
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2528
2551
pub enum ObjectType {
0 commit comments