File tree Expand file tree Collapse file tree 2 files changed +75
-1
lines changed
datafusion/sqllogictest/test_files
docs/source/user-guide/sql Expand file tree Collapse file tree 2 files changed +75
-1
lines changed Original file line number Diff line number Diff line change @@ -2057,3 +2057,16 @@ select 1 where null between null and 2;
20572057query T
20582058select 'A' where null between 2 and null;
20592059----
2060+
2061+ ### Demonstrate use of E literals for escaping
2062+ # should not have literal tab
2063+ query T
2064+ select 'foo\t\tbar';
2065+ ----
2066+ foo\t\tbar
2067+
2068+ # should have literal tab
2069+ query T
2070+ select E'foo\t\tbar';
2071+ ----
2072+ foo bar
Original file line number Diff line number Diff line change 1717 under the License.
1818-->
1919
20- # Operators
20+ # Operators and Literals
2121
2222## Numerical Operators
2323
@@ -552,3 +552,64 @@ Array Is Contained By
552552| true |
553553+ -- -----------------------------------------------------------------------+
554554```
555+
556+ ## Literals
557+
558+ Use single quotes for literal values. For example, the string ` foo bar ` is
559+ referred to using ` 'foo bar' `
560+
561+ ``` sql
562+ select ' foo' ;
563+ ```
564+
565+ ### Escaping
566+
567+ Unlike many other languages, SQL literals do not by default support C-style escape
568+ sequences such as ` \n ` for newline. Instead all characters in a ` ' ` string are treated
569+ literally.
570+
571+ To escape ` ' ` in SQL literals, use ` '' ` :
572+
573+ ``` sql
574+ > select ' it' ' s escaped' ;
575+ + -- --------------------+
576+ | Utf8(" it's escaped" ) |
577+ + -- --------------------+
578+ | it' s escaped |
579+ +----------------------+
580+ 1 row(s) fetched.
581+ ```
582+
583+ Strings such as `foo\n bar` mean `\` followed by `n` (not newline):
584+
585+ ```sql
586+ > select ' foo\nbar' ;
587+ +------------------+
588+ | Utf8("foo\n bar") |
589+ +------------------+
590+ | foo\n bar |
591+ +------------------+
592+ 1 row(s) fetched.
593+ Elapsed 0.005 seconds.
594+ ```
595+
596+ To add escaped characters such as newline or tab, instead of `\n ` you use the
597+ `E` style strings. For example, to add the text with a newline
598+
599+ ```text
600+ foo
601+ bar
602+ ```
603+
604+ You can use `E' foo\nbar' `
605+
606+ ```sql
607+ > select E' foo\nbar' ;
608+ +-----------------+
609+ | Utf8("foo
610+ bar") |
611+ +-----------------+
612+ | foo
613+ bar |
614+ +-----------------+
615+ ```
You can’t perform that action at this time.
0 commit comments