String Data Types
PostgreSQL includes three basic data types for storing string-related data. In compliance with the SQL standard, there are types for fixed-length and variable-length character strings. Additionally, PostgreSQL defines a more generic data type named TEXT that requires no specified upper limit regarding maximum size. However, this data type is PostgreSQL-specific and is not compliant with the SQL-92 standards.
CHAR (or CHARACTER)
Description
Holds a fixed-length string specified with a maximum length.
Inputs
CHAR(n)
n—Integer length of string (if omitted, a 1 is assumed).
Storage Size
(4+n) bytes
Notes
CHAR is a SQL-92-compatible data type. Data that does not fill to the limit specified is blank padded.
TEXT
Description
Holds a variable-length string.
Storage Size
Variable—depends on the length of string, but no smaller than 4 bytes.
VARCHAR (or CHARACTER VARYING)
Description
Holds a variable-length string with a specified limit.
Inputs
VARCHAR(n)
n—Integer length of string (if omitted, a 1 is assumed).
Storage Size
Variable—depends on the length of string, but no smaller than 4 bytes.
Notes
VARCHAR and CHARACTER VARYING are both SQL-compatible data types.
|