apache / apache/datafusion-sqlparser-rs
Postgres does not limit which operators can be used with `ANY` and `ALL`
- Lenguaje dominante
- Rust
- Estrellas
- 3.5k
- Forks
- 772
- Merge medio
- 4 d 9 h
- PR fusionados (30 d)
- 17
Descripción
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.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza en src/parser/mod.rs:2893-2908, donde se aplica la allowlist de operadores para ANY/ALL, e inspecciona cómo se representa allí el dialecto Postgres. Compara el comportamiento de Postgres en el ejemplo con la restricción existente para los dialectos que no son Postgres. Se considera terminado cuando Postgres acepta operadores binarios arbitrarios para estas expresiones, mientras que los demás dialectos conservan la allowlist actual.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- postgresql, rust
- Área
- databases
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100