apache / apache/datafusion-sqlparser-rs
Outdated operation precedence.
- 主要語言
- Rust
- 星號
- 3.5k
- 分支
- 772
- 平均合併
- 4 天 9 小時
- 30 天內合併 PR
- 17
描述
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?
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
首先閱讀 parser 所參照的 PostgreSQL 7.0 優先級表,以及 issue 中連結的目前 PostgreSQL 優先級文件。將 parser 對 `SELECT ~1 + 2` 產生的 AST 與文件所述行為和三個範例查詢進行比較。當 parser 套用預期的優先級並產生相應的 AST 時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- postgresql, rust, sql
- 領域
- compilers, databases
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100