PostgreSQL: Render prefix |/ and ||/ operators with a space
diff --git a/src/ast/mod.rs b/src/ast/mod.rs index dcfd1a9..92a0f92 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs
@@ -1964,7 +1964,9 @@ | UnaryOperator::DoubleAt | UnaryOperator::PGAbs | UnaryOperator::QuestionDash - | UnaryOperator::QuestionPipe => write!(f, "{op} {expr}"), + | UnaryOperator::QuestionPipe + | UnaryOperator::PGSquareRoot + | UnaryOperator::PGCubeRoot => write!(f, "{op} {expr}"), UnaryOperator::Minus => { if starts_with_operator_char(expr) { write!(f, "{op} {expr}") @@ -1972,11 +1974,9 @@ write!(f, "{op}{expr}") } } - UnaryOperator::Plus - | UnaryOperator::BangNot - | UnaryOperator::PGPrefixFactorial - | UnaryOperator::PGSquareRoot - | UnaryOperator::PGCubeRoot => write!(f, "{op}{expr}"), + UnaryOperator::Plus | UnaryOperator::BangNot | UnaryOperator::PGPrefixFactorial => { + write!(f, "{op}{expr}") + } }, Expr::Convert { is_try,
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index ab2d4b8..1985c7f 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs
@@ -2623,8 +2623,6 @@ #[test] fn parse_pg_unary_ops() { let pg_unary_ops = &[ - ("SELECT |/a", UnaryOperator::PGSquareRoot), - ("SELECT ||/a", UnaryOperator::PGCubeRoot), ("SELECT !!a", UnaryOperator::PGPrefixFactorial), ("SELECT @ a", UnaryOperator::PGAbs), ]; @@ -2638,6 +2636,21 @@ select.projection[0] ); } + + for (str_op, op) in [ + ("|/", UnaryOperator::PGSquareRoot), + ("||/", UnaryOperator::PGCubeRoot), + ] { + let select = pg().verified_only_select(&format!("SELECT {str_op} a")); + assert_eq!( + SelectItem::UnnamedExpr(Expr::UnaryOp { + op, + expr: Box::new(Expr::Identifier(Ident::new("a"))), + }), + select.projection[0] + ); + pg().one_statement_parses_to(&format!("SELECT {str_op}a"), &format!("SELECT {str_op} a")); + } } #[test] @@ -9984,3 +9997,10 @@ pg().verified_stmt("SELECT - @ 2"); pg().one_statement_parses_to("SELECT - #x", "SELECT - # x"); } + +#[test] +fn parse_pg_roots_render_apart_from_operand() { + pg().verified_stmt("SELECT |/ -2"); + pg().verified_stmt("SELECT ||/ -2"); + pg().verified_stmt("SELECT |/ ||/ 2"); +}