SQL
String Literals
String literals are delimited using single quotes (` '`, apostrophe) and result in `STRING_LITERAL` values.
Note that double quotes (` "`) cannot be used as string delimiter character: instead, double quotes are used to delimit [quoted identifiers](#docs:sql:dialect:keywords_and_identifiers::identifiers).  
#### Implicit String Literal Concatenation {#docs:sql:data_types:literal_types::implicit-string-literal-concatenation}  
Consecutive single-quoted string literals separated only by whitespace that contains at least one newline are implicitly concatenated:  
```sql
SELECT 'Hello'
' '
'World' AS greeting;
```  
is equivalent to:  
```sql
SELECT 'Hello'
|| ' '
|| 'World' AS greeting;
```  
They both return the following result:  
|  greeting   |
|-------------|
| Hello World |  
Note that implicit concatenation only works if there is at least one newline between the literals. Using adjacent string literals separated by whitespace without a newline results in a syntax error:  
```sql
SELECT 'Hello' ' ' 'World' AS greeting;
```  
```console
Parser Error: syntax error at or near "' '"
LINE 1: SELECT 'Hello' ' ' 'World' AS greeting;
^
```  
Also note that implicit concatenation only works with single-quoted string literals, and does not work with other kinds of string values.  
#### Implicit String Conversion {#docs:sql:data_types:literal_types::implicit-string-conversion}  
`STRING_LITERAL` instances can be implicitly converted to _any_ other type.  
For example, we can compare string literals with dates:  
```sql
SELECT d > '1992-01-01' AS result FROM (VALUES (DATE '1992-01-01')) t(d);
```  
| result |
|:-------|
| false  |  
However, we cannot compare `VARCHAR` values with dates.  
```sql
SELECT d > '1992-01-01'::VARCHAR FROM (VALUES (DATE '1992-01-01')) t(d);
```  
```console
Binder Error: Cannot compare values of type DATE and type VARCHAR - an explicit cast is required
```  
#### Escape String Literals {#docs:sql:data_types:literal_types::escape-string-literals}  
To escape a single quote (apostrophe) character in a string literal, use `''`. For example, `SELECT '''' AS s` returns `'`.  
To include special characters such as newline, use `E` escape the string. Both the uppercase (` E'...'`) and lowercase variants (` e'...'`) work.  
```sql
SELECT E'Hello\nworld' AS msg;
```  
Or:  
```sql
SELECT e'Hello\nworld' AS msg;
```  
<!-- This output intentionally uses the duckbox formatter -->  
```text
┌──────────────┐
│     msg      │
│   varchar    │
├──────────────┤
│ Hello\nworld │
└──────────────┘
```  
The following backslash escape sequences are supported:  
| Escape sequence | Name | ASCII code |
|:--|:--|--:|
| `\b` | backspace | 8 |
| `\f` | form feed | 12 |
| `\n` | newline | 10 |
| `\r` | carriage return |  13 |
| `\t` | tab | 9 |  
#### Dollar-Quoted String Literals {#docs:sql:data_types:literal_types::dollar-quoted-string-literals}  
DuckDB supports dollar-quoted string literals, which are surrounded by double-dollar symbols (` $$`):  
```sql
SELECT $$Hello
world$$ AS msg;
```  
<!-- This output intentionally uses the duckbox formatter -->  
```text
┌──────────────┐
│     msg      │
│   varchar    │
├──────────────┤
│ Hello\nworld │
└──────────────┘
```  
```sql
SELECT $$The price is $9.95$$ AS msg;
```  
|        msg         |
|--------------------|
| The price is $9.95 |  
[Implicit concatenation](#::implicit-string-literal-concatenation) only works for single-quoted string literals, not with dollar-quoted ones.