apache / apache/datafusion-sqlparser-rs

Postgres does not limit which operators can be used with `ANY` and `ALL`

Aperta
#1,841 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Rust
Stelle
3.5k
Fork
772
Merge medio
4g 9h
PR unite (30g)
17

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia in src/parser/mod.rs:2893-2908, dove viene applicata la allowlist degli operatori per ANY/ALL, e analizza come viene rappresentato il dialetto Postgres. Confronta il comportamento di Postgres nell’esempio con la restrizione esistente per i dialetti non-Postgres. Il lavoro è completato quando Postgres accetta operatori binari arbitrari per queste espressioni, mentre gli altri dialetti mantengono la allowlist attuale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
postgresql, rust
Ambito
databases
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.