Character Data Types
Table 1 lists the character data types supported by openGauss. For string operators and related built-in functions, see Character Processing Functions and Operators.
Table 1 Character data types
NOTE:
In addition to the size limitation on each column, the total size of each tuple is 8,203 bytes less than 1 GB, namely, 1,073,733,621 bytes.
In openGauss, there are two other fixed-length character types, as shown in Table 2. The name type exists only for the storage of identifiers in the internal system catalogs and is not intended for use by general users. Its length is currently defined as 64 bytes (63 usable characters plus terminator). The type “char” only uses one byte of storage. It is internally used in the system catalogs as a simplistic enumeration type.
Table 2 Special character types
Example
-- Create a table.
postgres=# CREATE TABLE char_type_t1
(
CT_COL1 CHARACTER(4)
);
-- Insert data.
postgres=# INSERT INTO char_type_t1 VALUES ('ok');
-- Query data in the table.
postgres=# SELECT ct_col1, char_length(ct_col1) FROM char_type_t1;
ct_col1 | char_length
---------+-------------
ok | 4
(1 row)
-- Delete the table.
postgres=# DROP TABLE char_type_t1;
-- Create a table.
postgres=# CREATE TABLE char_type_t2
(
CT_COL1 VARCHAR(5)
);
-- Insert data.
postgres=# INSERT INTO char_type_t2 VALUES ('ok');
postgres=# INSERT INTO char_type_t2 VALUES ('good');
-- Specify the type length. An error is reported if an inserted string exceeds this length.
postgres=# INSERT INTO char_type_t2 VALUES ('too long');
ERROR: value too long for type character varying(4)
CONTEXT: referenced column: ct_col1
-- Specify the type length. A string exceeding this length is truncated.
postgres=# INSERT INTO char_type_t2 VALUES ('too long'::varchar(5));
-- Query data.
postgres=# SELECT ct_col1, char_length(ct_col1) FROM char_type_t2;
ct_col1 | char_length
---------+-------------
ok | 2
good | 4
too l | 5
(3 rows)
-- Delete data.
postgres=# DROP TABLE char_type_t2;