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

Offen
#2,809 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
postgresql, rust
Bereich
compilers, databases

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
}
Vorherrschende Sprache
Rust
Sterne
3.5k
Forks
805
Ø Merge
2 T. 3 Std.
Gemergte PRs (30 T.)
116

Entwicklungsumgebung

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Hat eine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus apache/datafusion-sqlparser-rs

Alle Issues in apache/datafusion-sqlparser-rs

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.