apache / apache/datafusion-sqlparser-rs

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

Ouverte
#1,841 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Rust
Étoiles
3.5k
Forks
772
Merge moyen
4 j 9 h
PR mergées (30 j)
17

Description

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez dans src/parser/mod.rs:2893-2908, où la allowlist des opérateurs pour ANY/ALL est appliquée, et examinez comment le dialecte Postgres y est représenté. Comparez le comportement de Postgres dans l’exemple avec la restriction existante pour les dialectes autres que Postgres. C’est terminé lorsque Postgres accepte des opérateurs binaires arbitraires pour ces expressions, tandis que les autres dialectes conservent la allowlist actuelle.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
postgresql, rust
Domaine
databases
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.