@@ -11467,25 +11467,22 @@ fn parse_bang_not() {
11467
11467
let sql = "SELECT !a, !(b > 3)" ;
11468
11468
let Select { projection, .. } = dialects. verified_only_select ( sql) ;
11469
11469
11470
- for ( i, ( op, expr) ) in [
11471
- (
11472
- UnaryOperator :: BangNot ,
11473
- Box :: new ( Expr :: Identifier ( Ident :: new ( "a" ) ) ) ,
11474
- ) ,
11475
- (
11476
- UnaryOperator :: BangNot ,
11477
- Box :: new ( Expr :: Nested ( Box :: new ( Expr :: BinaryOp {
11478
- left : Box :: new ( Expr :: Identifier ( Ident :: new ( "b" ) ) ) ,
11479
- op : BinaryOperator :: Gt ,
11480
- right : Box :: new ( Expr :: Value ( Value :: Number ( "3" . parse ( ) . unwrap ( ) , false ) ) ) ,
11481
- } ) ) ) ,
11482
- ) ,
11470
+ for ( i, expr) in [
11471
+ Box :: new ( Expr :: Identifier ( Ident :: new ( "a" ) ) ) ,
11472
+ Box :: new ( Expr :: Nested ( Box :: new ( Expr :: BinaryOp {
11473
+ left : Box :: new ( Expr :: Identifier ( Ident :: new ( "b" ) ) ) ,
11474
+ op : BinaryOperator :: Gt ,
11475
+ right : Box :: new ( Expr :: Value ( Value :: Number ( "3" . parse ( ) . unwrap ( ) , false ) ) ) ,
11476
+ } ) ) ) ,
11483
11477
]
11484
11478
. into_iter ( )
11485
11479
. enumerate ( )
11486
11480
{
11487
11481
assert_eq ! (
11488
- SelectItem :: UnnamedExpr ( Expr :: UnaryOp { op: op, expr } ) ,
11482
+ SelectItem :: UnnamedExpr ( Expr :: UnaryOp {
11483
+ op: UnaryOperator :: BangNot ,
11484
+ expr
11485
+ } ) ,
11489
11486
projection[ i]
11490
11487
)
11491
11488
}
@@ -11511,3 +11508,69 @@ fn parse_bang_not() {
11511
11508
) ;
11512
11509
}
11513
11510
}
11511
+
11512
+ #[ test]
11513
+ fn parse_factorial_operator ( ) {
11514
+ let dialects = all_dialects_where ( |d| d. supports_factorial_operator ( ) ) ;
11515
+ let sql = "SELECT a!, (b + c)!" ;
11516
+ let Select { projection, .. } = dialects. verified_only_select ( sql) ;
11517
+
11518
+ for ( i, expr) in [
11519
+ Box :: new ( Expr :: Identifier ( Ident :: new ( "a" ) ) ) ,
11520
+ Box :: new ( Expr :: Nested ( Box :: new ( Expr :: BinaryOp {
11521
+ left : Box :: new ( Expr :: Identifier ( Ident :: new ( "b" ) ) ) ,
11522
+ op : BinaryOperator :: Plus ,
11523
+ right : Box :: new ( Expr :: Identifier ( Ident :: new ( "c" ) ) ) ,
11524
+ } ) ) ) ,
11525
+ ]
11526
+ . into_iter ( )
11527
+ . enumerate ( )
11528
+ {
11529
+ assert_eq ! (
11530
+ SelectItem :: UnnamedExpr ( Expr :: UnaryOp {
11531
+ op: UnaryOperator :: PGPostfixFactorial ,
11532
+ expr
11533
+ } ) ,
11534
+ projection[ i]
11535
+ )
11536
+ }
11537
+
11538
+ let sql_statements = [ "SELECT !a" , "SELECT !a b" , "SELECT !a as b" ] ;
11539
+
11540
+ for & sql in & sql_statements {
11541
+ assert_eq ! (
11542
+ dialects. parse_sql_statements( sql) . unwrap_err( ) ,
11543
+ ParserError :: ParserError ( "Expected: an expression, found: !" . to_string( ) )
11544
+ ) ;
11545
+ }
11546
+
11547
+ let sql_statements = [ "SELECT a!" , "SELECT a ! b" , "SELECT a ! as b" ] ;
11548
+
11549
+ // Due to the exclamation mark, which is both part of the `bang not` operator
11550
+ // and the `factorial` operator, additional filtering not supports
11551
+ // `bang not` operator is required here.
11552
+ let dialects =
11553
+ all_dialects_where ( |d| !d. supports_factorial_operator ( ) && !d. supports_bang_not_operator ( ) ) ;
11554
+
11555
+ for & sql in & sql_statements {
11556
+ assert_eq ! (
11557
+ dialects. parse_sql_statements( sql) . unwrap_err( ) ,
11558
+ ParserError :: ParserError ( "No infix parser for token ExclamationMark" . to_string( ) )
11559
+ ) ;
11560
+ }
11561
+
11562
+ // Due to the exclamation mark, which is both part of the `bang not` operator
11563
+ // and the `factorial` operator, additional filtering supports
11564
+ // `bang not` operator is required here.
11565
+ let dialects =
11566
+ all_dialects_where ( |d| !d. supports_factorial_operator ( ) && d. supports_bang_not_operator ( ) ) ;
11567
+
11568
+ for & sql in & sql_statements {
11569
+ assert_eq ! (
11570
+ dialects. parse_sql_statements( sql) . unwrap_err( ) ,
11571
+ ParserError :: ParserError (
11572
+ "current dialect support bang not operator, but with wrong syntax" . to_string( )
11573
+ )
11574
+ ) ;
11575
+ }
11576
+ }
0 commit comments