Character types v15
The following table lists the general-purpose character types available in EDB Postgres Advanced Server.
Name | Description |
---|---|
CHAR[(n)] | Fixed-length character string, blank-padded to the size specified by n |
CLOB | Large variable-length up to 1 GB |
LONG | Variable unlimited length. |
NVARCHAR(n) | Variable-length national character string, with limit |
NVARCHAR2(n) | Variable-length national character string, with limit |
STRING | Alias for VARCHAR2 |
VARCHAR(n) | Variable-length character string, with limit (considered deprecated, but supported for compatibility) |
VARCHAR2(n) | Variable-length character string, with limit |
Where n
is a positive integer, these types can store strings up to n
characters in length. An attempt to assign a value that exceeds the length of n
results in an error, unless the excess characters are all spaces. In this case, the string is truncated to the maximum length.
The storage requirement for data of these types is the actual string plus 1 byte if the string is less than 127 bytes or 4 bytes if the string is 127 bytes or greater. In the case of CHAR
, the padding also requires storage. Long strings are compressed by the system automatically, so the physical requirement on disk might be less. Long values are stored in background tables so they don't interfere with rapid access to the shorter column values.
The database character set determines the character set used to store textual values.
CHAR
If you don't specify a value for n
, n
defaults to 1
. If the string to assign is shorter than n
, values of type CHAR
are space-padded to the specified width (n
) and are stored and displayed that way.
Padding spaces are treated as semantically insignificant. That is, trailing spaces are disregarded when comparing two values of type CHAR
, and they are removed when converting a CHAR
value to one of the other string types.
If you explicitly cast an over-length value to a CHAR(n)
type, the value is truncated to n
characters without raising an error (as specified by the SQL standard).
VARCHAR, VARCHAR2, NVARCHAR and NVARCHAR2
If the string to assign is shorter than n
, values of type VARCHAR
, VARCHAR2
, NVARCHAR
, and NVARCHAR2
store the shorter string without padding.
!!! Note
The trailing spaces are semantically significant in VARCHAR
values.
If you explicitly cast a value to a VARCHAR
type, an over-length value is truncated to n
characters without raising an error (as specified by the SQL standard).
CLOB
You can store a large character string in a CLOB
type. CLOB
is semantically equivalent to VARCHAR2
except no length limit is specified. Generally, use a CLOB
type if you don't know the maximum string length.
The longest possible character string that you can store in a CLOB
type is about 1 GB.
!!!Note
The CLOB
data type is actually a DOMAIN
based on the PostgreSQL TEXT
data type. For information on a DOMAIN
, see the PostgreSQL core documentation.
Thus, use of the CLOB
type is limited by what can be done for TEXT
, such as a maximum size of approximately 1 GB.
For larger amounts of data, instead of using the CLOB
data type, use the PostgreSQL large objects feature that relies on the pg_largeobject
system catalog. For information on large objects, see the PostgreSQL core documentation.