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

Aperta
#2,809 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
postgresql, rust

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
}
Lingua principale
Rust
Stelle
3.5k
Fork
805
Merge medio
2g 3h
PR unite (30g)
116

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/datafusion-sqlparser-rs

Tutte le issue di apache/datafusion-sqlparser-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.