apache / apache/datafusion-sqlparser-rs
MySql dialect doesn't handle slash-escaped single quotes
- Dominant language
- Rust
- Stars
- 3.5k
- Forks
- 772
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 17
Description
The following fails to parse:
```rust
fn main() {
println!("{:?}",
sqlparser::parser::Parser::parse_sql(
&sqlparser::dialect::MySqlDialect {},
r#"INSERT INTO `example` (`col`) VALUES ('foo \'bar\' baz');"#
)
);
}
```
Instead returning:
```
Err(ParserError("Expected ), found: bar"))
```
But I believe it shouldn't — `mysqldump` generates SQL that is escaped like this, and the [docs](https://dev.mysql.com/doc/refman/8.0/en/string-literals.html) explicitly mention this as a valid escaping (see Table 9.1).
This is, according to [this doc](https://www.ibm.com/docs/en/informix-servers/12.10?topic=statements-quotation-marks-escape-characters) a difference between ANSI SQL and MySQL, but unfortunately this needs to be fixed in the tokenizer, which AFAICT the dialect system doesn't have a way to hook into?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the tokenizer and the MySqlDialect path used by Parser::parse_sql, then reproduce the supplied INSERT example to trace how slash-escaped single quotes are tokenized. Done means this MySQL input parses successfully without treating the escaped quotes as the end of the string.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, rust
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100