apache / apache/datafusion-sqlparser-rs
Unexpected failure parsing SQLite CREATE TABLE statement
- Langage dominant
- Rust
- Étoiles
- 3.5k
- Forks
- 772
- Merge moyen
- 4 j 9 h
- PR mergées (30 j)
- 17
Description
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();
}
```
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- rust, sqlite
- Domaine
- databases
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100