diff --git a/src/parser/mod.rs b/src/parser/mod.rs index fc6f44376..64a79aa81 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -3471,7 +3471,7 @@ impl<'a> Parser<'a> { right }; - if !matches!( + if !dialect_of!(self is PostgreSqlDialect) && !matches!( op, BinaryOperator::Gt | BinaryOperator::Lt diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 859eca453..0f26bccc8 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -5936,6 +5936,36 @@ fn parse_bitstring_literal() { ); } +#[test] +fn parse_arbitrary_operator_with_any_and_all() { + // The following statement is semantically non-sensical on vanilla postgres but it should *parse* in order to + // support situations where PG operators have been overloaded. + let select = pg().verified_only_select("SELECT 123 % ANY(ARRAY[1, 2, 3])"); + assert!( + matches!( + select.projection[0], + SelectItem::UnnamedExpr(Expr::AnyOp { + left: _, + compare_op: BinaryOperator::Modulo, + right: _, + is_some: false + }) + ) + ); + + let select = pg().verified_only_select("SELECT 123 % ALL(ARRAY[1, 2, 3])"); + assert!( + matches!( + select.projection[0], + SelectItem::UnnamedExpr(Expr::AllOp { + left: _, + compare_op: BinaryOperator::Modulo, + right: _, + }) + ) + ); +} + #[test] fn parse_varbit_datatype() { match pg_and_generic().verified_stmt("CREATE TABLE foo (x VARBIT, y VARBIT(42))") {