@@ -984,6 +984,47 @@ fn test_drop_trigger() {
984984 }
985985}
986986
987+ #[ test]
988+ fn parse_between_low_bound_precedence ( ) {
989+ match sqlite ( ) . verified_expr ( "a BETWEEN b > 1 AND c" ) {
990+ Expr :: Between { low, .. } => assert ! (
991+ matches!(
992+ * low,
993+ Expr :: BinaryOp {
994+ op: BinaryOperator :: Gt ,
995+ ..
996+ }
997+ ) ,
998+ "{low:?}"
999+ ) ,
1000+ other => panic ! ( "expected BETWEEN, got {other:?}" ) ,
1001+ }
1002+ sqlite ( ) . verified_expr ( "a BETWEEN b LIKE 'x' AND c" ) ;
1003+ sqlite ( ) . verified_expr ( "a BETWEEN b IS NOT NULL AND c" ) ;
1004+ sqlite ( ) . expr_parses_to ( "a BETWEEN b NOTNULL AND c" , "a BETWEEN b IS NOT NULL AND c" ) ;
1005+ sqlite ( ) . verified_expr ( "a BETWEEN b BETWEEN 1 AND 2 AND c" ) ;
1006+
1007+ // Operators after the high bound apply to the whole BETWEEN.
1008+ sqlite ( ) . verified_expr ( "5 BETWEEN 1 AND NULL IS NULL" ) ;
1009+ sqlite ( ) . verified_expr ( "5 BETWEEN 1 AND 10 = 1" ) ;
1010+
1011+ // The inner AND belongs to the bound expression, so the missing `)` is reported at FROM.
1012+ assert_eq ! (
1013+ sqlite( ) . parse_sql_statements( "SELECT a BETWEEN (1 AND 2 FROM t" ) ,
1014+ Err ( ParserError :: ParserError (
1015+ "Expected: ), found: FROM" . to_string( )
1016+ ) )
1017+ ) ;
1018+
1019+ assert_eq ! (
1020+ TestedDialects :: new( vec![ Box :: new( GenericDialect { } ) ] )
1021+ . parse_sql_statements( "SELECT a BETWEEN b > 1 AND c FROM t" ) ,
1022+ Err ( ParserError :: ParserError (
1023+ "Expected: AND, found: >" . to_string( )
1024+ ) )
1025+ ) ;
1026+ }
1027+
9871028#[ test]
9881029fn parse_pattern_operators_bind_at_like_precedence ( ) {
9891030 fn where_operator ( sql : & str ) -> BinaryOperator {
@@ -1517,7 +1558,6 @@ fn parse_on_conflict_target_predicate() {
15171558 other => panic ! ( "unexpected statement: {other:?}" ) ,
15181559 }
15191560}
1520-
15211561fn sqlite ( ) -> TestedDialects {
15221562 TestedDialects :: new ( vec ! [ Box :: new( SQLiteDialect { } ) ] )
15231563}
0 commit comments