String Literals
A string literal specifies a character string value.
Syntax
[r]('char*'|"char*")char is a character drawn from the supported character set.
- Use
\to escape special characters. - Use
\uXXXXor\Uxxxxxxxxto represent Unicode characters, whereXXXXandxxxxxxxxare 16-bit and 32-bit code points in hexadecimal respectively. For example,\u03C0→π,\U0001F44B→👋. - Use an octal number preceded by
\to represent an ASCII character. For example,\142→b.
r (case-insensitive) is an optional prefix that indicates a raw string literal. If a string literal starts with the r prefix, neither special characters nor Unicode characters are escaped by \.
The following escape sequences are recognized in regular string literals without the r prefix, and replaced according to the following rules:
\0->\u0000(null)\b->\u0008(backspace)\n->\u000a(line feed)\r->\u000d(carriage return)\t->\u0009(horizontal tab)\Z->\u001A(substitute)\%->\%(percent sign)\_->\_(underscore)
For \c where c is any other character, the backslash \ is simply removed and the character is left as is.
Examples
SELECT 'Hello, World!' AS col;
-- +-------------+
-- | col|
-- +-------------+
-- |Hello, World!|
-- +-------------+
SELECT "Sail" AS col;
-- +----+
-- | col|
-- +----+
-- |Sail|
-- +----+
SELECT 'It\'s about $25.' AS col;
-- +---------------+
-- | col|
-- +---------------+
-- |It's about $25.|
-- +---------------+
SELECT r"'\n' represents a newline character." AS col;
-- +------------------------------------+
-- | col|
-- +------------------------------------+
-- |'\n' represents a newline character.|
-- +------------------------------------+