wugeer commented on code in PR #1472:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1472#discussion_r1825279646


##########
src/parser/mod.rs:
##########
@@ -2800,11 +2814,40 @@ impl<'a> Parser<'a> {
                 format: None,
             })
         } else if Token::ExclamationMark == tok {
-            // PostgreSQL factorial operation
-            Ok(Expr::UnaryOp {
-                op: UnaryOperator::PGPostfixFactorial,
-                expr: Box::new(expr),
-            })
+            if self.dialect.supports_factorial_operator() {
+                match expr {
+                    Expr::Value(_) | Expr::Identifier(_) | Expr::Nested(_) | 
Expr::BinaryOp{..} => Ok(Expr::UnaryOp {
+                        op: UnaryOperator::PGPostfixFactorial,
+                        expr: Box::new(expr),
+                    }),
+                    _ => {
+                        self.expected(
+                            "Value or Identifier or  Nested or BinaryOp struct 
before factorial operator(!)", self.peek_token())
+                    },
+                }
+            } else if self.dialect.supports_bang_not_operator() {

Review Comment:
   @iffyio Sorry, I missed this reply.
   My intention with this code block was to provide additional context checks 
and more meaningful error messages. Without it, the error messages would be 
less precise, so I’m hesitant about whether to remove it or not.
   without it
   ```bash
    cargo run --features json_example --example cli err.sql --hive
       Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
        Running `target/debug/examples/cli err.sql --hive`
   Parsing from file 'err.sql' using HiveDialect
   2024-10-31T23:24:09.204Z DEBUG [sqlparser::parser] Parsing sql 'select a!, 
(b+c)!, C+D !
   '...
   2024-10-31T23:24:09.204Z DEBUG [sqlparser::parser] parsing expr
   2024-10-31T23:24:09.204Z DEBUG [sqlparser::parser] prefix: Identifier(Ident 
{ value: "a", quote_style: None })
   2024-10-31T23:24:09.204Z DEBUG [sqlparser::dialect] 
get_next_precedence_full() TokenWithLocation { token: ExclamationMark, 
location: Location { line: 1, column: 9 } }
   2024-10-31T23:24:09.204Z DEBUG [sqlparser::parser] next precedence: 50
   Error during parsing: ParserError("No infix parser for token ExclamationMark 
at Line: 1, Column: 9")
   ```
   currently
   ```bash
   cargo run --features json_example --example cli err.sql --hive
      Compiling sqlparser v0.51.0 (/home/xiehw/code/person/rust/sqlparser-rs)
       Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.04s
        Running `target/debug/examples/cli err.sql --hive`
   Parsing from file 'err.sql' using HiveDialect
   2024-10-31T23:24:17.700Z DEBUG [sqlparser::parser] Parsing sql 'select a!, 
(b+c)!, C+D !
   '...
   2024-10-31T23:24:17.700Z DEBUG [sqlparser::parser] parsing expr
   2024-10-31T23:24:17.700Z DEBUG [sqlparser::parser] prefix: Identifier(Ident 
{ value: "a", quote_style: None })
   2024-10-31T23:24:17.700Z DEBUG [sqlparser::dialect] 
get_next_precedence_full() TokenWithLocation { token: ExclamationMark, 
location: Location { line: 1, column: 9 } }
   2024-10-31T23:24:17.700Z DEBUG [sqlparser::parser] next precedence: 50
   Error during parsing: ParserError("current dialect support bang not 
operator, but with wrong syntax at Line: 1, Column: 9")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to