You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/09/22 16:13:26 UTC
(datafusion-sqlparser-rs) 01/01: PostgreSQL: Render prefix |/ and ||/ operators with a space (#2545)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-2545-e05707b59306481cc8959694b064fbe94f9a9a49
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git
commit 5d9de3617123e8a633f5dc35ef39fb5a045dd3eb
Author: Luca Cappelletti <ca...@gmail.com>
AuthorDate: Tue Sep 22 16:13:15 2026 +0000
PostgreSQL: Render prefix |/ and ||/ operators with a space (#2545)
---
src/ast/mod.rs | 12 ++++++------
tests/sqlparser_postgres.rs | 24 ++++++++++++++++++++++--
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index 040878bd8..85344da92 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -1971,7 +1971,9 @@ impl fmt::Display for Expr {
| 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}")
@@ -1979,11 +1981,9 @@ impl fmt::Display for Expr {
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 ab2d4b8ee..1985c7fcd 100644
--- a/tests/sqlparser_postgres.rs
+++ b/tests/sqlparser_postgres.rs
@@ -2623,8 +2623,6 @@ fn parse_ampersand_arobase() {
#[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 @@ fn parse_pg_unary_ops() {
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 @@ fn parse_unary_minus_before_pg_prefix_operators() {
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");
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org