Skip to content

Commit c0f12bd

Browse files
committed
[SPARK-52545][SQL][DOCS] Update string literal docs for quote escaping rules
1 parent a6fda31 commit c0f12bd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/sql-ref-literals.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ A string literal is used to specify a character string value.
4343

4444
* **char**
4545

46-
One character from the character set. Use `\` to escape special characters (e.g., `'` or `\`).
46+
One character from the character set. Use `\` to escape special characters (e.g., `'` or `\`), additionally, consecutive quotes can be used for escaping (e.g., `'S''park'` equals `'S\'park'`, `"S""park"` equals `"S\"park"`).
4747
To represent unicode characters, use 16-bit or 32-bit unicode escape of the form `\uxxxx` or `\Uxxxxxxxx`,
4848
where xxxx and xxxxxxxx are 16-bit and 32-bit code points in hexadecimal respectively (e.g., `\u3042` for `` and `\U0001F44D` for `👍`).
4949
An ASCII character can also be represented as an octal number preceded by `\` like `\101`, which represents `A`.
@@ -62,6 +62,8 @@ The following escape sequences are recognized in regular string literals (withou
6262
- `\%` -> `\%`;
6363
- `\_` -> `\_`;
6464
- `\<other char>` -> `<other char>`, skip the slash and leave the character as is.
65+
- `""` -> `"`, skip first `"` in double-quoted string.
66+
- `''` -> `'`, skip first `'` in single-quoted string.
6567

6668
The unescaping rules above can be turned off by setting the SQL config `spark.sql.parser.escapedStringLiterals` to `true`.
6769

@@ -100,6 +102,13 @@ SELECT r"'\n' represents newline character." AS col;
100102
|'\n' represents newline character.|
101103
+----------------------------------+
102104
105+
SELECT "S""park" AS col1, 'S''park' AS col2;
106+
+--------+--------+
107+
| col1| col2|
108+
+--------+--------+
109+
| S"park | S'park |
110+
+--------+--------+
111+
103112
SELECT 'Hello' ',' 'World!' AS col;
104113
+-------------+
105114
| col|

0 commit comments

Comments
 (0)