Character Types

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

Table 3-5. Postgres Character Types

Character TypeStorageRecommendationDescription
char1 byteSQL92-compatibleSingle character
char(n)(4+n) bytesSQL92-compatibleFixed-length blank padded
text(4+x) bytesBest choiceVariable-length
varchar(n)(4+n) bytesSQL92-compatibleVariable-length with limit

There is one other fixed-length character type in Postgres. The name type only has one purpose and that is for storage of internal catalog names. It is not intended for use by the general user. Its length is currently defined as 32 bytes (31 characters plus terminator) but should be reference using 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.

Table 3-6. Postgres Specialty Character Type

Character TypeStorageDescription
name32 bytesThirty-one character internal type