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
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>9.11.Network Address Functions and Operators</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="functions.html" title="Chapter9.Functions and Operators">
<link rel="prev" href="functions-geometry.html" title="9.10.Geometric Functions and Operators">
<link rel="next" href="functions-sequence.html" title="9.12.Sequence Manipulation Functions">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="functions-net"></a>9.11.Network Address Functions and Operators</h2></div></div></div>
<p> <a href="functions-net.html#cidr-inet-operators-table" title="Table9.31.cidr and inet Operators">Table9.31, “<code class="type">cidr</code> and <code class="type">inet</code> Operators”</a> shows the operators
available for the <code class="type">cidr</code> and <code class="type">inet</code> types.
The operators <code class="literal"><<</code>,
<code class="literal"><<=</code>, <code class="literal">>></code>, and
<code class="literal">>>=</code> test for subnet inclusion. They
consider only the network parts of the two addresses, ignoring any
host part, and determine whether one network part is identical to
or a subnet of the other.
</p>
<div class="table">
<a name="cidr-inet-operators-table"></a><p class="title"><b>Table9.31.<code class="type">cidr</code> and <code class="type">inet</code> Operators</b></p>
<div class="table-contents"><table summary="cidr and inet Operators" border="1">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>Operator</th>
<th>Description</th>
<th>Example</th>
</tr></thead>
<tbody>
<tr>
<td> <code class="literal"><</code> </td>
<td>is less than</td>
<td><code class="literal">inet '192.168.1.5' < inet '192.168.1.6'</code></td>
</tr>
<tr>
<td> <code class="literal"><=</code> </td>
<td>is less than or equal</td>
<td><code class="literal">inet '192.168.1.5' <= inet '192.168.1.5'</code></td>
</tr>
<tr>
<td> <code class="literal">=</code> </td>
<td>equals</td>
<td><code class="literal">inet '192.168.1.5' = inet '192.168.1.5'</code></td>
</tr>
<tr>
<td> <code class="literal">>=</code> </td>
<td>is greater or equal</td>
<td><code class="literal">inet '192.168.1.5' >= inet '192.168.1.5'</code></td>
</tr>
<tr>
<td> <code class="literal">></code> </td>
<td>is greater than</td>
<td><code class="literal">inet '192.168.1.5' > inet '192.168.1.4'</code></td>
</tr>
<tr>
<td> <code class="literal"><></code> </td>
<td>is not equal</td>
<td><code class="literal">inet '192.168.1.5' <> inet '192.168.1.4'</code></td>
</tr>
<tr>
<td> <code class="literal"><<</code> </td>
<td>is contained within</td>
<td><code class="literal">inet '192.168.1.5' << inet '192.168.1/24'</code></td>
</tr>
<tr>
<td> <code class="literal"><<=</code> </td>
<td>is contained within or equals</td>
<td><code class="literal">inet '192.168.1/24' <<= inet '192.168.1/24'</code></td>
</tr>
<tr>
<td> <code class="literal">>></code> </td>
<td>contains</td>
<td><code class="literal">inet '192.168.1/24' >> inet '192.168.1.5'</code></td>
</tr>
<tr>
<td> <code class="literal">>>=</code> </td>
<td>contains or equals</td>
<td><code class="literal">inet '192.168.1/24' >>= inet '192.168.1/24'</code></td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p> <a href="functions-net.html#cidr-inet-functions-table" title="Table9.32.cidr and inet Functions">Table9.32, “<code class="type">cidr</code> and <code class="type">inet</code> Functions”</a> shows the functions
available for use with the <code class="type">cidr</code> and <code class="type">inet</code>
types. The <code class="function">host</code>,
<code class="function">text</code>, and <code class="function">abbrev</code>
functions are primarily intended to offer alternative display
formats. You can cast a text value to <code class="type">inet</code> using normal casting
syntax: <code class="literal">inet(<em class="replaceable"><code>expression</code></em>)</code> or
<code class="literal"><em class="replaceable"><code>colname</code></em>::inet</code>.
</p>
<div class="table">
<a name="cidr-inet-functions-table"></a><p class="title"><b>Table9.32.<code class="type">cidr</code> and <code class="type">inet</code> Functions</b></p>
<div class="table-contents"><table summary="cidr and inet Functions" border="1">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>Function</th>
<th>Return Type</th>
<th>Description</th>
<th>Example</th>
<th>Result</th>
</tr></thead>
<tbody>
<tr>
<td><code class="literal"><code class="function">broadcast</code>(<code class="type">inet</code>)</code></td>
<td><code class="type">inet</code></td>
<td>broadcast address for network</td>
<td><code class="literal">broadcast('192.168.1.5/24')</code></td>
<td><code class="literal">192.168.1.255/24</code></td>
</tr>
<tr>
<td><code class="literal"><code class="function">host</code>(<code class="type">inet</code>)</code></td>
<td><code class="type">text</code></td>
<td>extract IP address as text</td>
<td><code class="literal">host('192.168.1.5/24')</code></td>
<td><code class="literal">192.168.1.5</code></td>
</tr>
<tr>
<td><code class="literal"><code class="function">masklen</code>(<code class="type">inet</code>)</code></td>
<td><code class="type">int</code></td>
<td>extract netmask length</td>
<td><code class="literal">masklen('192.168.1.5/24')</code></td>
<td><code class="literal">24</code></td>
</tr>
<tr>
<td><code class="literal"><code class="function">set_masklen</code>(<code class="type">inet</code>, <code class="type">int</code>)</code></td>
<td><code class="type">inet</code></td>
<td>set netmask length for <code class="type">inet</code> value</td>
<td><code class="literal">set_masklen('192.168.1.5/24', 16)</code></td>
<td><code class="literal">192.168.1.5/16</code></td>
</tr>
<tr>
<td><code class="literal"><code class="function">netmask</code>(<code class="type">inet</code>)</code></td>
<td><code class="type">inet</code></td>
<td>construct netmask for network</td>
<td><code class="literal">netmask('192.168.1.5/24')</code></td>
<td><code class="literal">255.255.255.0</code></td>
</tr>
<tr>
<td><code class="literal"><code class="function">hostmask</code>(<code class="type">inet</code>)</code></td>
<td><code class="type">inet</code></td>
<td>construct host mask for network</td>
<td><code class="literal">hostmask('192.168.23.20/30')</code></td>
<td><code class="literal">0.0.0.3</code></td>
</tr>
<tr>
<td><code class="literal"><code class="function">network</code>(<code class="type">inet</code>)</code></td>
<td><code class="type">cidr</code></td>
<td>extract network part of address</td>
<td><code class="literal">network('192.168.1.5/24')</code></td>
<td><code class="literal">192.168.1.0/24</code></td>
</tr>
<tr>
<td><code class="literal"><code class="function">text</code>(<code class="type">inet</code>)</code></td>
<td><code class="type">text</code></td>
<td>extract IP address and netmask length as text</td>
<td><code class="literal">text(inet '192.168.1.5')</code></td>
<td><code class="literal">192.168.1.5/32</code></td>
</tr>
<tr>
<td><code class="literal"><code class="function">abbrev</code>(<code class="type">inet</code>)</code></td>
<td><code class="type">text</code></td>
<td>abbreviated display format as text</td>
<td><code class="literal">abbrev(cidr '10.1.0.0/16')</code></td>
<td><code class="literal">10.1/16</code></td>
</tr>
<tr>
<td><code class="literal"><code class="function">family</code>(<code class="type">inet</code>)</code></td>
<td><code class="type">int</code></td>
<td>extract family of address; <code class="literal">4</code> for IPv4,
<code class="literal">6</code> for IPv6</td>
<td><code class="literal">family('::1')</code></td>
<td><code class="literal">6</code></td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><p> <a href="functions-net.html#macaddr-functions-table" title="Table9.33.macaddr Functions">Table9.33, “<code class="type">macaddr</code> Functions”</a> shows the functions
available for use with the <code class="type">macaddr</code> type. The function
<code class="literal"><code class="function">trunc</code>(<code class="type">macaddr</code>)</code> returns a MAC
address with the last 3 bytes set to zero. This can be used to
associate the remaining prefix with a manufacturer. The directory
<code class="filename">contrib/mac</code> in the source distribution
contains some utilities to create and maintain such an association
table.
</p>
<div class="table">
<a name="macaddr-functions-table"></a><p class="title"><b>Table9.33.<code class="type">macaddr</code> Functions</b></p>
<div class="table-contents"><table summary="macaddr Functions" border="1">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>Function</th>
<th>Return Type</th>
<th>Description</th>
<th>Example</th>
<th>Result</th>
</tr></thead>
<tbody><tr>
<td><code class="literal"><code class="function">trunc</code>(<code class="type">macaddr</code>)</code></td>
<td><code class="type">macaddr</code></td>
<td>set last 3 bytes to zero</td>
<td><code class="literal">trunc(macaddr '12:34:56:78:90:ab')</code></td>
<td><code class="literal">12:34:56:00:00:00</code></td>
</tr></tbody>
</table></div>
</div>
<br class="table-break"><p> The <code class="type">macaddr</code> type also supports the standard relational
operators (<code class="literal">></code>, <code class="literal"><=</code>, etc.) for
lexicographical ordering.
</p>
</div></body>
</html>
|