PostgreSqlDialect: `*=` and `@@@` are split into two tokens,

Đang mở
#2,809 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
postgresql, rust
Lĩnh vực
compilers, databases

Hướng nghiên cứu

Start by running the reproduction with PostgreSqlDialect and Parser::parse_sql on SELECT a *= b and SELECT a @@@ b, then find where the tokenizer groups operator characters into operator tokens. The issue lists the operators to support (*=, *<>, *<, *<=, *>, *>=, @@@) and the OPERATOR(pg_catalog.*=) form. Done means each statement parses as a single operator and to_string() round-trips without splitting.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

PostgreSQL

version 0.63.0, PostgreSqlDialect.

PostgreSQL's lexer reads a run of operator characters as one operator (manual, "Lexical Structure", "Operators"; src/backend/parser/scan.l). However, sqlparser only recognizes a specific list, so operators end up split.

The composite type comparison operators (manual, "Composite Type Comparison")::

SELECT a *= b    -- Expected: an expression, found: =
SELECT a *<> b   -- Expected: an expression, found: <>
SELECT a *< b    -- Expected: an expression, found: <
SELECT a *<= b   -- Expected: an expression, found: <=
SELECT a *> b    -- Expected: an expression, found: >
SELECT a *>= b   -- Expected: an expression, found: >=

The @@@ operator doesn't cause an error but is parsed incoretory.

SELECT a @@@ b   -- parses as a @@ (@b); to_string() gives: SELECT a @@ @b
`SELECT 'a b'::tsvector @@@ 'a'::tsquery;   -- t
SELECT 'a b'::tsvector @@ @ 'a'::tsquery;  -- ERROR: operator does not exist

I ran into similar issues trying to write it as OPERATOR() which failed similiarly:

SELECT a OPERATOR(pg_catalog.*=) b    -- Expected: ), found: =
SELECT a OPERATOR(pg_catalog.@@@) b   -- Expected: ), found: @

The * operators are valid on PostgreSQL 18.6, on values of a record type:

SELECT a *= b, a = b, a *< b, a *<> b
FROM (SELECT ROW(1.0) a, ROW(1.00) b) s;   -- f | t | f | t

How to reproduce:

use sqlparser::{dialect::PostgreSqlDialect, parser::Parser};
for sql in ["SELECT a *= b", "SELECT a @@@ b"] {
    println!("{:?}", Parser::parse_sql(&PostgreSqlDialect {}, sql).map(|s| s
}
Ngôn ngữ chính
Rust
Star
3.5k
Fork
805
Merge trung bình
2 ngày 3 giờ
Pull request đã merge (30 ngày)
116

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/datafusion-sqlparser-rs

Tất cả issue của apache/datafusion-sqlparser-rs

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.