You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by lu...@apache.org on 2026/09/19 20:46:03 UTC

(datafusion-sqlparser-rs) branch postgres-root-operators-display-space created (now 47edbf0e)

This is an automated email from the ASF dual-hosted git repository.

LucaCappelletti94 pushed a change to branch postgres-root-operators-display-space
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git


      at 47edbf0e Render prefix |/ and ||/ operators with a space

This branch includes the following new commits:

     new 47edbf0e Render prefix |/ and ||/ operators with a space

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org


(datafusion-sqlparser-rs) 01/01: Render prefix |/ and ||/ operators with a space

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

LucaCappelletti94 pushed a commit to branch postgres-root-operators-display-space
in repository https://gitbox.apache.org/repos/asf/datafusion-sqlparser-rs.git

commit 47edbf0e0fb2fec81a350380cbef36678ad567c1
Author: LucaCappelletti94 <ca...@gmail.com>
AuthorDate: Sat Sep 19 22:45:54 2026 +0200

    Render prefix |/ and ||/ operators with a space
---
 src/ast/mod.rs              |  2 ++
 tests/sqlparser_postgres.rs | 32 ++++++++++++++++++++++++++------
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index 20058b83..cd4509af 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -1966,6 +1966,8 @@ impl fmt::Display for Expr {
                         | UnaryOperator::DoubleAt
                         | UnaryOperator::QuestionDash
                         | UnaryOperator::QuestionPipe
+                        | UnaryOperator::PGSquareRoot
+                        | UnaryOperator::PGCubeRoot
                 ) {
                     write!(f, "{op} {expr}")
                 } else {
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs
index d71e49b2..c6751ccd 100644
--- a/tests/sqlparser_postgres.rs
+++ b/tests/sqlparser_postgres.rs
@@ -2622,12 +2622,7 @@ fn parse_ampersand_arobase() {
 
 #[test]
 fn parse_pg_unary_ops() {
-    let pg_unary_ops = &[
-        ("|/", UnaryOperator::PGSquareRoot),
-        ("||/", UnaryOperator::PGCubeRoot),
-        ("!!", UnaryOperator::PGPrefixFactorial),
-        ("@", UnaryOperator::PGAbs),
-    ];
+    let pg_unary_ops = &[("!!", UnaryOperator::PGPrefixFactorial), ("@", UnaryOperator::PGAbs)];
     for (str_op, op) in pg_unary_ops {
         let select = pg().verified_only_select(&format!("SELECT {}a", str_op));
         assert_eq!(
@@ -2638,6 +2633,24 @@ 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]
@@ -9953,3 +9966,10 @@ fn parse_insert_by_name_keywords_as_table_and_alias() {
         statement => panic!("Expected INSERT statement, got: {statement:?}"),
     }
 }
+
+#[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