Supported Versions: Current (17) / 16 / 15 / 14 / 13
Development Versions: devel
Unsupported versions: 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

3.3. Character Types

SQL defines two primary character types: character and character varying. Postgres supports these types, in addition to the more general text type, which unlike character varying does not require an explicit declared upper limit on the size of the field.

Refer to Section 1.1.2.1 for information about the syntax of string literals, and to Chapter 4 for information about available operators and functions.

Table 3-4. Character Types

Type Name Storage Recommendation Description
character(n), char(n) (4+n) bytes SQL-compatible Fixed-length blank padded
character varying(n), varchar(n) (4+n) bytes SQL-compatible Variable-length with limit
text (4+n) bytes Most flexible Variable unlimited length

Note: Although the type text is not SQL-compliant, many other RDBMS packages have it as well.

There are two other fixed-length character types in Postgres. The name type exists only for storage of internal catalog names and is not intended for use by the general user. Its length is currently defined as 32 bytes (31 characters plus terminator) but should be referenced using the macro NAMEDATALEN. The length is set at compile time (and is therefore adjustable for special uses); the default maximum length may change in a future release. The type "char" (note the quotes) is different from char(1) in that it only uses one byte of storage. It is internally used in the system catalogs as a poor-man's enumeration type.

Table 3-5. Specialty Character Type

Type Name Storage Description
"char" 1 byte Single character internal type
name 32 bytes Thirty-one character internal type