In DuckDB, strings can be stored in the VARCHAR field. The field allows storage of Unicode characters. Internally, the data is encoded as UTF-8.
| Name | Aliases | Description |
|---|---|---|
VARCHAR |
CHAR, BPCHAR, STRING, TEXT
| Variable-length character string. |
VARCHAR(n) |
CHAR(n), BPCHAR(n), STRING(n), TEXT(n)
| Variable-length character string. The maximum length n has no effect and is only provided for compatibility. |
Specifying the length for the VARCHAR, STRING, and TEXT types is not required and has no effect on the system. Specifying the length will not improve performance or reduce storage space of the strings in the database. These variants variant is supported for compatibility reasons with other systems that do require a length to be specified for strings.
If you wish to restrict the number of characters in a VARCHAR column for data integrity reasons the CHECK constraint should be used, for example:
CREATE TABLE strings (
val VARCHAR CHECK (length(val) <= 10) -- val has a maximum length of 10
); The VARCHAR field allows storage of Unicode characters. Internally, the data is encoded as UTF-8.
Values of the text type are character strings, also known as string values or simply strings. At runtime, string values are constructed in one of the following ways:
To use special characters in string, use escape string literals or dollar-quoted string literals. Alternatively, you can use concatenation and the chr character function:
SELECT 'Hello' || chr(10) || 'world' AS msg;
┌──────────────┐ │ msg │ │ varchar │ ├──────────────┤ │ Hello\nworld │ └──────────────┘
See Text Functions and Pattern Matching.
© Copyright 2018–2024 Stichting DuckDB Foundation
Licensed under the MIT License.
https://duckdb.org/docs/sql/data_types/text.html