Скачать в pdf «PostgreSQL»

line segment


list of points









IP address with optional netmask


IP network address


Ethernet MAC address

Table 9.1: PostgreSQL data types

9.2 Installed Types

PostgreSQL supports a large number of data types, as shown in Table
9.1. Except for the number types, all entered values must be surrounded by single quotes.

Character String

Character string types are the most commonly used data types. They can hold any sequence of letters, digits, punctuation, and other valid characters. Typical character strings are names, descriptions, and mailing addresses. You can store any value in a character string. Nevertheless, this type should be used only when other data types are inappropriate, as other types provide better data validation, more compact storage, and better performance.

Three character string data types exist: text, VARCHAR (length), and CHAR(length). Text does not limit the number of characters stored. VARCHAR(length) limits the length of the field to

length characters. Both text and VARCHAR() store only the number of characters in the string. CHAR(length) is similar to VARCHAR(), except it always stores exactly length characters. This type pads the value with trailing spaces to achieve the specified length, and provides slightly faster access than text or VARCHAR().

Understanding why character string types differ from other data types can be difficult. For example, you can store 763 as a character string. In that case, you will store the symbols 7, 6, and 3, not the numeric value 763. Consequently, you cannot add a number to the character string 763, because it does not make sense to add a number to three symbols. Similarly, the character string 3IS/1992 consists of eight symbols starting with 3 and ending with 2. If you store this value in a character string data type, it is not a date. You cannot sort the string with other values and expect them to be in chronological order. The string 1/4/199S is less than 3/S/1992 when both are sorted as character strings because 1 is less than 3.

Скачать в pdf «PostgreSQL»