apache / datafusion-sqlparser-rs

Extensible SQL Lexer and Parser for Rust
Apache License 2.0
2.75k stars 527 forks source link

`LIKE ... ESCAPE <escape_char>` should accept an empty string #1198

Open TennyZhuang opened 6 months ago

TennyZhuang commented 6 months ago

Currently, we use Option<char> to represent escape_char, which cannot represent three case. We should introduce a new enum to represent that.

enum EscapeChar {
    NotSpecified,
    Empty,
    Escape(char),
}

to pass the case:

https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE:~:text=it's%20also%20possible%20to%20select%20no%20escape%20character%20by%20writing%20escape%20''

TennyZhuang commented 6 months ago

I can help to implement that.

TennyZhuang commented 6 months ago

Another option is create a newtype EscapeChar to represent '' or a single character, and store an Option<EscapeChar> in the AST.

TennyZhuang commented 6 months ago

I'd like to port https://github.com/risingwavelabs/risingwave/pull/15867/commits/b05cb06719d668ce86a4eb5882e9f284b3c03251 back to the repo, if the fix is reasonable.

alamb commented 6 months ago

Seems resonable to me