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 NameStorageRecommendationDescription
character(n), char(n)(4+n) bytesSQL-compatibleFixed-length blank padded
character varying(n), varchar(n)(4+n) bytesSQL-compatibleVariable-length with limit
text(4+n) bytesMost flexibleVariable 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 NameStorageDescription
"char"1 byteSingle character internal type
name32 bytesThirty-one character internal type