Text type
-
VARCHAR.-
Aliases:
CHAR,BPCHAR,STRING,TEXT
-
Description
The VARCHAR type is used to store text strings. This type allows storing characters Unicode. The data is encoded in the format UTF-8.
To specify the value of a text string in the expression INSERT, use single quotes.
Example
Create a varchar_table table and fill two cells with text strings:
CREATE TABLE varchar_table(text_column VARCHAR);
INSERT INTO varchar_table VALUES
('My name is Tengri'),
('My nickname is TNGRi');
SELECT * FROM varchar_table;
+----------------------+
| text_column |
+----------------------+
| My name is Tengri |
+----------------------+
| My nickname is TNGRi |
+----------------------+
Please note that in the programme output, text strings are displayed without quotation marks.
String literals
Tengri supports three types of string literals, which allow for flexible handling of text data, hexadecimal values and byte sequences.
| Literal | Syntax | Input → Output |
|---|---|---|
Hexadecimal |
|
Hex string → Escaped string |
Byte |
|
String → Escaped string |
Escaped |
|
Escaped string → String |
Hexadecimal literals
A hexadecimal literal allows you to specify a sequence of bytes in hex format. The result is returned as an escaped string.
- Syntax
-
X'<hex>'
See example
SELECT X'7fff' AS X_literal;
+-----------+
| X_literal |
+-----------+
| \x7F\xFF |
+-----------+
Byte literals
A byte literal takes a regular string and converts each of its characters to the corresponding hexadecimal code (UTF-8). The result is returned as an escaped sequence of bytes.
- Syntax
-
B'<string>'
See example
SELECT B'abc' AS B_literal;
+--------------+
| B_literal |
+--------------+
| \x61\x62\x63 |
+--------------+
Escaped literals
An escaped literal interprets escape sequences — \xXX for hexadecimal character codes, as well as standard special characters such as \n and \t. The result is returned as a normal string.
- Syntax
-
E'<escaped string>'
See example
SELECT E'\x61bc' AS E_literal;
+-----------+
| E_literal |
+-----------+
| abc |
+-----------+