]> begriffs open source - ai-pg/blob - full-docs/txt/datatype.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / datatype.txt
1
2 Chapter 8. Data Types
3
4    Table of Contents
5
6    8.1. Numeric Types
7
8         8.1.1. Integer Types
9         8.1.2. Arbitrary Precision Numbers
10         8.1.3. Floating-Point Types
11         8.1.4. Serial Types
12
13    8.2. Monetary Types
14    8.3. Character Types
15    8.4. Binary Data Types
16
17         8.4.1. bytea Hex Format
18         8.4.2. bytea Escape Format
19
20    8.5. Date/Time Types
21
22         8.5.1. Date/Time Input
23         8.5.2. Date/Time Output
24         8.5.3. Time Zones
25         8.5.4. Interval Input
26         8.5.5. Interval Output
27
28    8.6. Boolean Type
29    8.7. Enumerated Types
30
31         8.7.1. Declaration of Enumerated Types
32         8.7.2. Ordering
33         8.7.3. Type Safety
34         8.7.4. Implementation Details
35
36    8.8. Geometric Types
37
38         8.8.1. Points
39         8.8.2. Lines
40         8.8.3. Line Segments
41         8.8.4. Boxes
42         8.8.5. Paths
43         8.8.6. Polygons
44         8.8.7. Circles
45
46    8.9. Network Address Types
47
48         8.9.1. inet
49         8.9.2. cidr
50         8.9.3. inet vs. cidr
51         8.9.4. macaddr
52         8.9.5. macaddr8
53
54    8.10. Bit String Types
55    8.11. Text Search Types
56
57         8.11.1. tsvector
58         8.11.2. tsquery
59
60    8.12. UUID Type
61    8.13. XML Type
62
63         8.13.1. Creating XML Values
64         8.13.2. Encoding Handling
65         8.13.3. Accessing XML Values
66
67    8.14. JSON Types
68
69         8.14.1. JSON Input and Output Syntax
70         8.14.2. Designing JSON Documents
71         8.14.3. jsonb Containment and Existence
72         8.14.4. jsonb Indexing
73         8.14.5. jsonb Subscripting
74         8.14.6. Transforms
75         8.14.7. jsonpath Type
76
77    8.15. Arrays
78
79         8.15.1. Declaration of Array Types
80         8.15.2. Array Value Input
81         8.15.3. Accessing Arrays
82         8.15.4. Modifying Arrays
83         8.15.5. Searching in Arrays
84         8.15.6. Array Input and Output Syntax
85
86    8.16. Composite Types
87
88         8.16.1. Declaration of Composite Types
89         8.16.2. Constructing Composite Values
90         8.16.3. Accessing Composite Types
91         8.16.4. Modifying Composite Types
92         8.16.5. Using Composite Types in Queries
93         8.16.6. Composite Type Input and Output Syntax
94
95    8.17. Range Types
96
97         8.17.1. Built-in Range and Multirange Types
98         8.17.2. Examples
99         8.17.3. Inclusive and Exclusive Bounds
100         8.17.4. Infinite (Unbounded) Ranges
101         8.17.5. Range Input/Output
102         8.17.6. Constructing Ranges and Multiranges
103         8.17.7. Discrete Range Types
104         8.17.8. Defining New Range Types
105         8.17.9. Indexing
106         8.17.10. Constraints on Ranges
107
108    8.18. Domain Types
109    8.19. Object Identifier Types
110    8.20. pg_lsn Type
111    8.21. Pseudo-Types
112
113    PostgreSQL has a rich set of native data types available to users.
114    Users can add new types to PostgreSQL using the CREATE TYPE command.
115
116    Table 8.1 shows all the built-in general-purpose data types. Most of
117    the alternative names listed in the “Aliases” column are the names used
118    internally by PostgreSQL for historical reasons. In addition, some
119    internally used or deprecated types are available, but are not listed
120    here.
121
122    Table 8.1. Data Types
123    Name Aliases Description
124    bigint int8 signed eight-byte integer
125    bigserial serial8 autoincrementing eight-byte integer
126    bit [ (n) ]   fixed-length bit string
127    bit varying [ (n) ] varbit [ (n) ] variable-length bit string
128    boolean bool logical Boolean (true/false)
129    box   rectangular box on a plane
130    bytea   binary data (“byte array”)
131    character [ (n) ] char [ (n) ] fixed-length character string
132    character varying [ (n) ] varchar [ (n) ] variable-length character
133    string
134    cidr   IPv4 or IPv6 network address
135    circle   circle on a plane
136    date   calendar date (year, month, day)
137    double precision float, float8 double precision floating-point number
138    (8 bytes)
139    inet   IPv4 or IPv6 host address
140    integer int, int4 signed four-byte integer
141    interval [ fields ] [ (p) ]   time span
142    json   textual JSON data
143    jsonb   binary JSON data, decomposed
144    line   infinite line on a plane
145    lseg   line segment on a plane
146    macaddr   MAC (Media Access Control) address
147    macaddr8   MAC (Media Access Control) address (EUI-64 format)
148    money   currency amount
149    numeric [ (p, s) ] decimal [ (p, s) ] exact numeric of selectable
150    precision
151    path   geometric path on a plane
152    pg_lsn   PostgreSQL Log Sequence Number
153    pg_snapshot   user-level transaction ID snapshot
154    point   geometric point on a plane
155    polygon   closed geometric path on a plane
156    real float4 single precision floating-point number (4 bytes)
157    smallint int2 signed two-byte integer
158    smallserial serial2 autoincrementing two-byte integer
159    serial serial4 autoincrementing four-byte integer
160    text   variable-length character string
161    time [ (p) ] [ without time zone ]   time of day (no time zone)
162    time [ (p) ] with time zone timetz time of day, including time zone
163    timestamp [ (p) ] [ without time zone ]   date and time (no time zone)
164    timestamp [ (p) ] with time zone timestamptz date and time, including
165    time zone
166    tsquery   text search query
167    tsvector   text search document
168    txid_snapshot   user-level transaction ID snapshot (deprecated; see
169    pg_snapshot)
170    uuid   universally unique identifier
171    xml   XML data
172
173 Compatibility
174
175    The following types (or spellings thereof) are specified by SQL:
176    bigint, bit, bit varying, boolean, char, character varying, character,
177    varchar, date, double precision, integer, interval, numeric, decimal,
178    real, smallint, time (with or without time zone), timestamp (with or
179    without time zone), xml.
180
181    Each data type has an external representation determined by its input
182    and output functions. Many of the built-in types have obvious external
183    formats. However, several types are either unique to PostgreSQL, such
184    as geometric paths, or have several possible formats, such as the date
185    and time types. Some of the input and output functions are not
186    invertible, i.e., the result of an output function might lose accuracy
187    when compared to the original input.