• Data Warehouse Service

dws
  1. Help Center
  2. Data Warehouse Service
  3. Developer Guide
  4. SQL Reference
  5. Data Types
  6. Character Types

Character Types

Table 1 lists the character types that can be used in DWS. For string operators and related built-in functions, see Character Processing Function and Operator.

Table 1 Character Types

Name

Description

Storage (GB)

CHAR(n)

CHARACTER(n)

NCHAR(n)

Fixed-length character string, blank padded. n indicates the string length. If the precision n is not specified, the default precision 1 is used.

The maximum size is 10 MB.

VARCHAR(n)

CHARACTER VARYING(n)

Variable-length string n indicates the string length.

The maximum size is 10 MB.

VARCHAR2(n)

Variable-length string VARCHAR(n) alias, compatible with Oracle n indicates the string length.

The maximum size is 10 MB.

NVARCHAR2(n)

Variable-length string n indicates the string length.

The maximum size is 10 MB.

CLOB

A big text object. TEXT alias, compatible with Oracle

The maximum size is 10,7373,3621 bytes (1 GB - 8023 bytes).

TEXT

Variable-length string

The maximum size is 10,7373,3621 bytes (1 GB - 8023 bytes).

NOTE:

In addition to the size limitation on each column, the total size of each tuple is 10,7373,3621 bytes (1 GB - 8023 bytes).

DWS has two other fixed-length character types, as listed 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

Name

Description

Storage (GB)

name

Internal type for object names

64 bytes

"char"

Single-byte internal type

1 byte

Example

-- Create a table.
CREATE TABLE char_type_t1 
(
    CT_COL1 CHARACTER(4)
) DISTRIBUTE BY HASH (CT_COL1);

-- Insert data.
INSERT INTO char_type_t1 VALUES ('ok');

-- Query data in the table.
SELECT ct_col1, char_length(ct_col1) FROM char_type_t1;
 ct_col1 | char_length 
---------+-------------
 ok      |           4
(1 row)

-- Delete the table.
DROP TABLE char_type_t1;
-- Create a table.
CREATE TABLE char_type_t2  
(
    CT_COL1 VARCHAR(5)
) DISTRIBUTE BY HASH (CT_COL1);

-- Insert data.
INSERT INTO char_type_t2 VALUES ('ok');

INSERT INTO char_type_t2 VALUES ('good');

-- Specify the type length. An error is reported if an inserted string exceeds this length.
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.
INSERT INTO char_type_t2 VALUES ('too long'::varchar(5));

-- Query data.
SELECT ct_col1, char_length(ct_col1) FROM char_type_t2;
 ct_col1 | char_length 
---------+-------------
 ok      |           2
 good    |           5
 too l   |           5
(3 rows)

-- Delete data.
DROP TABLE char_type_t2;