Skip to content

fix: allow arbitrary operators with ANY and ALL on Postgres #1842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3471,7 +3471,7 @@ impl<'a> Parser<'a> {
right
};

if !matches!(
if !dialect_of!(self is PostgreSqlDialect) && !matches!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the dialect trait for this logic (dialect_of is effectively deprecated internally)? something like if self.dialect.supports_arbitrary_comparison_in_subquery_operator()

op,
BinaryOperator::Gt
| BinaryOperator::Lt
Expand Down
30 changes: 30 additions & 0 deletions tests/sqlparser_postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))") {
Expand Down