apache / apache/datafusion-sqlparser-rs
Postgres does not limit which operators can be used with `ANY` and `ALL`
- Vorherrschende Sprache
- Rust
- Sterne
- 3.5k
- Forks
- 772
- Ø Merge
- 4 T. 9 Std.
- Gemergte PRs (30 T.)
- 17
Beschreibung
In PR #963 a check was introduced which limits which operators can be used with `ANY` and `ALL` expressions.
Postgres can parse more (possibly _all_ binary operators, investigation pending) in this location. Postgres only seems to care that the operator yields a boolean - which is a semantic error, not a syntax (parse) error.
Example (semantic error, not a parse error):
```
select 123 % ANY(array[246]);
ERROR: op ANY/ALL (array) requires operator to yield boolean
LINE 1: select 123 % ANY(array[246]);
^
```
The following code in `src/parser/mod.rs:2893-2908` is where the allowlist of operators is enforced:
```rust
if !matches!(
op,
BinaryOperator::Gt
| BinaryOperator::Lt
| BinaryOperator::GtEq
| BinaryOperator::LtEq
| BinaryOperator::Eq
| BinaryOperator::NotEq
) {
return parser_err!(
format!(
"Expected one of [=, >, <, =>, =<, !=] as comparison operator, found: {op}"
),
tok.span.start
);
};
```
I propose that instead of hard-coding the allowed operators we instead check if the dialect is Postgres, and if so allow arbitrary `BinaryOperator`s to be used. Existing behaviour will be preserved for all other dialects.
This is a blocker for a new customer at my day job - I will do the work myself - so really I'm looking for feedback on the suggested approach.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne in src/parser/mod.rs:2893-2908, wo die Operator-Allowlist für ANY/ALL durchgesetzt wird, und untersuche, wie der Postgres-Dialekt dort dargestellt wird. Vergleiche das Postgres-Verhalten im Beispiel mit der bestehenden Einschränkung für Nicht-Postgres-Dialekte. Fertig ist die Änderung, wenn Postgres beliebige binäre Operatoren für diese Ausdrücke akzeptiert, während andere Dialekte die aktuelle Allowlist beibehalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- postgresql, rust
- Bereich
- databases
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100