Character Types
variable-length with limit
|
- character(n ) , char(n )
+ character(n ) , char(n ) , bpchar(n )
fixed-length, blank padded
|
error, unless the excess characters are all spaces, in which case
the string will be truncated to the maximum length. (This somewhat
bizarre exception is required by the
SQL
- standard.) If the string to be stored is shorter than the declared
+ standard.)
+ However, if one explicitly casts a value to character
+ varying(n ) or
+ character(n ) , then an over-length
+ value will be truncated to n characters without
+ raising an error. (This too is required by the
+ If the string to be stored is shorter than the declared
length, values of type character will be space-padded;
values of type character varying will simply store the
shorter
- If one explicitly casts a value to character
- varying(n ) or
- character(n ) , then an over-length
- value will be truncated to n characters without
- raising an error. (This too is required by the
+ In addition,
PostgreSQL provides the
+ text type, which stores strings of any length.
+ Although the text type is not in the
+
SQL standard, several other SQL database
+ management systems have it as well.
+
text is
PostgreSQL 's native
+ string data type, in that most built-in functions operating on strings
+ are declared to take or return text not character
+ varying. For many purposes, character varying
+ acts as though it were a domain
+ over text .
- The notations varchar(n ) and
- char(n ) are aliases for character
- varying(n ) and
- character(n ) , respectively.
- If specified, the length must be greater than zero and cannot exceed
- 10485760.
- character without length specifier is equivalent to
- character(1) . If character varying is used
- without length specifier, the type accepts strings of any size. The
- latter is a
PostgreSQL extension.
+ The type name varchar is an alias for character
+ varying, while char and bpchar are
+ aliases for character .
+ The varchar and char aliases are defined in
+ the
SQL standard, but
bpchar is
+ a
PostgreSQL extension.
- In addition,
PostgreSQL provides the
- text type, which stores strings of any length.
- Although the type text is not in the
-
SQL standard, several other SQL database
- management systems have it as well.
+ If specified, the length n must be greater
+ than zero and cannot exceed 10485760.
+ character without length specifier is equivalent to
+ character(1) . If character varying is used
+ without length specifier, the type accepts strings of any size. The
+ latter behavior is a
PostgreSQL extension.