apache / apache/datafusion-sqlparser-rs

Unexpected failure parsing SQLite CREATE TABLE statement

Offen
#322 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
3.5k
Forks
772
Ø Merge
4 T. 9 Std.
Gemergte PRs (30 T.)
17

Beschreibung

When parsing the following statement with the SQLite dialect:

```sql
CREATE TABLE '""' (
'id' INT UNSIGNED NOT NULL,
'name' TEXT NOT NULL,
'surname' TEXT NULL,
'zip' INT UNSIGNED NULL
);
```

the result is:

`ParserError("Expected column name or constraint definition, found: 'id'")`

but I expect that this would be correctly parsed as a CREATE TABLE statement with `""` as the table name. From the SQL grammar, the table name in a CREATE TABLE statement appears to be a [local or schema qualified name](https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html#local-or-schema-qualified-name). It's not actually clear to me if using single quotes to delimit a table name is valid according to that description of the grammar, but SQLite does accept it. For reference, [here](https://www.sqlite.org/lang_createtable.html) is the SQLite documentation for CREATE TABLE.

This is definitely an uncommon edge case. I found it in the [Standardized corpus for SQLite Database Forensics](https://www.sciencedirect.com/science/article/pii/S1742287618300471) (accessible [here](https://faui1-files.cs.fau.de/public/sqlite-forensic-corpus/)) in sample 01-01. (For context, I'm using that collection as a set of test cases for a personal project I'm working on which uses this library.)

Full repro using sqlparser 0.9.0:

```rust
fn main() {
let statement = "CREATE TABLE '\"\"' (\n\t'id' INT UNSIGNED NOT NULL,\n\t'name' TEXT NOT NULL,\n\t'surname' TEXT NULL,\n\t'zip' INT UNSIGNED NULL\n)";
let dialect = sqlparser::dialect::SQLiteDialect {};
let parsed = sqlparser::parser::Parser::parse_sql(&dialect, statement).unwrap();
}
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Start with the SQLiteDialect and Parser::parse_sql entry points, using the supplied CREATE TABLE statement as the reproduction. Trace how quoted table and column names are parsed, then add coverage showing that this statement is accepted as a CREATE TABLE statement with the expected table name.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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