@@ -926,6 +926,37 @@ fn test_drop_trigger() {
926926 }
927927}
928928
929+ #[ test]
930+ fn parse_pattern_operators_bind_at_like_precedence ( ) {
931+ fn where_operator ( sql : & str ) -> BinaryOperator {
932+ let Statement :: Query ( query) = sqlite ( ) . verified_stmt ( sql) else {
933+ panic ! ( "expected a query" ) ;
934+ } ;
935+ let SetExpr :: Select ( select) = * query. body else {
936+ panic ! ( "expected a select" ) ;
937+ } ;
938+ let Some ( Expr :: BinaryOp { op, .. } ) = select. selection else {
939+ panic ! ( "expected a WHERE binary operator" ) ;
940+ } ;
941+ op
942+ }
943+
944+ // Above AND, so the pattern does not swallow the rest of the expression.
945+ for operator in [ "REGEXP" , "MATCH" , "GLOB" , "LIKE" ] {
946+ let sql = format ! ( "SELECT 1 FROM t WHERE a {operator} 'p' AND b = 1" ) ;
947+ assert_eq ! ( where_operator( & sql) , BinaryOperator :: And , "{operator}" ) ;
948+ }
949+ // Below string concatenation, so the pattern is not cut short either.
950+ for ( operator, expected) in [
951+ ( "REGEXP" , BinaryOperator :: Regexp ) ,
952+ ( "MATCH" , BinaryOperator :: Match ) ,
953+ ( "GLOB" , BinaryOperator :: Glob ) ,
954+ ] {
955+ let sql = format ! ( "SELECT 1 FROM t WHERE a {operator} 'p' || 'q'" ) ;
956+ assert_eq ! ( where_operator( & sql) , expected, "{operator}" ) ;
957+ }
958+ }
959+
929960fn sqlite ( ) -> TestedDialects {
930961 TestedDialects :: new ( vec ! [ Box :: new( SQLiteDialect { } ) ] )
931962}
0 commit comments