Character types are required any time that you wish to reference character data, such as blocks of ASCII text. They
are commonly used for storing names, addresses, and so on.
SQL provides two character types called character, and character varying.
In addition to these, a general text type is supported by
PostgreSQL, which does not require an explicitly declared upper limit on the size of the field. Columns of type
text are automatically re-sized according to the data you put in them, and they may
re-size without boundaries (discounting, of course, the 1GB limit for a single field). Table 3-12
shows the available character data types within PostgreSQL.
Table 3-12. Character types
Type
|
Storage
|
Description
|
character(
n
), char(
n
)
|
(4 +
n
) bytes
|
A fixed-length character string, padded with spaces so that it is
n
characters in length.
|
character varying(
n
), varchar(
n
)
|
Up to (4 +
n
) bytes
|
A variable-length character string with a limit of
n
characters
|
text
|
Variable
|
A variable, unlimited-length character string
|
The
n
in Table 3-12 represents an arbitrarily specified number of
characters. This number is specified for a column when a table is created.
Note: Although the text data type is not part of the ANSI/ISO SQL standards, many other
Relational Database Management Systems (RDBMS) provide this functionality, including Sybase and MS SQL Server.