BenSatori commented on code in PR #2509:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2509#discussion_r4766129790


##########
src/tokenizer.rs:
##########
@@ -2085,6 +2094,33 @@ impl<'a> Tokenizer<'a> {
         }
     }
 
+    /// Reads a Unicode string literal body introduced by the `U&` prefix, 
e.g. the
+    /// `\0061\0062\0063` in `U&'\0061\0062\0063'`, honoring a trailing 
`UESCAPE '<char>'`
+    /// clause if present.
+    /// See 
<https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-UESCAPE>
+    fn tokenize_unicode_single_quoted_string(
+        &self,
+        chars: &mut State,
+    ) -> Result<String, TokenizerError> {
+        let error_loc = chars.location();
+        let raw = self.tokenize_single_quoted_string(chars, '\'', false)?;

Review Comment:
   Done in 19f9193f, applied as suggested. Without it, `U&'a''b'` with 
`unescape(false)` round-tripped as `U&'a''''b'`. (`U&"a""b"` was already fine, 
since the quoted-identifier path collapses `""` regardless of `unescape`.)



##########
tests/sqlparser_postgres.rs:
##########
@@ -7205,6 +7205,29 @@ fn test_unicode_string_literal() {
     }
 }
 
+#[test]
+fn test_unicode_string_literal_uescape() {
+    // Custom escape character via UESCAPE, see the postgres docs example
+    pg_and_generic().expr_parses_to(r#"U&'d!0061t!+000061' UESCAPE '!'"#, 
"U&'data'");
+}

Review Comment:
   Added `test_unicode_string_literal_no_unescape` as suggested. It fails 
without the tokenizer change and passes with it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to