Skip to content

Commit 6eee5ed

Browse files
committed
[DOCS][SQL] Fix incorrect documentation for string literals
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
1 parent 66efc73 commit 6eee5ed

File tree

2 files changed

+59
-25
lines changed

2 files changed

+59
-25
lines changed

docs.feldera.com/docs/sql/string.md

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,28 @@ but:
4646
SELECT 'foo' 'bar'
4747
```
4848

49-
is not valid syntax.
50-
51-
## Escaped characters
52-
53-
We also accept escaped characters within string constants, which are
54-
an extension to the SQL standard. Within a quoted string, a
55-
backslash character (`\`) begins a C-like backslash escape sequence, in
56-
which the combination of backslash and the following character(s)
57-
represent a special byte value:
58-
59-
|Backslash Escape Sequence|Interpretation|
60-
|-------------------------|--------------|
61-
|<code>\b</code> | backspace |
62-
|<code>\f</code> | form feed |
63-
|<code>\n</code> | newline |
64-
|<code>\r</code> | carriage return |
65-
|<code>\t</code> | tab |
66-
|<code>\o, \oo, \ooo</code> | (o = 0–7) octal byte value |
67-
|<code>\xh, \xhh (h = 0–9, A–F)</code> | hexadecimal byte value |
68-
|<code>\uxxxx, \Uxxxxxxxx (x = 0–9, A–F)</code> | 16 or 32-bit hexadecimal Unicode character value |
69-
70-
Any other character following a backslash is taken literally. Thus, to
71-
include a backslash character, write two backslashes `\\`. Also, a
72-
single quote can be included in an escape string by writing `\'`, in
73-
addition to the normal way of `''`.
49+
is not valid syntax. Newlines are supported within string literals:
50+
51+
```
52+
SELECT 'a
53+
b'
54+
```
55+
56+
produces a multi-line string literal.
57+
58+
## Unicode characters
59+
60+
A string literal prefixed with the `U&` can contain unicode characters
61+
described using their numeric code: `U&'hello\0041'` includes the
62+
unicode character with code U+0041, which is the uppercase letter 'A'.
63+
A unicode character is described by an escape character followed by
64+
four hexadecimal digits.
65+
66+
The default escape character is backslash, but it can be changed using
67+
the following syntax: `U&'hello!0041' UESCAPE '!'`. The `UESCAPE`
68+
notation designates the escape character to use in interpreting the
69+
current literal, which is the exclamation sign in the previous
70+
example.
7471

7572
## Operations on string values
7673

sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression1Tests.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.dbsp.sqlCompiler.circuit.operator.DBSPLagOperator;
55
import org.dbsp.sqlCompiler.circuit.operator.DBSPStreamAggregateOperator;
66
import org.dbsp.sqlCompiler.compiler.DBSPCompiler;
7+
import org.dbsp.sqlCompiler.compiler.sql.tools.Change;
78
import org.dbsp.sqlCompiler.compiler.sql.tools.CompilerCircuitStream;
89
import org.dbsp.sqlCompiler.compiler.sql.tools.SqlIoTest;
910
import org.dbsp.sqlCompiler.compiler.visitors.inner.InnerVisitor;
@@ -12,6 +13,8 @@
1213
import org.dbsp.sqlCompiler.compiler.visitors.outer.Passes;
1314
import org.dbsp.sqlCompiler.ir.expression.DBSPCloneExpression;
1415
import org.dbsp.sqlCompiler.ir.expression.DBSPTupleExpression;
16+
import org.dbsp.sqlCompiler.ir.expression.DBSPZSetExpression;
17+
import org.dbsp.sqlCompiler.ir.expression.literal.DBSPStringLiteral;
1518
import org.dbsp.sqlCompiler.ir.statement.DBSPStaticItem;
1619
import org.dbsp.util.Linq;
1720
import org.dbsp.util.Logger;
@@ -749,6 +752,40 @@ CREATE TABLE row_tbl(
749752
FROM row_tbl;""");
750753
}
751754

755+
@Test
756+
public void issue5087() {
757+
this.qs("""
758+
SELECT '1
759+
2' AS r;
760+
r
761+
---
762+
1\\n2
763+
(1 row)
764+
765+
SELECT U&'hello\\0041';
766+
r
767+
---
768+
helloA
769+
(1 row)
770+
771+
SELECT U&'hello!0041' UESCAPE '!';
772+
r
773+
---
774+
helloA
775+
(1 row)""");
776+
}
777+
778+
@Test
779+
public void issue5087a() {
780+
var ccs = this.getCCS("""
781+
-- C escape sequences do not have any special meaning
782+
CREATE VIEW V AS SELECT 'a\\t\\b\\n\\r'""");
783+
ccs.addPair(new Change(),
784+
new Change("V",
785+
new DBSPZSetExpression(new DBSPTupleExpression(
786+
new DBSPStringLiteral("a\\t\\b\\n\\r")))));
787+
}
788+
752789
@Test
753790
public void issue4467b() {
754791
var ccs = this.getCCS("""

0 commit comments

Comments
 (0)