- |
- character(n>), char(n>)
- fixed-length, blank padded
-
|
character varying(n>), varchar(n>)
variable-length with limit
+ |
+ character(n>), char(n>)
+ fixed-length, blank padded
+
|
text
variable unlimited length
SQL defines two primary character types:
- character(n>) and character
- varying(n>), where n> is a
- positive integer. Both of these types can store strings up to
+ character varying(n>) and
+ character(n>), where n>
+ is a positive integer. Both of these types can store strings up to
n> characters in length. An attempt to store a
longer string into a column of these types will result in an
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 length, values of type
- character will be space-padded; values of type
- character varying will simply store the shorter
+ 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
+ length, values of type character will be space-padded;
+ values of type character varying will simply store the
+ shorter
string.
- If one explicitly casts a value to
- character(n>) or character
- varying(n>), then an overlength value will
- be truncated to n> characters without raising an
- error. (This too is required by the
SQL
- standard.)
+ 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
- The notations char(n>) and
- varchar(n>) are aliases for
- character(n>) and character
- varying(n>),
- respectively. 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 notations varchar(n>) and
+ char(n>) are aliases for character
+ varying(n>) and
+ character(n>), respectively.
+ 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.
There are two other fixed-length character types in
- 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 64 bytes (63 usable characters plus terminator)
- but should be referenced using the constant
- 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.
+
PostgreSQL, shown in
+ linkend="datatype-character-special-table">. 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 64 bytes (63 usable characters plus
+ terminator) but should be referenced using the constant
+ 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.
- CHAR(n):
- fixed length character string of length
+ VARCHAR(n):
+ varying length character string of maximum length
n.
- VARCHAR(n):
- varying length character string of maximum length
+ CHAR(n):
+ fixed length character string of length
n.
+