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.