Skip to content

Commit

Permalink
Support National string literal with lower case n (#612)
Browse files Browse the repository at this point in the history
* National string literal with lower case n

It's used by Snowflake

* Corrected DB name

Co-authored-by: Maciej Skrzypkowski <maciej.skrzypkowski@satoricyber.com>
  • Loading branch information
mskrzypkows and Maciej Skrzypkowski committed Sep 27, 2022
1 parent 0724ef1 commit d4e5b4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/tokenizer.rs
Expand Up @@ -387,7 +387,8 @@ impl<'a> Tokenizer<'a> {
}
Ok(Some(Token::Whitespace(Whitespace::Newline)))
}
'N' => {
// Redshift uses lower case n for national string literal
n @ 'N' | n @ 'n' => {
chars.next(); // consume, to check the next char
match chars.peek() {
Some('\'') => {
Expand All @@ -397,7 +398,7 @@ impl<'a> Tokenizer<'a> {
}
_ => {
// regular identifier starting with an "N"
let s = self.tokenize_word('N', chars);
let s = self.tokenize_word(n, chars);
Ok(Some(Token::make_word(&s, None)))
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/sqlparser_common.rs
Expand Up @@ -2851,6 +2851,7 @@ fn parse_literal_string() {
);

one_statement_parses_to("SELECT x'deadBEEF'", "SELECT X'deadBEEF'");
one_statement_parses_to("SELECT n'national string'", "SELECT N'national string'");
}

#[test]
Expand Down

0 comments on commit d4e5b4d

Please sign in to comment.