File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -93,6 +93,10 @@ export const exprMap: CstToDocMap<AllExprNodes> = {
9393 // String concatenation with whitespace (MySQL / MariaDB)
9494 return print . spaced ( [ "left" , "right" ] ) ;
9595 }
96+ if ( isString ( node . operator ) && isCompactOp ( node . operator ) ) {
97+ // Some operators are better formatted without spaces around them
98+ return print ( [ "left" , "operator" , "right" ] ) ;
99+ }
96100 return print . spaced ( [ "left" , "operator" , "right" ] ) ;
97101 } ,
98102 prefix_op_expr : ( print , node ) =>
@@ -307,3 +311,5 @@ const isFunctionContext = (
307311} ;
308312
309313const isBooleanOp = ( { name } : Keyword ) => name === "AND" || name === "OR" ;
314+
315+ const isCompactOp = ( op : string ) => op === "->" || op === "->>" ;
Original file line number Diff line number Diff line change @@ -233,6 +233,11 @@ describe("expr", () => {
233233 await testPostgresql ( `SELECT 5 OPERATOR(+) 6` ) ;
234234 await testPostgresql ( `SELECT x OPERATOR(my_schema.>>) y FROM tbl` ) ;
235235 } ) ;
236+
237+ it ( `formats -> and ->> operators without spaces` , async ( ) => {
238+ await testPostgresql ( `SELECT user->'name'` ) ;
239+ await testPostgresql ( `SELECT col->>'field'->>'field' FROM tbl` ) ;
240+ } ) ;
236241 } ) ;
237242
238243 describe ( "MySQL" , ( ) => {
You can’t perform that action at this time.
0 commit comments