apache / apache/datafusion-sqlparser-rs
Outdated operation precedence.
- Langage dominant
- Rust
- Étoiles
- 3.5k
- Forks
- 772
- Merge moyen
- 4 j 9 h
- PR mergées (30 j)
- 17
Description
Here's an expression: `SELECT ~1 + 2`. If you plug it into `PostgreSQL` interpreter, here's what the output looks like:
```
postgres=# select ~1 + 2;
?column?
----------
-4
(1 row)
postgres=# select ~(1 + 2);
?column?
----------
-4
(1 row)
postgres=# select (~1) + 2;
?column?
----------
0
(1 row)
```
As you can see here, and according to [operation precedence](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-PRECEDENCE) listed in documentation, the `+` operation is more powerful than the `~` operation, and thus we have PGBitwiseNot(1 + 2). However, if we plug this into the parser, we get the following AST:
```
...
projection: [
UnnamedExpr(
BinaryOp {
left: UnaryOp {
op: PGBitwiseNot,
expr: Value(
Number(
"1",
false,
),
),
},
op: Plus,
right: Value(
Number(
"2",
false,
),
),
},
),
],
...
```
Which is implying `(~1) + 2` instead of `~(1 + 2)`. This should be fixed.
**UPDATE:**
In code, I found a reference to an old [PostgreSQL precedence table](https://www.postgresql.org/docs/7.0/operators.htm#AEN2026), using which the parser is built. However, this table is for a very old (`7.0`, released `May 8, 2000`) version of PostgreSQL. There latest version is `15.1`. Shouldn't this be updated?
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par lire la table de précédence de PostgreSQL 7.0 référencée par le parser ainsi que la documentation actuelle de PostgreSQL sur la précédence, liée dans l’issue. Comparez l’AST du parser pour `SELECT ~1 + 2` avec le comportement documenté et les trois requêtes d’exemple. C’est terminé lorsque le parser applique la précédence prévue et produit l’AST correspondant.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- postgresql, rust, sql
- Domaine
- compilers, databases
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100