aboutsummaryrefslogtreecommitdiff
path: root/doc/src/sgml/datatype.sgml
blob: e805d2beacfc0f99af41aaf6fb5d3981affb271f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.42 2000/11/16 06:03:40 momjian Exp $
-->

 <chapter id="datatype">
  <title id="datatype-title">Data Types</title>

  <abstract>
   <para>
    Describes the built-in data types available in 
    <productname>Postgres</productname>.
   </para>
  </abstract>

  <para>
   <productname>Postgres</productname> has a rich set of native data 
   types available to users.
   Users may add new types to <productname>Postgres</productname> using the
   <command>CREATE TYPE</command> command.
  </para>

  <para>
   In the context of data types, the following sections will discuss 
   <acronym>SQL</acronym> standards compliance, porting issues, and usage.

   Some <productname>Postgres</productname> types correspond directly to 
   <acronym>SQL92</acronym>-compatible types. In other
   cases, data types defined by <acronym>SQL92</acronym> syntax are mapped directly
   into native <productname>Postgres</productname> types. 

   Many of the built-in types have obvious external formats. However, several
   types are either unique to <productname>Postgres</productname>, 
   such as open and closed paths, or have
   several possibilities for formats, such as the date and time types.
  </para>

  <para>
   <table tocentry="1">
    <title><productname>Postgres</productname> Data Types</title>
    <titleabbrev>Data Types</titleabbrev>
    <tgroup cols="3">
     <thead>
      <row>
       <entry><productname>Postgres</productname> Type</entry>
       <entry><acronym>SQL92</acronym> or <acronym>SQL99</acronym> Type</entry>
       <entry>Description</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>bool</entry>
       <entry>boolean</entry>
       <entry>logical boolean (true/false)</entry>
      </row>
      <row>
       <entry>box</entry>
       <entry></entry>
       <entry>rectangular box in 2D plane</entry>
      </row>
      <row>
       <entry>char(n)</entry>
       <entry>character(n)</entry>
       <entry>fixed-length character string</entry>
      </row>
      <row>
       <entry>cidr</entry>
       <entry></entry>
       <entry>IP network address</entry>
      </row>
      <row>
       <entry>circle</entry>
       <entry></entry>
       <entry>circle in 2D plane</entry>
      </row>
      <row>
       <entry>date</entry>
       <entry>date</entry>
       <entry>calendar date without time of day</entry>
      </row>
      <row>
       <entry>decimal</entry>
       <entry>decimal(p,s)</entry>
       <entry>exact numeric with selectable precision</entry>
      </row>
      <row>
       <entry>float4</entry>
       <entry>float(<replaceable>p</replaceable>), <replaceable>p</replaceable> < 7</entry>
       <entry>floating-point number with precision <replaceable>p</replaceable></entry>
      </row>
      <row>
       <entry>float8</entry>
       <entry>float(<replaceable>p</replaceable>), 7 <= <replaceable>p</replaceable> < 16</entry>
       <entry>floating-point number with precision <replaceable>p</replaceable></entry>
      </row>
      <row>
       <entry>inet</entry>
       <entry></entry>
       <entry>IP network or host address</entry>
      </row>
      <row>
       <entry>int2</entry>
       <entry>smallint</entry>
       <entry>signed two-byte integer</entry>
      </row>
      <row>
       <entry>int4</entry>
       <entry>int, integer</entry>
       <entry>signed 4-byte integer</entry>
      </row>
      <row>
       <entry>int8</entry>
       <entry></entry>
       <entry>signed 8-byte integer</entry>
      </row>
      <row>
       <entry>interval</entry>
       <entry>interval</entry>
       <entry>general-use time span</entry>
      </row>
      <row>
       <entry>line</entry>
       <entry></entry>
       <entry>infinite line in 2D plane</entry>
      </row>
      <row>
       <entry>lseg</entry>
       <entry></entry>
       <entry>line segment in 2D plane</entry>
      </row>
      <row>
       <entry>money</entry>
       <entry>decimal(9,2)</entry>
       <entry>US-style currency</entry>
      </row>
      <row>
       <entry>numeric</entry>
       <entry>numeric(p,s)</entry>
       <entry>exact numeric with selectable precision</entry>
      </row>
      <row>
       <entry>path</entry>
       <entry></entry>
       <entry>open and closed geometric path in 2D plane</entry>
      </row>
      <row>
       <entry>point</entry>
       <entry></entry>
       <entry>geometric point in 2D plane</entry>
      </row>
      <row>
       <entry>polygon</entry>
       <entry></entry>
       <entry>closed geometric path in 2D plane</entry>
      </row>
      <row>
       <entry>serial</entry>
       <entry></entry>
       <entry>unique id for indexing and cross-reference</entry>
      </row>
      <row>
       <entry>text</entry>
       <entry></entry>
       <entry>variable-length character string</entry>
      </row>
      <row>
       <entry>time</entry>
       <entry>time [ without time zone ]</entry>
       <entry>time of day</entry>
      </row>
      <row>
       <entry>timetz</entry>
       <entry>time with time zone</entry>
       <entry>time of day, including time zone</entry>
      </row>
      <row>
       <entry>timestamp</entry>
       <entry>timestamp [ with time zone ]</entry>
       <entry>date/time</entry>
      </row>
      <row>
       <entry>varchar(n)</entry>
       <entry>character varying(n)</entry>
       <entry>variable-length character string</entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </para>

  <para>
   <note>
    <para>
     The <type>cidr</type> and <type>inet</type> types are designed to handle any IP type 
     but only ipv4 is handled in the current implementation.  
     Everything here that talks about ipv4 will apply to ipv6 in a
     future release.
    </para>
   </note>
  </para>

  <para>
   <table tocentry="1">
    <title><productname>Postgres</productname> Function Constants</title>
    <titleabbrev>Constants</titleabbrev>
    <tgroup cols="3">
     <thead>
      <row>
       <entry><productname>Postgres</productname> Function</entry>
       <entry><acronym>SQL92</acronym> Constant</entry>
       <entry>Description</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>date('now')</entry>
       <entry>current_date</entry>
       <entry>date of current transaction</entry>
      </row>
      <row>
       <entry>time('now')</entry>
       <entry>current_time</entry>
       <entry>time of current transaction</entry>
      </row>
      <row>
       <entry>timestamp('now')</entry>
       <entry>current_timestamp</entry>
       <entry>date and time of current transaction</entry>
      </row>
     </tbody>
    </tgroup>
   </table>
  </para>

  <para>
   <productname>Postgres</productname> has features at the forefront of 
   <acronym>ORDBMS</acronym> development. In addition to
   <acronym>SQL99</acronym> conformance, substantial portions 
   of <acronym>SQL92</acronym> are also supported.
   Although we strive for <acronym>SQL92</acronym> compliance, 
   there are some aspects of the standard
   which are ill considered and which should not live through subsequent standards.
   <productname>Postgres</productname> will not make great efforts to 
   conform to these features; however, these tend to apply in little-used 
   or obsure cases, and a typical user is not likely to run into them.
  </para>

  <para>
   Most of the input and output functions corresponding to the
   base types (e.g., integers and floating point numbers) do some
   error-checking.
   Some of the operators and functions (e.g.,
   addition and multiplication) do not perform run-time error-checking in the
   interests of improving execution speed.
   On some systems, for example, the numeric operators for some data types may
   silently underflow or overflow.
  </para>

  <para>
   Some of the input and output functions are not invertible.  That is,
   the result of an output function may lose precision when compared to
   the original input.

   <note>
    <para>
     Floating point numbers are allowed to retain
     most of the intrinsic precision of the type (typically 15 digits for doubles, 
     6 digits for 4-byte floats). 
     Other types with underlying floating point fields (e.g. geometric
     types) carry similar precision.
    </para>
   </note>
  </para>

  <sect1 id="numeric-types">
   <title>Numeric Types</title>

   <para>
    Numeric types consist of two-, four-, and eight-byte integers,
    four- and eight-byte
    floating point numbers and fixed-precision decimals.
   </para>

   <para>
    <table tocentry="1">
     <title><productname>Postgres</productname> Numeric Types</title>
     <titleabbrev>Numerics</titleabbrev>
     <tgroup cols="4">
      <thead>
       <row>
	<entry>Numeric Type</entry>
	<entry>Storage</entry>
	<entry>Description</entry>
	<entry>Range</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>decimal</entry>
	<entry>variable</entry>
	<entry>User-specified precision</entry>
	<entry>no limit</entry>
       </row>
       <row>
	<entry>float4</entry>
	<entry>4 bytes</entry>
	<entry>Variable-precision</entry>
	<entry>6 decimal places</entry>
       </row>
       <row>
	<entry>float8</entry>
	<entry>8 bytes</entry>
	<entry>Variable-precision</entry>
	<entry>15 decimal places</entry>
       </row>
       <row>
	<entry>int2</entry>
	<entry>2 bytes</entry>
	<entry>Fixed-precision</entry>
	<entry>-32768 to +32767</entry>
       </row>
       <row>
	<entry>int4</entry>
	<entry>4 bytes</entry>
	<entry>Usual choice for fixed-precision</entry>
	<entry>-2147483648 to +2147483647</entry>
       </row>
       <row>
	<entry>int8</entry>
	<entry>8 bytes</entry>
	<entry>Very large range fixed-precision</entry>
	<entry>~18 decimal places</entry>
       </row>
       <row>
	<entry>numeric</entry>
	<entry>variable</entry>
	<entry>User-specified precision</entry>
	<entry>no limit</entry>
       </row>
       <row>
	<entry>serial</entry>
	<entry>4 bytes</entry>
	<entry>Identifer or cross-reference</entry>
	<entry>0 to +2147483647</entry>
       </row>
      </tbody>
     </tgroup>
    </table>
   </para>

   <para>
    The numeric types have a full set of corresponding arithmetic operators and
    functions. Refer to <xref linkend="numerical-operators"> 
    and <xref linkend="math-functions"> for more information.
   </para>

   <para>
    The <type>int8</type> type may not be available on all platforms since
    it relies on compiler support for eight-byte integers.
   </para>

   <sect2>
    <title>The Serial Type</title>

    <para>
     The <type>serial</type> type is a special-case type constructed by
     <productname>Postgres</productname> from other existing components.
     It is typically used to create unique identifiers for table entries.
     In the current implementation, specifying

     <programlisting>
CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceable class="parameter">colname</replaceable> SERIAL);
     </programlisting>

     is equivalent to specifying:

     <programlisting>
CREATE SEQUENCE <replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq;
CREATE TABLE <replaceable class="parameter">tablename</replaceable>
    (<replaceable class="parameter">colname</replaceable> INT4 DEFAULT nextval('<replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_seq');
CREATE UNIQUE INDEX <replaceable class="parameter">tablename</replaceable>_<replaceable class="parameter">colname</replaceable>_key on <replaceable class="parameter">tablename</replaceable> (<replaceable class="parameter">colname</replaceable>);
     </programlisting>

     <caution>
      <para>
       The implicit sequence created for the <type>serial</type> type will
       <emphasis>not</emphasis> be automatically removed when the
       table is dropped.
      </para>
     </caution>

     Implicit sequences supporting the <type>serial</type> are
     not automatically dropped when a table containing a serial type
     is dropped. So, the following commands executed in order will likely fail:

     <programlisting>
CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceable class="parameter">colname</replaceable> SERIAL);
DROP TABLE <replaceable class="parameter">tablename</replaceable>;
CREATE TABLE <replaceable class="parameter">tablename</replaceable> (<replaceable class="parameter">colname</replaceable> SERIAL);
     </programlisting>

     The sequence will remain in the database until explicitly dropped using
     <command>DROP SEQUENCE</command>.
    </para>
   </sect2>
  </sect1>

  <sect1 id="monetary-types">
   <title>Monetary Type</title>

   <note>
    <title>Obsolete Type</title>
    <para>
     The <type>money</type> is now deprecated. Use <type>numeric</type>
     or <type>decimal</type> instead. The money type may become a
     locale-aware layer over the numeric type in a future release.
    </para>
   </note>

   <para>
    The <type>money</type> type supports US-style currency with 
    fixed decimal point representation.
    If <productname>Postgres</productname> is compiled with USE_LOCALE 
    then the money type should use the monetary conventions defined for
    <citetitle>locale(7)</citetitle>.
   </para>

   <para>
    <table tocentry="1">
     <title><productname>Postgres</productname> Monetary Types</title>
     <titleabbrev>Money</titleabbrev>
     <tgroup cols="4">
      <thead>
       <row>
	<entry>Monetary Type</entry>
	<entry>Storage</entry>
	<entry>Description</entry>
	<entry>Range</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>money</entry>
	<entry>4 bytes</entry>
	<entry>Fixed-precision</entry>
	<entry>-21474836.48 to +21474836.47</entry>
       </row>
      </tbody>
     </tgroup>
    </table>
   </para>

   <para>
    <type>numeric</type>
    will replace the money type, and should be preferred.
   </para>

  </sect1>

  <sect1 id="character-types">
   <title>Character Types</title>

   <para>
    <acronym>SQL92</acronym> defines two primary character types:
    <type>char</type> and <type>varchar</type>. 
    <productname>Postgres</productname> supports these types, in
    addition to the more general <type>text</type> type, 
    which unlike <type>varchar</type>
    does not require an explicit declared upper
    limit on the size of the field.
   </para>

   <para>
    <table tocentry="1">
     <title><productname>Postgres</productname> Character Types</title>
     <titleabbrev>Characters</titleabbrev>
     <tgroup cols="4">
      <thead>
       <row>
	<entry>Character Type</entry>
	<entry>Storage</entry>
	<entry>Recommendation</entry>
	<entry>Description</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>"char"</entry>
	<entry>1 byte</entry>
	<entry><acronym>SQL92</acronym>-compatible</entry>
	<entry>Single character</entry>
       </row>
       <row>
	<entry>char(n)</entry>
	<entry>(4+n) bytes</entry>
	<entry><acronym>SQL92</acronym>-compatible</entry>
	<entry>Fixed-length blank padded</entry>
       </row>
       <row>
	<entry>text</entry>
	<entry>(4+length) bytes</entry>
	<entry>Best choice</entry>
	<entry>Variable-length</entry>
       </row>
       <row>
	<entry>varchar(n)</entry>
	<entry>(4+n) bytes</entry>
	<entry><acronym>SQL92</acronym>-compatible</entry>
	<entry>Variable-length with limit</entry>
       </row>
      </tbody>
     </tgroup>
    </table>
   </para>

   <para>
    There is one other fixed-length character type in <productname>Postgres</productname>. 
    The <type>name</type> type
    only has one purpose and that is for storage of internal catalog
    names.
    It is not intended for use by the general user.
    Its length is currently defined as 32 bytes (31 characters plus terminator) 
    but should be reference using 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.
   </para>

   <para>
    <table tocentry="1">
     <title><productname>Postgres</productname> Specialty Character Type</title>
     <titleabbrev>Specialty Characters</titleabbrev>
     <tgroup cols="3">
      <thead>
       <row>
	<entry>Character Type</entry>
	<entry>Storage</entry>
	<entry>Description</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>name</entry>
	<entry>32 bytes</entry>
	<entry>Thirty-one character internal type</entry>
       </row>
      </tbody>
     </tgroup>
    </table>
   </para>

  </sect1>

  <sect1 id="datetime-types">
   <title>Date/Time Types</title>

   <para>
    <productname>Postgres</productname> supports the full set of
    <acronym>SQL</acronym> date and time types.
   </para>

   <para>
    <table tocentry="1">
     <title><productname>Postgres</productname> Date/Time Types</title>
     <titleabbrev>Date/Time</titleabbrev>
     <tgroup cols="4">
      <thead>
       <row>
	<entry>Type</entry>
        <entry>Description</entry>
	<entry>Storage</entry>
        <entry>Earliest</entry>
        <entry>Latest</entry>
        <entry>Resolution</entry>
       </row>
      </thead>
      <tbody>
       <row>
        <entry><type>timestamp</type></entry>
        <entry>both date and time</entry>
        <entry>8 bytes</entry>
        <entry>4713 BC</entry>
        <entry>AD 1465001</entry>
        <entry>1 microsec / 14 digits</entry>
       </row>
       <row>
        <entry><type>timestamp [ with time zone ]</type></entry>
        <entry>date and time with time zone</entry>
        <entry>8 bytes</entry>
        <entry>1903 AD</entry>
        <entry>2037 AD</entry>
        <entry>1 microsec / 14 digits</entry>
       </row>
       <row>
        <entry><type>interval</type></entry>
        <entry>for time intervals</entry>
        <entry>12 bytes</entry>
        <entry>-178000000 years</entry>
        <entry>178000000 years</entry>
        <entry>1 microsecond</entry>
       </row>
       <row>
        <entry><type>date</type></entry>
        <entry>dates only</entry>
        <entry>4 bytes</entry>
        <entry>4713 BC</entry>
        <entry>32767 AD</entry>
        <entry>1 day</entry>
       </row>
       <row>
        <entry><type>time [ without time zone ]</type></entry>
        <entry>times of day only</entry>
        <entry>4 bytes</entry>
        <entry>00:00:00.00</entry>
        <entry>23:59:59.99</entry>
        <entry>1 microsecond</entry>
       </row>
       <row>
        <entry><type>time with time zone</type></entry>
        <entry>times of day only</entry>
        <entry>4 bytes</entry>
        <entry>00:00:00.00+12</entry>
        <entry>23:59:59.99-12</entry>
        <entry>1 microsecond</entry>
       </row>
      </tbody>
     </tgroup>
    </table>

    <note>
     <para>
      To ensure compatibility to earlier versions of <productname>Postgres</productname>
      we also continue to provide <type>datetime</type> (equivalent to <type>timestamp</type>) and
      <type>timespan</type> (equivalent to <type>interval</type>),
      however support for these is now restricted to having an
      implicit translation to <type>timestamp</type> and
      <type>interval</type>.
      The types <type>abstime</type>
      and <type>reltime</type> are lower precision types which are used internally.
      You are discouraged from using any of these types in new
      applications and are encouraged to move any old
      ones over when appropriate. Any or all of these internal types might disappear in a future release.
     </para>
    </note>
   </para>


   <sect2>
    <title>Date/Time Input</title>

    <para>
     Date and time input is accepted in almost any reasonable format, including
     <acronym>ISO-8601</acronym>, <acronym>SQL</acronym>-compatible, 
     traditional <productname>Postgres</productname>, and others.
     The ordering of month and day in date input can be ambiguous, therefore a setting
     exists to specify how it should be interpreted in ambiguous cases. The command
     <literal>SET DateStyle TO 'US'</literal> or <literal>SET DateStyle TO 'NonEuropean'</literal>
     specifies the variant "month before day", the command
     <literal>SET DateStyle TO 'European'</literal> sets the variant
     "day before month". The <literal>ISO</literal> style
     is the default but this default can be changed at compile time or at run time.
    </para>

    <para>
     See <xref endterm="datetime-appendix-title" linkend="datetime-appendix-title">
     for the exact parsing rules of date/time input and for the recognized time zones.
    </para>

    <para>
     Remember that any date or time input needs to be enclosed into single quotes,
     like text strings.
    </para>

    <sect3>
    <title>date</title>
    <para>
     The following are possible inputs for the <type>date</type> type.

     <table tocentry="1">
      <title><productname>Postgres</productname> Date Input</title>
      <titleabbrev>Date Inputs</titleabbrev>
      <tgroup cols="2">
       <thead>
	<row>
	 <entry>Example</entry>
	 <entry>Description</entry>
	</row>
       </thead>
       <tbody>
	<row>
	 <entry>January 8, 1999</entry>
	 <entry>Unambiguous</entry>
	</row>
	<row>
	 <entry>1999-01-08</entry>
	 <entry>ISO-8601 format, preferred</entry>
	</row>
	<row>
	 <entry>1/8/1999</entry>
	 <entry>US; read as August 1 in European mode</entry>
	</row>
	<row>
	 <entry>8/1/1999</entry>
	 <entry>European; read as August 1 in US mode</entry>
	</row>
	<row>
	 <entry>1/18/1999</entry>
	 <entry>US; read as January 18 in any mode</entry>
	</row>
	<row>
	 <entry>19990108</entry>
	 <entry>ISO-8601 year, month, day</entry>
	</row>
	<row>
	 <entry>990108</entry>
	 <entry>ISO-8601 year, month, day</entry>
	</row>
	<row>
	 <entry>1999.008</entry>
	 <entry>Year and day of year</entry>
	</row>
	<row>
	 <entry>99008</entry>
	 <entry>Year and day of year</entry>
	</row>
	<row>
	 <entry>January 8, 99 BC</entry>
	 <entry>Year 99 before the Common Era</entry>
	</row>
       </tbody>
      </tgroup>
     </table>
    </para>

    <para>
     <table tocentry="1">
      <title><productname>Postgres</productname> Month Abbreviations</title>
      <titleabbrev>Month Abbreviations</titleabbrev>
      <tgroup cols="2">
       <thead>
	<row>
	 <entry>Month</entry>
	 <entry>Abbreviations</entry>
	</row>
       </thead>
       <tbody>
	<row>
	 <entry>April</entry>
	 <entry>Apr</entry>
	</row>
	<row>
	 <entry>August</entry>
	 <entry>Aug</entry>
	</row>
	<row>
	 <entry>December</entry>
	 <entry>Dec</entry>
	</row>
	<row>
	 <entry>February</entry>
	 <entry>Feb</entry>
	</row>
	<row>
	 <entry>January</entry>
	 <entry>Jan</entry>
	</row>
	<row>
	 <entry>July</entry>
	 <entry>Jul</entry>
	</row>
	<row>
	 <entry>June</entry>
	 <entry>Jun</entry>
	</row>
	<row>
	 <entry>March</entry>
	 <entry>Mar</entry>
	</row>
	<row>
	 <entry>November</entry>
	 <entry>Nov</entry>
	</row>
	<row>
	 <entry>October</entry>
	 <entry>Oct</entry>
	</row>
	<row>
	 <entry>September</entry>
	 <entry>Sep, Sept</entry>
	</row>
       </tbody>
      </tgroup>
     </table>

     <note>
      <para>
       The month <literal>May</literal> has no explicit abbreviation, for obvious reasons.
      </para>
     </note>
    </para>

    <para>
     <table tocentry="1">
      <title><productname>Postgres</productname> Day of Week Abbreviations</title>
      <titleabbrev>Day of Week Abbreviations</titleabbrev>
      <tgroup cols="2">
       <thead>
	<row>
	 <entry>Day</entry>
	 <entry>Abbreviation</entry>
	</row>
       </thead>
       <tbody>
	<row>
	 <entry>Sunday</entry>
	 <entry>Sun</entry>
	</row>
	<row>
	 <entry>Monday</entry>
	 <entry>Mon</entry>
	</row>
	<row>
	 <entry>Tuesday</entry>
	 <entry>Tue, Tues</entry>
	</row>
	<row>
	 <entry>Wednesday</entry>
	 <entry>Wed, Weds</entry>
	</row>
	<row>
	 <entry>Thursday</entry>
	 <entry>Thu, Thur, Thurs</entry>
	</row>
	<row>
	 <entry>Friday</entry>
	 <entry>Fri</entry>
	</row>
	<row>
	 <entry>Saturday</entry>
	 <entry>Sat</entry>
	</row>
       </tbody>
      </tgroup>
     </table>
    </para>
    </sect3>

    <sect3>
     <title>time [ without time zone ]</title>

     <para>
      Per SQL99, this type can be referenced as <type>time</type> and
      as <type>time without time zone</type>.
     </para>

     <para>
      The following are valid <type>time</type> inputs.

      <table tocentry="1">
       <title><productname>Postgres</productname> Time Input</title>
       <titleabbrev>Time Inputs</titleabbrev>
       <tgroup cols="2">
	<thead>
	 <row>
	  <entry>Example</entry>
	  <entry>Description</entry>
	 </row>
	</thead>
	<tbody>
	 <row>
	  <entry>04:05:06.789</entry>
	  <entry>ISO-8601</entry>
	 </row>
	 <row>
	  <entry>04:05:06</entry>
	  <entry>ISO-8601</entry>
	 </row>
	 <row>
	  <entry>04:05</entry>
	  <entry>ISO-8601</entry>
	 </row>
	 <row>
	  <entry>040506</entry>
	  <entry>ISO-8601</entry>
	 </row>
	 <row>
	  <entry>04:05 AM</entry>
	  <entry>Same as 04:05; AM does not affect value</entry>
	 </row>
	 <row>
	  <entry>04:05 PM</entry>
	  <entry>Same as 16:05; input hour must be <= 12</entry>
	 </row>
	 <row>
	  <entry>z</entry>
	  <entry>Same as 00:00:00</entry>
	 </row>
	 <row>
	  <entry>zulu</entry>
	  <entry>Same as 00:00:00</entry>
	 </row>
	 <row>
	  <entry>allballs</entry>
	  <entry>Same as 00:00:00</entry>
	 </row>
	</tbody>
       </tgroup>
      </table>
     </para>
    </sect3>

    <sect3>
     <title>time with time zone</title>

     <para>
      This type is defined by SQL92, but the definition exhibits
      fundamental deficiencies which renders the type nearly useless. In
      most cases, a combination of <type>date</type>,
      <type>time</type>, and <type>timestamp</type>
      should provide a complete range of date/time functionality
      required by any application.
     </para>

     <para>
      <type>time with time zone</type> accepts all input also legal
      for the <type>time</type> type, appended with a legal time zone,
      as follows:

      <table tocentry="1">
       <title><productname>Postgres</productname> Time With Time
	Zone Input</title>
       <titleabbrev>Time With Time Zone Inputs</titleabbrev>
       <tgroup cols="2">
       <thead>
	<row>
	 <entry>Example</entry>
	 <entry>Description</entry>
	</row>
       </thead>
       <tbody>
	<row>
	 <entry>04:05:06.789-8</entry>
	 <entry>ISO-8601</entry>
	</row>
	<row>
	 <entry>04:05:06-08:00</entry>
	 <entry>ISO-8601</entry>
	</row>
	<row>
	 <entry>04:05-08:00</entry>
	 <entry>ISO-8601</entry>
	</row>
	<row>
	 <entry>040506-08</entry>
	 <entry>ISO-8601</entry>
	</row>
       </tbody>
      </tgroup>
     </table>
    </para>

     <para>
      Refer to <xref endterm="timezone-title" linkend="timezone"> for
      more examples of time zones.
     </para>
    </sect3>

    <sect3>
    <title>timestamp</title>

     <para>
      Valid input for the <type>timestamp</type> type consists of a concatenation
      of a date and a time, followed by an optional <literal>AD</literal> or
      <literal>BC</literal>, followed by an optional time zone. (See below.)
      Thus

      <programlisting>
1999-01-08 04:05:06 -8:00
      </programlisting>

      is a valid <type>timestamp</type> value, which is <acronym>ISO</acronym>-compliant.
      In addition, the wide-spread format

      <programlisting>
January 8 04:05:06 1999 PST
      </programlisting>
      is supported.
     </para>

     <para>
      <table tocentry="1" id="timezone">
       <title id="timezone-title"><productname>Postgres</productname> Time Zone Input</title>
       <titleabbrev>Time Zone Inputs</titleabbrev>
       <tgroup cols="2">
	<thead>
	 <row>
	  <entry>Time Zone</entry>
	  <entry>Description</entry>
	 </row>
	</thead>
	<tbody>
	 <row>
	  <entry>PST</entry>
	  <entry>Pacific Standard Time</entry>
	 </row>
	 <row>
	  <entry>-8:00</entry>
	  <entry>ISO-8601 offset for PST</entry>
	 </row>
	 <row>
	  <entry>-800</entry>
	  <entry>ISO-8601 offset for PST</entry>
	 </row>
	 <row>
	  <entry>-8</entry>
	  <entry>ISO-8601 offset for PST</entry>
	 </row>
	</tbody>
       </tgroup>
      </table>
     </para>
    </sect3>

    <sect3>
     <title>interval</title>

      <para>
       <type>interval</type>s can be specified with the following syntax:

      <programlisting>
  Quantity Unit [Quantity Unit...] [Direction]
@ Quantity Unit [Direction]
      </programlisting>

      where: <literal>Quantity</literal> is ..., <literal>-1</literal>,
      <literal>0</literal>, <literal>1</literal>, <literal>2</literal>, ...;
      <literal>Unit</literal> is <literal>second</literal>,
      <literal>minute</literal>, <literal>hour</literal>, <literal>day</literal>,
      <literal>week</literal>, <literal>month</literal>, <literal>year</literal>,
      <literal>decade</literal>, <literal>century</literal>, <literal>millennium</literal>,
      or abbreviations or plurals of these units;
      <literal>Direction</literal> can be <literal>ago</literal> or
      empty.
     </para>
    </sect3>

    <sect3>
     <title>Special values</title>

     <para>
      The following <acronym>SQL</acronym>-compatible functions can be used as date or time
      input for the corresponding datatype: <literal>CURRENT_DATE</literal>,
      <literal>CURRENT_TIME</literal>, <literal>CURRENT_TIMESTAMP</literal>.
     </para>
     <para>
      <productname>Postgres</productname> also supports several special constants for
      convenience.

     <table tocentry="1">
      <title><productname>Postgres</productname> Special Date/Time Constants</title>
      <titleabbrev>Constants</titleabbrev>
      <tgroup cols="2">
       <thead>
	<row>
	 <entry>Constant</entry>
	 <entry>Description</entry>
	</row>
       </thead>
       <tbody>
	<row>
	 <entry>current</entry>
	 <entry>Current transaction time, deferred</entry>
	</row>
	<row>
	 <entry>epoch</entry>
	 <entry>1970-01-01 00:00:00+00 (Unix system time zero)</entry>
	</row>
	<row>
	 <entry>infinity</entry>
	 <entry>Later than other valid times</entry>
	</row>
	<row>
	 <entry>-infinity</entry>
	 <entry>Earlier than other valid times</entry>
	</row>
	<row>
	 <entry>invalid</entry>
	 <entry>Illegal entry</entry>
	</row>
	<row>
	 <entry>now</entry>
	 <entry>Current transaction time</entry>
	</row>
	<row>
	 <entry>today</entry>
	 <entry>Midnight today</entry>
	</row>
	<row>
	 <entry>tomorrow</entry>
	 <entry>Midnight tomorrow</entry>
        </row>
	<row>
	 <entry>yesterday</entry>
	 <entry>Midnight yesterday</entry>
	</row>
       </tbody>
      </tgroup>
     </table>
     <literal>'now'</literal> is resolved when the value is inserted, <literal>'current'</literal>
     is resolved everytime the value is retrieved. So you probably want to use <literal>'now'</literal>
     in most applications. (Of course you <emphasis>really</emphasis> want to use
     <literal>CURRENT_TIMESTAMP</literal>, which is equivalent to <literal>'now'</literal>.)
    </para>
    </sect3>

   </sect2>


   <sect2>
    <title>Date/Time Output</title>

    <para>
     Output formats can be set to one of the four styles
     ISO-8601, <acronym>SQL</acronym> (Ingres), traditional
     Postgres, and German, using the <command>SET DateStyle</command>.
     The default is the <acronym>ISO</acronym> format.

     <table tocentry="1">
      <title><productname>Postgres</productname> Date/Time Output Styles</title>
      <titleabbrev>Styles</titleabbrev>
      <tgroup cols="3">
       <thead>
	<row>
	 <entry>Style Specification</entry>
	 <entry>Description</entry>
	 <entry>Example</entry>
	</row>
       </thead>
       <tbody>
	<row>
	 <entry>'ISO'</entry>
	 <entry>ISO-8601 standard</entry>
	 <entry>1997-12-17 07:37:16-08</entry>
	</row>
	<row>
	 <entry>'SQL'</entry>
	 <entry>Traditional style</entry>
	 <entry>12/17/1997 07:37:16.00 PST</entry>
	</row>
	<row>
	 <entry>'Postgres'</entry>
	 <entry>Original style</entry>
	 <entry>Wed Dec 17 07:37:16 1997 PST</entry>
	</row>
	<row>
	 <entry>'German'</entry>
	 <entry>Regional style</entry>
	 <entry>17.12.1997 07:37:16.00 PST</entry>
	</row>
       </tbody>
      </tgroup>
     </table>
    </para>

    <para>
     The output of the <type>date</type> and <type>time</type> styles is of course
     only the date or time part in accordance with the above examples.
    </para>

    <para>
     The <acronym>SQL</acronym> style has European and non-European (US) variants, 
     which determines whether month follows day or vica versa. (See also above
     at Date/Time Input, how this setting affects interpretation of input values.)

     <table tocentry="1">
      <title><productname>Postgres</productname> Date Order Conventions</title>
      <titleabbrev>Date Order</titleabbrev>
      <tgroup cols="3">
       <thead>
	<row>
	 <entry>Style Specification</entry>
	 <entry>Description</entry>
	 <entry>Example</entry>
	</row>
       </thead>
       <tbody>
	<row>
	 <entry>European</entry>
	 <entry><replaceable>day</replaceable>/<replaceable>month</replaceable>/<replaceable>year</replaceable></entry>
	 <entry>17/12/1997 15:37:16.00 MET</entry>
	</row>
	<row>
	 <entry>US</entry>
	 <entry><replaceable>month</replaceable>/<replaceable>day</replaceable>/<replaceable>year</replaceable></entry>
	 <entry>12/17/1997 07:37:16.00 PST</entry>
	</row>
       </tbody>
      </tgroup>
     </table>
    </para>

    <para>
    <type>interval</type> output looks like the input format, except that units like
    <literal>week</literal> or <literal>century</literal> are converted to years and days.
    In ISO mode the output looks like

<programlisting>
[ Quantity Units [ ... ] ] [ Days ] Hours:Minutes [ ago ]
</programlisting>
    </para>

    <para>
     There are several ways to affect the appearance of date/time types:

     <itemizedlist spacing="compact" mark="bullet">
      <listitem>
       <para>
	The <envar>PGDATESTYLE</envar> environment variable used by the backend directly 
	on postmaster start-up.
       </para>
      </listitem>
      <listitem>
       <para>
	The <envar>PGDATESTYLE</envar> environment variable used by the frontend libpq 
	on session start-up.
       </para>
      </listitem>
      <listitem>
       <para>
	<command>SET DATESTYLE</command> <acronym>SQL</acronym> command.
       </para>
      </listitem>
     </itemizedlist>
    </para>

   </sect2>

   <sect2>
    <title>Time Zones</title>

    <para>
     <productname>Postgres</productname> endeavors to be compatible with
     <acronym>SQL92</acronym> definitions for typical usage.
     However, the <acronym>SQL92</acronym> standard has an odd mix of date and
     time types and capabilities. Two obvious problems are:

     <itemizedlist>
      <listitem>
       <para>
	Although the <type>date</type> type 
	does not have an associated time zone, the
	<type>time</type> type can or does.
	Time zones in the real world can have no meaning unless 
	associated with a date as well as a time
	since the offset may vary through the year with daylight savings
	time boundaries.
       </para>
      </listitem>

      <listitem>
       <para>
	The default time zone is specified as a constant integer offset 
	from GMT/UTC. It is not possible to adapt to daylight savings
	time when doing date/time arithmetic across
	<acronym>DST</acronym> boundaries.
       </para>
      </listitem>

     </itemizedlist>
    </para>

    <para>
     To address these difficulties, we recommend using date/time
     types which contain both date and time when using time zones. We
     recommend <emphasis>not</emphasis> using the SQL92 type TIME
     WITH TIME ZONE (though it is supported by
     <productname>Postgres</productname> for legacy applications and
     for compatibility with other RDBMS implementations).
     <productname>Postgres</productname> 
     assumes local time for any type containing only
     date or time. Further, time zone support is derived from 
     the underlying operating system
     time zone capabilities, and hence can handle daylight savings time 
     and other expected behavior.
    </para>

    <para>
     <productname>Postgres</productname> obtains time zone support 
     from the underlying operating system for dates between 1902 and
     2038 (near the typical date limits for Unix-style
     systems). Outside of this range, all dates are assumed to be
     specified and used in Universal Coordinated Time (UTC).
    </para>

    <para>
     All dates and times are stored internally in UTC,
     traditionally known as Greenwich Mean Time (GMT). 
     Times are converted to local time on the database server before being
     sent to the client frontend, hence by default are in the server
     time zone.
    </para>

    <para>
     There are several ways to affect the time zone behavior:

     <itemizedlist spacing="compact" mark="bullet">
      <listitem>
       <para>
	The TZ environment variable is used by the backend directly
	on postmaster start-up as the default time zone.
       </para>
      </listitem>
      <listitem>
       <para>
	The PGTZ environment variable set at the client used by libpq 
	to send time zone information to the backend upon connection.
       </para>
      </listitem>
      <listitem>
       <para>
	The <acronym>SQL</acronym> command <command>SET TIME ZONE</command>
	sets the time zone for the session.
       </para>
      </listitem>
      <listitem>
       <para>
	The <acronym>SQL92</acronym> qualifier on
	<programlisting>
<replaceable>timestamp</replaceable> AT TIME ZONE '<replaceable>zone</replaceable>'
	</programlisting>
	where <replaceable>zone</replaceable> can be specified as a
	text time zone (e.g. <literal>'PST'</literal>) or as an
	interval (e.g. <literal>INTERVAL '-08:00'</literal>).
       </para>
      </listitem>
     </itemizedlist>
    </para>

    <para>
     <note>
      <para>
       If an invalid time zone is specified,
       the time zone becomes GMT (on most systems anyway).
      </para>
     </note>

     <note>
      <para>
       If the compiler option USE_AUSTRALIAN_RULES is set 
       then <literal>EST</literal> refers to Australia Eastern Std Time,
       which has an offset of +10:00 hours from UTC.
      </para>
     </note>
    </para>

   </sect2>

   <sect2>
    <title>Internals</title>

    <para>
     <productname>Postgres</productname> uses Julian dates
     for all date/time calculations. They have the nice property of correctly
     predicting/calculating any date more recent than 4713BC
     to far into the future, using the assumption that the length of the
     year is 365.2425 days.
    </para>

    <para>
     Date conventions before the 19th century make for interesting reading,
     but are not consistant enough to warrant coding into a date/time handler.
    </para>
   </sect2>

  </sect1>

  <sect1 id="boolean-type">
   <title>Boolean Type</title>

   <para>
    <productname>Postgres</productname> supports <type>bool</type> as
    the <acronym>SQL99</acronym> boolean type.
    <type>bool</type> can have one of only two states: 'true' or 'false'. 
    A third state, 'unknown', is not
    implemented and is not suggested in <acronym>SQL99</acronym>; 
    <acronym>NULL</acronym> is an
    effective substitute. <type>bool</type> can be used in any boolean expression, 
    and boolean expressions
    always evaluate to a result compatible with this type.</para>

   <para>
    <type>bool</type> uses 1 byte of storage.
   </para>

   <para>
    <table tocentry="1">
     <title><productname>Postgres</productname> Boolean Type</title>
     <titleabbrev>Booleans</titleabbrev>
     <tgroup cols="3">
      <thead>
       <row>
	<entry>State</entry>
	<entry>Output</entry>
	<entry>Input</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>True</entry>
	<entry>'t'</entry>
	<entry>TRUE, 't', 'true', 'y', 'yes', '1'</entry>
       </row>
       <row>
	<entry>False</entry>
	<entry>'f'</entry>
	<entry>FALSE, 'f', 'false', 'n', 'no', '0'</entry>
       </row>
      </tbody>
     </tgroup>
    </table>
   </para>
  </sect1>

  <sect1 id="geometric-types">
   <title>Geometric Types</title>

   <para>
    Geometric types represent two-dimensional spatial objects. 
    The most fundamental type,
    the point, forms the basis for all of the other types.
   </para>

   <para>
    <table tocentry="1">
     <title><productname>Postgres</productname> Geometric Types</title>
     <titleabbrev>Geometrics</titleabbrev>
     <tgroup cols="4">
      <thead>
       <row>
	<entry>Geometric Type</entry>
	<entry>Storage</entry>
	<entry>Representation</entry>
	<entry>Description</entry>
       </row>
      </thead>
      <tbody>
       <row>
	<entry>point</entry>
	<entry>16 bytes</entry>
	<entry>(x,y)</entry>
	<entry>Point in space</entry>
       </row>
       <row>
	<entry>line</entry>
	<entry>32 bytes</entry>
	<entry>((x1,y1),(x2,y2))</entry>
	<entry>Infinite line</entry>
       </row>
       <row>
	<entry>lseg</entry>
	<entry>32 bytes</entry>
	<entry>((x1,y1),(x2,y2))</entry>
	<entry>Finite line segment</entry>
       </row>
       <row>
	<entry>box</entry>
	<entry>32 bytes</entry>
	<entry>((x1,y1),(x2,y2))</entry>
	<entry>Rectangular box</entry>
       </row>
       <row>
	<entry>path</entry>
	<entry>4+32n bytes</entry>
	<entry>((x1,y1),...)</entry>
	<entry>Closed path (similar to polygon)</entry>
       </row>
       <row>
	<entry>path</entry>
	<entry>4+32n bytes</entry>
	<entry>[(x1,y1),...]</entry>
	<entry>Open path</entry>
       </row>
       <row>
	<entry>polygon</entry>
	<entry>4+32n bytes</entry>
	<entry>((x1,y1),...)</entry>
	<entry>Polygon (similar to closed path)</entry>
       </row>
       <row>
	<entry>circle</entry>
	<entry>24 bytes</entry>
	<entry><(x,y),r></entry>
	<entry>Circle (center and radius)</entry>
       </row>
      </tbody>
     </tgroup>
    </table>
   </para>

   <para>
    A rich set of functions and operators is available to perform various geometric
    operations such as scaling, translation, rotation, and determining 
    intersections.
   </para>

   <sect2>
    <title>Point</title>

    <para>
     Points are the fundamental two-dimensional building block for geometric types.
    </para>

    <para>
     <type>point</type> is specified using the following syntax:

     <synopsis>
( <replaceable>x</replaceable> , <replaceable>y</replaceable> )
  <replaceable>x</replaceable> , <replaceable>y</replaceable>
     </synopsis>

     where the arguments are

     <variablelist>
      <varlistentry>
       <term><replaceable>x</replaceable></term>
       <listitem>
	<para>
	 The x-axis coordinate as a floating point number.
	</para>
       </listitem>
      </varlistentry>

      <varlistentry>
       <term><replaceable>y</replaceable></term>
       <listitem>
	<para>
	 The y-axis coordinate as a floating point number.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </sect2>

   <sect2>
    <title>Line Segment</title>

    <para>
     Line segments (<type>lseg</type>) are represented by pairs of points.
    </para>

    <para>
     <type>lseg</type> is specified using the following syntax:

     <synopsis>
( ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ( <replaceable>x2</replaceable> , <replaceable>y2</replaceable> ) )
  ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ( <replaceable>x2</replaceable> , <replaceable>y2</replaceable> )  
    <replaceable>x1</replaceable> , <replaceable>y1</replaceable>   ,   <replaceable>x2</replaceable> , <replaceable>y2</replaceable>
     </synopsis>

     where the arguments are

     <variablelist>
      <varlistentry>
       <term>(<replaceable>x1</replaceable>,<replaceable>y1</replaceable>)</term>
       <term>(<replaceable>x2</replaceable>,<replaceable>y2</replaceable>)</term>
       <listitem>
	<para>
	 The endpoints of the line segment.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>
   </sect2>

   <sect2>
    <title>Box</title>

    <para>
     Boxes are represented by pairs of points which are opposite
     corners of the box.
    </para>

    <para>
     <type>box</type> is specified using the following syntax:

     <synopsis>
( ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ( <replaceable>x2</replaceable> , <replaceable>y2</replaceable> ) )
  ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ( <replaceable>x2</replaceable> , <replaceable>y2</replaceable> )  
    <replaceable>x1</replaceable> , <replaceable>y1</replaceable>   ,   <replaceable>x2</replaceable> , <replaceable>y2</replaceable>
     </synopsis>

     where the arguments are

     <variablelist>
      <varlistentry>
       <term>(<replaceable>x1</replaceable>,<replaceable>y1</replaceable>)</term>
       <term>(<replaceable>x2</replaceable>,<replaceable>y2</replaceable>)</term>
       <listitem>
	<para>
	 Opposite corners of the box.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>

    <para>
     Boxes are output using the first syntax.
     The corners are reordered on input to store
     the lower left corner first and the upper right corner last.
     Other corners of the box can be entered, but the lower
     left and upper right corners are determined from the input and stored.
    </para>
   </sect2>

   <sect2>
    <title>Path</title>

    <para>
     Paths are represented by connected sets of points. Paths can be "open", where
     the first and last points in the set are not connected, and "closed",
     where the first and last point are connected. Functions
     <function>popen(p)</function>
     and
     <function>pclose(p)</function>
     are supplied to force a path to be open or closed, and functions
     <function>isopen(p)</function>
     and
     <function>isclosed(p)</function>
     are supplied to test for either type in a query.
    </para>

    <para>
     <type>path</type> is specified using the following syntax:

     <synopsis>
( ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ... , ( <replaceable>xn</replaceable> , <replaceable>yn</replaceable> ) )
[ ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ... , ( <replaceable>xn</replaceable> , <replaceable>yn</replaceable> ) ]
  ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ... , ( <replaceable>xn</replaceable> , <replaceable>yn</replaceable> )  
  ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable>   , ... ,   <replaceable>xn</replaceable> , <replaceable>yn</replaceable> )  
    <replaceable>x1</replaceable> , <replaceable>y1</replaceable>   , ... ,   <replaceable>xn</replaceable> , <replaceable>yn</replaceable>    
     </synopsis>

     where the arguments are

     <variablelist>
      <varlistentry>
       <term>(<replaceable>x</replaceable>,<replaceable>y</replaceable>)</term>
       <listitem>
	<para>
	 Endpoints of the line segments comprising the path.
	 A leading square bracket ("[") indicates an open path, while
	 a leading parenthesis ("(") indicates a closed path.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>

    <para>
     Paths are output using the first syntax.
    </para>
   </sect2>

   <sect2>
    <title>Polygon</title>

    <para>
     Polygons are represented by sets of points. Polygons should probably be
     considered equivalent to closed paths, but are stored differently 
     and have their own set of support routines.
    </para>

    <para>
     <type>polygon</type> is specified using the following syntax:

     <synopsis>
( ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ... , ( <replaceable>xn</replaceable> , <replaceable>yn</replaceable> ) )
  ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable> ) , ... , ( <replaceable>xn</replaceable> , <replaceable>yn</replaceable> )  
  ( <replaceable>x1</replaceable> , <replaceable>y1</replaceable>   , ... ,   <replaceable>xn</replaceable> , <replaceable>yn</replaceable> )  
    <replaceable>x1</replaceable> , <replaceable>y1</replaceable>   , ... ,   <replaceable>xn</replaceable> , <replaceable>yn</replaceable>    
     </synopsis>

     where the arguments are

     <variablelist>
      <varlistentry>
       <term>(<replaceable>x</replaceable>,<replaceable>y</replaceable>)</term>
       <listitem>
	<para>
	 Endpoints of the line segments comprising the boundary of the
	 polygon.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>

    <para>
     Polygons are output using the first syntax.
    </para>
   </sect2>

   <sect2>
    <title>Circle</title>

    <para>
     Circles are represented by a center point and a radius.
    </para>

    <para>
     <type>circle</type> is specified using the following syntax:

     <synopsis>
&lt; ( <replaceable>x</replaceable> , <replaceable>y</replaceable> ) , <replaceable>r</replaceable> &gt;
( ( <replaceable>x</replaceable> , <replaceable>y</replaceable> ) , <replaceable>r</replaceable> )
  ( <replaceable>x</replaceable> , <replaceable>y</replaceable> ) , <replaceable>r</replaceable>  
    <replaceable>x</replaceable> , <replaceable>y</replaceable>   , <replaceable>r</replaceable>  
     </synopsis>

     where the arguments are

     <variablelist>
      <varlistentry>
       <term>(<replaceable>x</replaceable>,<replaceable>y</replaceable>)</term>
       <listitem>
	<para>
	 Center of the circle.
	</para>
       </listitem>
      </varlistentry>

      <varlistentry>
       <term><replaceable>r</replaceable></term>
       <listitem>
	<para>
	 Radius of the circle.
	</para>
       </listitem>
      </varlistentry>
     </variablelist>
    </para>

    <para>
     Circles are output using the first syntax.
    </para>
   </sect2>

  </sect1>

  <sect1 id="net-types">
   <title>Network Address Data Types</title>

   <para>
    <productname>Postgres</> offers data types to store IP and MAC
    addresses.  It is preferable to use these types over plain text
    types, because these types offer input error checking and several
    specialized operators and functions.

    <table tocentry="1" id="net-types-table">
     <title>Network Address Data Types</title>
     <tgroup cols="4">
      <thead>
       <row>
	<entry>Name</entry>
	<entry>Storage</entry>
	<entry>Description</entry>
	<entry>Range</entry>
       </row>
      </thead>
      <tbody>

       <row>
	<entry>cidr</entry>
	<entry>12 bytes</entry>
	<entry>IP networks</entry>
	<entry>valid IPv4 networks</entry>
       </row>

       <row>
	<entry>inet</entry>
	<entry>12 bytes</entry>
	<entry>IP hosts and networks</entry>
	<entry>valid IPv4 hosts or networks</entry>
       </row>

       <row>
	<entry>macaddr</entry>
	<entry>6 bytes</entry>
	<entry>MAC addresses</entry>
	<entry>customary formats</entry>
       </row>

      </tbody>
     </tgroup>
    </table>
   </para>

   <para>
    IP v6 is not supported, yet.
   </para>


   <sect2 id="inet-type">
    <title><type>inet</type></title>

    <para>
     The <type>inet</type> type holds an IP host address, and
     optionally the identity of the subnet it is in, all in one field.
     The subnet identity is represented by the number of bits in the
     network part of the address (the "netmask").  If the netmask is 32,
     then the value does not indicate a subnet, only a single host.
     Note that if you want to accept networks only, you should use the
     <type>cidr</type> type rather than <type>inet</type>.
    </para>

    <para>
     The input format for this type is <replaceable
     class="parameter">x.x.x.x/y</replaceable> where <replaceable
     class="parameter">x.x.x.x</replaceable> is an IP address and
     <replaceable class="parameter">y</replaceable> is the number of
     bits in the netmask.  If the <replaceable
     class="parameter">y</replaceable> part is left off, then the
     netmask is 32, and the value represents just a single host.
     On display, the <replaceable class="parameter">/y</replaceable>
     portion is suppressed if the netmask is 32.
    </para>
   </sect2>

   <sect2 id="cidr-type">
    <title><type>cidr</></title>

    <para>
     The <type>cidr</type> type holds an IP network specification.
     Input and output formats follow Classless Internet Domain Routing
     conventions.
     The format for
     specifying classless networks is <replaceable
     class="parameter">x.x.x.x/y</> where <replaceable
     class="parameter">x.x.x.x</> is the network and <replaceable
     class="parameter">y</> is the number of bits in the netmask.  If
     <replaceable class="parameter">y</> omitted, it is calculated
     using assumptions from the older classful numbering system, except
     that it will be at least large enough to include all of the octets
     written in the input.
    </para>

    <para>
     Here are some examples:

     <table tocentry="1">
      <title><type>cidr</> Type Input Examples</title>
      <tgroup cols="2">
       <thead> 
	<row> 
	 <entry>CIDR Input</entry>
	 <entry>CIDR Displayed</entry>
	</row>
       </thead>
       <tbody>
	<row>
	 <entry>192.168.100.128/25</entry>
	 <entry>192.168.100.128/25</entry>
	</row>
	<row>
	 <entry>192.168/24</entry>
	 <entry>192.168.0/24</entry>
	</row>
	<row>
	 <entry>192.168/25</entry>
	 <entry>192.168.0.0/25</entry>
	</row>
	<row>
	 <entry>192.168.1</entry>
	 <entry>192.168.1/24</entry>
	</row>
	<row>
	 <entry>192.168</entry>
	 <entry>192.168.0/24</entry>
	</row>
	<row>
	 <entry>128.1</entry>
	 <entry>128.1/16</entry>
	</row>
	<row>
	 <entry>128</entry>
	 <entry>128.0/16</entry>
	</row>
	<row>
	 <entry>128.1.2</entry>
	 <entry>128.1.2/24</entry>
	</row>
	<row>
	 <entry>10.1.2</entry>
	 <entry>10.1.2/24</entry>
	</row>
	<row>
	 <entry>10.1</entry>
	 <entry>10.1/16</entry>
	</row>
	<row>
	 <entry>10</entry>
	 <entry>10/8</entry>
	</row>
       </tbody>
      </tgroup>
     </table>
    </para>
   </sect2>

   <sect2 id="inet-vs-cidr">
    <title><type>inet</type> vs <type>cidr</type></title>

    <para>
    The essential difference between <type>inet</type> and <type>cidr</type>
    data types is that <type>inet</type> accepts values with nonzero bits to
    the right of the netmask, whereas <type>cidr</type> does not.

      <tip>
        <para>
	If you do not like the output format for <type>inet</type> or
	<type>cidr</type> values, try the <function>host</>() and
	<function>text</>() functions.
	</para>
      </tip>
    </para>
   </sect2>

   <sect2 id="macaddr-type">
    <title><type>macaddr</></>

    <para>
     The <type>macaddr</> type stores MAC addresses, i.e., Ethernet
     card hardware addresses (although MAC addresses are used for
     other purposes as well).  Input is accepted in various customary
     formats, including <literal>'08002b:010203'</>,
     <literal>'08002b-010203'</>, <literal>'0800.2b01.0203'</>,
     <literal>'08-00-2b-01-02-03'</>, and
     <literal>'08:00:2b:01:02:03'</>, which would all specify the same
     address.  Upper and lower case is accepted for the digits
     <literal>a</> through <literal>f</>.  Output is always in the
     latter of the given forms.
    </para>
   </sect2>

  </sect1>

 </chapter>

<!-- Keep this comment at the end of the file
Local variables:
mode:sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"./reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:("/usr/lib/sgml/catalog")
sgml-local-ecat-files:nil
End:
-->