apache / apache/datafusion-sqlparser-rs
Postgres does not limit which operators can be used with `ANY` and `ALL`
- Ngôn ngữ chính
- Rust
- Star
- 3.5k
- Fork
- 772
- Merge trung bình
- 4 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 17
Mô tả
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.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Bắt đầu tại src/parser/mod.rs:2893-2908, nơi allowlist toán tử cho ANY/ALL được áp dụng, và kiểm tra cách dialect Postgres được biểu diễn ở đó. So sánh hành vi của Postgres trong ví dụ với hạn chế hiện có đối với các dialect không phải Postgres. Hoàn tất khi Postgres chấp nhận các toán tử nhị phân tùy ý cho những biểu thức này, trong khi các dialect khác vẫn giữ allowlist hiện tại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- postgresql, rust
- Lĩnh vực
- databases
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 35/100