This page in other versions: 9.0 / 9.1 / 9.2 / 9.3  |  Development versions: devel / 9.4  |  Unsupported versions: 7.1 / 7.2 / 7.3 / 7.4 / 8.0 / 8.1 / 8.2 / 8.3 / 8.4

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
Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group