@@ -58,6 +58,11 @@ several possibilities for formats, such as date and time types.
58
58
<ENTRY>character(n)</ENTRY>
59
59
<ENTRY>fixed-length character string</ENTRY>
60
60
</ROW>
61
+ <ROW>
62
+ <ENTRY>cidr</ENTRY>
63
+ <ENTRY></ENTRY>
64
+ <ENTRY>IP version 4 network or host address</ENTRY>
65
+ </ROW>
61
66
<ROW>
62
67
<ENTRY>circle</ENTRY>
63
68
<ENTRY></ENTRY>
@@ -78,6 +83,11 @@ several possibilities for formats, such as date and time types.
78
83
<ENTRY>real, double precision</ENTRY>
79
84
<ENTRY>double-precision floating-point number</ENTRY>
80
85
</ROW>
86
+ <ROW>
87
+ <ENTRY>inet</ENTRY>
88
+ <ENTRY></ENTRY>
89
+ <ENTRY>IP version 4 network or host address</ENTRY>
90
+ </ROW>
81
91
<ROW>
82
92
<ENTRY>int2</ENTRY>
83
93
<ENTRY>smallint</ENTRY>
@@ -163,6 +173,14 @@ several possibilities for formats, such as date and time types.
163
173
</TABLE>
164
174
</Para>
165
175
176
+ <para>
177
+ <note>
178
+ <para>
179
+ The <type>cidr</type> and <type>inet</type> types are designed to handle any IP type
180
+ but only ipv4 is handled in the current implementation.
181
+ Everything here that talks about ipv4 will apply to ipv6 in a future release.
182
+ </note>
183
+
166
184
<Para>
167
185
<TABLE TOCENTRY="1">
168
186
<TITLE><ProductName>Postgres</ProductName> Function Constants</TITLE>
@@ -500,17 +518,21 @@ This is set at compile time and may change in a future release.
500
518
501
519
<Para>
502
520
There are two fundamental kinds of date and time measurements:
503
- clock time and time interval .
504
- Both quantities have continuity and smoothness, as does time itself.
521
+ absolute clock times and relative time intervals .
522
+ Both quantities should demonstrate continuity and smoothness, as does time itself.
505
523
<ProductName>Postgres</ProductName> supplies two primary user-oriented
506
524
date and time types,
507
- <Type>datetime</Type> and timespan, as well as
508
- the related <acronym>SQL92</acronym> types date and time.
525
+ <Type>datetime</Type> and <Type>timespan</Type>, as well as
526
+ the related <acronym>SQL92</acronym> types <Type>timestamp</Type>,
527
+ <Type>interval</Type>,
528
+ <Type>date</Type> and <Type>time</Type>.
509
529
</Para>
510
530
511
531
<Para>
512
- Other date and time types are available
513
- also, mostly
532
+ In a future release, <Type>datetime</Type> and <Type>timespan</Type> are likely
533
+ to merge with the <acronym>SQL92</acronym> types <Type>timestamp</Type>,
534
+ <Type>interval</Type>.
535
+ Other date and time types are also available, mostly
514
536
for historical reasons.
515
537
</Para>
516
538
@@ -579,6 +601,9 @@ for historical reasons.
579
601
</TBODY>
580
602
</TGROUP>
581
603
</TABLE>
604
+
605
+ <type>timestamp</type> is currently implemented separately from
606
+ <type>datetime</type>, although they share input and output routines.
582
607
</Para>
583
608
584
609
<Para>
@@ -652,13 +677,26 @@ for historical reasons.
652
677
<ProductName>Postgres</ProductName> endevours to be compatible with
653
678
<Acronym>SQL92</Acronym> definitions for typical usage.
654
679
The <Acronym>SQL92</Acronym> standard has an odd mix of date and
655
- time types and capabilities. For example, although the date type
680
+ time types and capabilities. Two obvious problems are:
681
+
682
+ <itemizedlist>
683
+ <listitem>
684
+ <para>
685
+ Although the <type>date</type> type
656
686
does not have an associated time zone, the
657
- time type can. The default time zone is specified as a constant offset
658
- from GMT/UTC;
659
- however, time zones in the real world can have no meaning unless
660
- associated with a date as well
661
- as a time since the offset will vary through the year.
687
+ <type>time</type> type can or does.
688
+
689
+ <listitem>
690
+ <para>
691
+ The default time zone is specified as a constant integer offset
692
+ from GMT/UTC.
693
+
694
+ </itemizedlist>
695
+
696
+ However, time zones in the real world can have no meaning unless
697
+ associated with a date as well as a time
698
+ since the offset may vary through the year with daylight savings
699
+ time boundaries.
662
700
663
701
<Para>
664
702
To address these difficulties, <ProductName>Postgres</ProductName>
@@ -1412,3 +1450,127 @@ Circles are output using the first syntax.
1412
1450
1413
1451
</Sect1>
1414
1452
1453
+ <Sect1>
1454
+ <Title>IP Version 4 Networks and Host Addresses</Title>
1455
+
1456
+ <Para>
1457
+ The <Type>cidr</Type> type stores networks specified
1458
+ in <acronym>CIDR</acronym> notation.
1459
+ The <Type>inet</Type> type stores hosts and networks in CIDR notation.
1460
+ </Para>
1461
+
1462
+ <Para>
1463
+ <TABLE TOCENTRY="1">
1464
+ <TITLE><ProductName>Postgres</ProductName>IP Version 4 Type</TITLE>
1465
+ <TITLEABBREV>IPV4</TITLEABBREV>
1466
+ <TGROUP COLS="4">
1467
+ <THEAD>
1468
+ <ROW>
1469
+ <ENTRY>IPV4 Type</ENTRY>
1470
+ <ENTRY>Storage</ENTRY>
1471
+ <ENTRY>Description</ENTRY>
1472
+ <ENTRY>Range</ENTRY>
1473
+ </ROW>
1474
+ </THEAD>
1475
+ <TBODY>
1476
+ <ROW>
1477
+ <ENTRY>cidr</ENTRY>
1478
+ <ENTRY>variable</ENTRY>
1479
+ <ENTRY>CIDR networks</ENTRY>
1480
+ <ENTRY>Valid IPV4 CIDR blocks</ENTRY>
1481
+ </ROW>
1482
+ <ROW>
1483
+ <ENTRY>inet</ENTRY>
1484
+ <ENTRY>variable</ENTRY>
1485
+ <ENTRY>nets and hosts</ENTRY>
1486
+ <ENTRY>Valid IPV4 CIDR blocks</ENTRY>
1487
+ </ROW>
1488
+ </TBODY>
1489
+ </TGROUP>
1490
+ </TABLE>
1491
+ </Para>
1492
+
1493
+ <Sect2>
1494
+ <Title><type>inet</type> for IP Networks</Title>
1495
+
1496
+ <Para>
1497
+ The cidr type holds a CIDR network.
1498
+ The format for specifying networks is "x.x.x.x/y" where "x.x.x.x" is the
1499
+ network and "/y" is the number of bits in the netmask.
1500
+ If the "/y" part is left off, it is calculated using assumptions from
1501
+ the old class system except that it is extended to include at least
1502
+ all of the octets in the input.
1503
+ Here are some examples.
1504
+
1505
+ <!-- There's a lot of examples here.
1506
+ -- Take some out if you think there are too many...
1507
+ -->
1508
+
1509
+ <Para>
1510
+ <TABLE TOCENTRY="1">
1511
+ <TGROUP COLS="4">
1512
+ <THEAD>
1513
+ <ROW>
1514
+ <ENTRY>Input</ENTRY>
1515
+ <ENTRY>Output</ENTRY>
1516
+ </THEAD>
1517
+ <TBODY>
1518
+ <ROW>
1519
+ <ENTRY>select '192.168.1'::cidr</ENTRY>
1520
+ <ENTRY>192.168.1/24</ENTRY>
1521
+ </ROW>
1522
+ <ROW>
1523
+ <ENTRY>select '192.168'::cidr</ENTRY>
1524
+ <ENTRY>192.168.0/24</ENTRY>
1525
+ </ROW>
1526
+ <ROW>
1527
+ <ENTRY>select '128.1'::cidr</ENTRY>
1528
+ <ENTRY>128.1/16</ENTRY>
1529
+ </ROW>
1530
+ <ROW>
1531
+ <ENTRY>select '128':::cidr</ENTRY>
1532
+ <ENTRY>128.0/16</ENTRY>
1533
+ </ROW>
1534
+ <ROW>
1535
+ <ENTRY>select '128.1.2'::cidr</ENTRY>
1536
+ <ENTRY>128.1.2/24</ENTRY>
1537
+ </ROW>
1538
+ <ROW>
1539
+ <ENTRY>select '10.1.2'::cidr</ENTRY>
1540
+ <ENTRY>10.1.2/24</ENTRY>
1541
+ </ROW>
1542
+ <ROW>
1543
+ <ENTRY>select '10.1'::cidr</ENTRY>
1544
+ <ENTRY>10.1/16</ENTRY>
1545
+ </ROW>
1546
+ <ROW>
1547
+ <ENTRY>select '10'::cidr</ENTRY>
1548
+ <ENTRY>10/8</ENTRY>
1549
+ </ROW>
1550
+ </TBODY>
1551
+ </TGROUP>
1552
+ </TABLE>
1553
+ </Para>
1554
+
1555
+ <Sect2>
1556
+ <Title><type>inet</type> for IP Networks</Title>
1557
+
1558
+ <Para>
1559
+ The inet type is designed to hold, in one field, all of the information
1560
+ about a host including the CIDR style subnet that it is in.
1561
+ Note that if you want to store proper CIDR networks, see the cidr type.
1562
+ The inet type is similar to the cidr type except that the bits in the
1563
+ host part can be non-zero.
1564
+ Functions exist to extract the various elements of the field.
1565
+ </Para>
1566
+
1567
+ <Para>
1568
+ The input format for this function is "x.x.x.x/y" where "x.x.x.x" is
1569
+ an internet host and y is the number of bits in the netmask.
1570
+ If the "/y" part is left off, it is treated as "/32."
1571
+ On output, the "/y" part is not printed if it is /32.
1572
+ This allows the type to be used as a straight host type by just leaving of
1573
+ the bits part.
1574
+ </Sect1>
1575
+
1576
+ </chapter>
0 commit comments