@@ -2860,16 +2860,41 @@ impl fmt::Display for OrderBy {
28602860pub struct OrderByExpr {
28612861 /// The expression to order by.
28622862 pub expr : Expr ,
2863+ /// Optional PostgreSQL `USING <operator>` clause.
2864+ pub using_operator : Option < OrderByUsingOperator > ,
28632865 /// Ordering options such as `ASC`/`DESC` and `NULLS` behavior.
28642866 pub options : OrderByOptions ,
28652867 /// Optional `WITH FILL` clause (ClickHouse extension) which specifies how to fill gaps.
28662868 pub with_fill : Option < WithFill > ,
28672869}
28682870
2871+ /// An operator used in PostgreSQL's `ORDER BY ... USING <operator>` clause.
2872+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2873+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2874+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2875+ pub enum OrderByUsingOperator {
2876+ /// A symbolic operator such as `<`, `>`, or `~<~`.
2877+ Symbol ( String ) ,
2878+ /// PostgreSQL `OPERATOR(...)` syntax, e.g. `OPERATOR(pg_catalog.<)`.
2879+ Qualified ( Vec < String > ) ,
2880+ }
2881+
2882+ impl fmt:: Display for OrderByUsingOperator {
2883+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
2884+ match self {
2885+ OrderByUsingOperator :: Symbol ( op) => write ! ( f, "{op}" ) ,
2886+ OrderByUsingOperator :: Qualified ( path) => {
2887+ write ! ( f, "OPERATOR({})" , display_separated( path, "." ) )
2888+ }
2889+ }
2890+ }
2891+ }
2892+
28692893impl From < Ident > for OrderByExpr {
28702894 fn from ( ident : Ident ) -> Self {
28712895 OrderByExpr {
28722896 expr : Expr :: Identifier ( ident) ,
2897+ using_operator : None ,
28732898 options : OrderByOptions :: default ( ) ,
28742899 with_fill : None ,
28752900 }
@@ -2878,7 +2903,11 @@ impl From<Ident> for OrderByExpr {
28782903
28792904impl fmt:: Display for OrderByExpr {
28802905 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
2881- write ! ( f, "{}{}" , self . expr, self . options) ?;
2906+ write ! ( f, "{}" , self . expr) ?;
2907+ if let Some ( using_operator) = & self . using_operator {
2908+ write ! ( f, " USING {using_operator}" ) ?;
2909+ }
2910+ write ! ( f, "{}" , self . options) ?;
28822911 if let Some ( ref with_fill) = self . with_fill {
28832912 write ! ( f, " {with_fill}" ) ?
28842913 }
0 commit comments