This topic describes the common character types in PolarDB for PostgreSQL(Compatible with Oracle).
The following table lists the common character types.
Name | Description |
---|---|
CHAR[(n)] | The fixed-length string. If the length is less than n, the string is padded with spaces. |
CLOB | The large variable-length string. The maximum size is 1 GB. |
LONG | The variable-length string with unlimited length. |
NVARCHAR(n) | The variable-length string with a limited length. |
NVARCHAR2(n) | The variable-length string with a limited length. |
STRING | The alias of VARCHAR2. |
VARCHAR(n) | The variable-length string with a limited length. (This data type is provided for the purpose of compatibility and is not recommended.) |
VARCHAR2(n) | The variable-length string with a limited length. |
TEXT | The large variable-length string. The maximum size is 1 GB. |
CHAR
For the CHAR type, if you do not specify a value for n, the default value is 1. If the string to be stored is shorter than n, a value of the CHAR type is space-padded to the specified length n, and is stored and displayed that way.
Padding spaces are insignificant in semantics. This indicates that trailing spaces are disregarded when you compare two CHAR values, and the spaces are removed when a CHAR value is converted to another string type.
If you explicitly cast a value to a CHAR(n) type, an over-length value is truncated to n characters without generating an error. This is the same as that specified by the SQL standards.
VARCHAR, VARCHAR2, NVARCHAR, and NVARCHAR2
If the string to be assigned is shorter than n, the VARCHAR, VARCHAR2, NVARCHAR, and NVARCHAR2 value types store the string of the actual length without padding spaces.
If you explicitly cast a value to a VARCHAR type, an over-length value is truncated to n characters without generating an error. This is the same as that specified by the SQL standards.
CLOB
TEXT
Considerations
The storage requirement for data of these types is the actual string plus 1 byte if the string is less than 127 bytes. If the string is 127 bytes or larger, the data of these types is the actual string plus 4 bytes. For data of the CHAR type, the trailing spaces of a string also require the storage space. Long strings are automatically compressed by the system. In this case, less actual storage space is required on disks. Long values are stored in background tables so they do not interfere with rapid access to the shorter column values.
The database character set determines the character set used to store textual values.