Skip to content

Only support escape literals for Postgres, Redshift and generic dialect #1674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 24, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use sqlparser_derive::{Visit, VisitMut};
use crate::dialect::Dialect;
use crate::dialect::{
BigQueryDialect, DuckDbDialect, GenericDialect, MySqlDialect, PostgreSqlDialect,
SnowflakeDialect,
RedshiftSqlDialect, SnowflakeDialect,
};
use crate::keywords::{Keyword, ALL_KEYWORDS, ALL_KEYWORDS_INDEX};
use crate::{ast::DollarQuotedString, dialect::HiveDialect};
Expand Down Expand Up @@ -982,7 +982,8 @@ impl<'a> Tokenizer<'a> {
}
}
// PostgreSQL accepts "escape" string constants, which are an extension to the SQL standard.
x @ 'e' | x @ 'E' => {
x @ 'e' | x @ 'E' if dialect_of!(self is PostgreSqlDialect | RedshiftSqlDialect | GenericDialect) =>
{
let starting_loc = chars.location();
chars.next(); // consume, to check the next char
match chars.peek() {
Expand Down Expand Up @@ -3543,4 +3544,18 @@ mod tests {
];
compare(expected, tokens);
}

#[test]
fn test_mysql_escape_literal() {
let dialect = MySqlDialect {};
let sql = "select e'\\u'";
let tokens = Tokenizer::new(&dialect, sql).tokenize().unwrap();
let expected = vec![
Token::make_keyword("select"),
Token::Whitespace(Whitespace::Space),
Token::make_word("e", None),
Token::SingleQuotedString("u".to_string()),
];
compare(expected, tokens);
}
}
Loading