apache / apache/datafusion-sqlparser-rs
Unexpected failure parsing SQLite CREATE TABLE statement
- Lenguaje dominante
- Rust
- Estrellas
- 3.5k
- Forks
- 772
- Merge medio
- 4 d 9 h
- PR fusionados (30 d)
- 17
Descripción
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();
}
```
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- rust, sqlite
- Área
- databases
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100