summaryrefslogtreecommitdiffstats
path: root/doc/src/sgml/html/functions-net.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/sgml/html/functions-net.html')
-rw-r--r--doc/src/sgml/html/functions-net.html397
1 files changed, 397 insertions, 0 deletions
diff --git a/doc/src/sgml/html/functions-net.html b/doc/src/sgml/html/functions-net.html
new file mode 100644
index 0000000..f9fef60
--- /dev/null
+++ b/doc/src/sgml/html/functions-net.html
@@ -0,0 +1,397 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>9.12. Network Address Functions and Operators</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="functions-geometry.html" title="9.11. Geometric Functions and Operators" /><link rel="next" href="functions-textsearch.html" title="9.13. Text Search Functions and Operators" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">9.12. Network Address Functions and Operators</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-geometry.html" title="9.11. Geometric Functions and Operators">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 15.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="functions-textsearch.html" title="9.13. Text Search Functions and Operators">Next</a></td></tr></table><hr /></div><div class="sect1" id="FUNCTIONS-NET"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.12. Network Address Functions and Operators</h2></div></div></div><p>
+ The IP network address types, <code class="type">cidr</code> and <code class="type">inet</code>,
+ support the usual comparison operators shown in
+ <a class="xref" href="functions-comparison.html#FUNCTIONS-COMPARISON-OP-TABLE" title="Table 9.1. Comparison Operators">Table 9.1</a>
+ as well as the specialized operators and functions shown in
+ <a class="xref" href="functions-net.html#CIDR-INET-OPERATORS-TABLE" title="Table 9.39. IP Address Operators">Table 9.39</a> and
+ <a class="xref" href="functions-net.html#CIDR-INET-FUNCTIONS-TABLE" title="Table 9.40. IP Address Functions">Table 9.40</a>.
+ </p><p>
+ Any <code class="type">cidr</code> value can be cast to <code class="type">inet</code> implicitly;
+ therefore, the operators and functions shown below as operating on
+ <code class="type">inet</code> also work on <code class="type">cidr</code> values. (Where there are
+ separate functions for <code class="type">inet</code> and <code class="type">cidr</code>, it is
+ because the behavior should be different for the two cases.)
+ Also, it is permitted to cast an <code class="type">inet</code> value
+ to <code class="type">cidr</code>. When this is done, any bits to the right of the
+ netmask are silently zeroed to create a valid <code class="type">cidr</code> value.
+ </p><div class="table" id="CIDR-INET-OPERATORS-TABLE"><p class="title"><strong>Table 9.39. IP Address Operators</strong></p><div class="table-contents"><table class="table" summary="IP Address Operators" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
+ Operator
+ </p>
+ <p>
+ Description
+ </p>
+ <p>
+ Example(s)
+ </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">inet</code> <code class="literal">&lt;&lt;</code> <code class="type">inet</code>
+ → <code class="returnvalue">boolean</code>
+ </p>
+ <p>
+ Is subnet strictly contained by subnet?
+ This operator, and the next four, test for subnet inclusion. They
+ consider only the network parts of the two addresses (ignoring any
+ bits to the right of the netmasks) and determine whether one network
+ is identical to or a subnet of the other.
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1.5' &lt;&lt; inet '192.168.1/24'</code>
+ → <code class="returnvalue">t</code>
+ </p>
+ <p>
+ <code class="literal">inet '192.168.0.5' &lt;&lt; inet '192.168.1/24'</code>
+ → <code class="returnvalue">f</code>
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1/24' &lt;&lt; inet '192.168.1/24'</code>
+ → <code class="returnvalue">f</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">inet</code> <code class="literal">&lt;&lt;=</code> <code class="type">inet</code>
+ → <code class="returnvalue">boolean</code>
+ </p>
+ <p>
+ Is subnet contained by or equal to subnet?
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1/24' &lt;&lt;= inet '192.168.1/24'</code>
+ → <code class="returnvalue">t</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">inet</code> <code class="literal">&gt;&gt;</code> <code class="type">inet</code>
+ → <code class="returnvalue">boolean</code>
+ </p>
+ <p>
+ Does subnet strictly contain subnet?
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1/24' &gt;&gt; inet '192.168.1.5'</code>
+ → <code class="returnvalue">t</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">inet</code> <code class="literal">&gt;&gt;=</code> <code class="type">inet</code>
+ → <code class="returnvalue">boolean</code>
+ </p>
+ <p>
+ Does subnet contain or equal subnet?
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1/24' &gt;&gt;= inet '192.168.1/24'</code>
+ → <code class="returnvalue">t</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">inet</code> <code class="literal">&amp;&amp;</code> <code class="type">inet</code>
+ → <code class="returnvalue">boolean</code>
+ </p>
+ <p>
+ Does either subnet contain or equal the other?
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1/24' &amp;&amp; inet '192.168.1.80/28'</code>
+ → <code class="returnvalue">t</code>
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1/24' &amp;&amp; inet '192.168.2.0/28'</code>
+ → <code class="returnvalue">f</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="literal">~</code> <code class="type">inet</code>
+ → <code class="returnvalue">inet</code>
+ </p>
+ <p>
+ Computes bitwise NOT.
+ </p>
+ <p>
+ <code class="literal">~ inet '192.168.1.6'</code>
+ → <code class="returnvalue">63.87.254.249</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">inet</code> <code class="literal">&amp;</code> <code class="type">inet</code>
+ → <code class="returnvalue">inet</code>
+ </p>
+ <p>
+ Computes bitwise AND.
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1.6' &amp; inet '0.0.0.255'</code>
+ → <code class="returnvalue">0.0.0.6</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">inet</code> <code class="literal">|</code> <code class="type">inet</code>
+ → <code class="returnvalue">inet</code>
+ </p>
+ <p>
+ Computes bitwise OR.
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1.6' | inet '0.0.0.255'</code>
+ → <code class="returnvalue">192.168.1.255</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">inet</code> <code class="literal">+</code> <code class="type">bigint</code>
+ → <code class="returnvalue">inet</code>
+ </p>
+ <p>
+ Adds an offset to an address.
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1.6' + 25</code>
+ → <code class="returnvalue">192.168.1.31</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">bigint</code> <code class="literal">+</code> <code class="type">inet</code>
+ → <code class="returnvalue">inet</code>
+ </p>
+ <p>
+ Adds an offset to an address.
+ </p>
+ <p>
+ <code class="literal">200 + inet '::ffff:fff0:1'</code>
+ → <code class="returnvalue">::ffff:255.240.0.201</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">inet</code> <code class="literal">-</code> <code class="type">bigint</code>
+ → <code class="returnvalue">inet</code>
+ </p>
+ <p>
+ Subtracts an offset from an address.
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1.43' - 36</code>
+ → <code class="returnvalue">192.168.1.7</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="type">inet</code> <code class="literal">-</code> <code class="type">inet</code>
+ → <code class="returnvalue">bigint</code>
+ </p>
+ <p>
+ Computes the difference of two addresses.
+ </p>
+ <p>
+ <code class="literal">inet '192.168.1.43' - inet '192.168.1.19'</code>
+ → <code class="returnvalue">24</code>
+ </p>
+ <p>
+ <code class="literal">inet '::1' - inet '::ffff:1'</code>
+ → <code class="returnvalue">-4294901760</code>
+ </p></td></tr></tbody></table></div></div><br class="table-break" /><div class="table" id="CIDR-INET-FUNCTIONS-TABLE"><p class="title"><strong>Table 9.40. IP Address Functions</strong></p><div class="table-contents"><table class="table" summary="IP Address Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
+ Function
+ </p>
+ <p>
+ Description
+ </p>
+ <p>
+ Example(s)
+ </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.1.1.1.1" class="indexterm"></a>
+ <code class="function">abbrev</code> ( <code class="type">inet</code> )
+ → <code class="returnvalue">text</code>
+ </p>
+ <p>
+ Creates an abbreviated display format as text.
+ (The result is the same as the <code class="type">inet</code> output function
+ produces; it is <span class="quote">“<span class="quote">abbreviated</span>”</span> only in comparison to the
+ result of an explicit cast to <code class="type">text</code>, which for historical
+ reasons will never suppress the netmask part.)
+ </p>
+ <p>
+ <code class="literal">abbrev(inet '10.1.0.0/32')</code>
+ → <code class="returnvalue">10.1.0.0</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="function">abbrev</code> ( <code class="type">cidr</code> )
+ → <code class="returnvalue">text</code>
+ </p>
+ <p>
+ Creates an abbreviated display format as text.
+ (The abbreviation consists of dropping all-zero octets to the right
+ of the netmask; more examples are in
+ <a class="xref" href="datatype-net-types.html#DATATYPE-NET-CIDR-TABLE" title="Table 8.22. cidr Type Input Examples">Table 8.22</a>.)
+ </p>
+ <p>
+ <code class="literal">abbrev(cidr '10.1.0.0/16')</code>
+ → <code class="returnvalue">10.1/16</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.3.1.1.1" class="indexterm"></a>
+ <code class="function">broadcast</code> ( <code class="type">inet</code> )
+ → <code class="returnvalue">inet</code>
+ </p>
+ <p>
+ Computes the broadcast address for the address's network.
+ </p>
+ <p>
+ <code class="literal">broadcast(inet '192.168.1.5/24')</code>
+ → <code class="returnvalue">192.168.1.255/24</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.4.1.1.1" class="indexterm"></a>
+ <code class="function">family</code> ( <code class="type">inet</code> )
+ → <code class="returnvalue">integer</code>
+ </p>
+ <p>
+ Returns the address's family: <code class="literal">4</code> for IPv4,
+ <code class="literal">6</code> for IPv6.
+ </p>
+ <p>
+ <code class="literal">family(inet '::1')</code>
+ → <code class="returnvalue">6</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.5.1.1.1" class="indexterm"></a>
+ <code class="function">host</code> ( <code class="type">inet</code> )
+ → <code class="returnvalue">text</code>
+ </p>
+ <p>
+ Returns the IP address as text, ignoring the netmask.
+ </p>
+ <p>
+ <code class="literal">host(inet '192.168.1.0/24')</code>
+ → <code class="returnvalue">192.168.1.0</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.6.1.1.1" class="indexterm"></a>
+ <code class="function">hostmask</code> ( <code class="type">inet</code> )
+ → <code class="returnvalue">inet</code>
+ </p>
+ <p>
+ Computes the host mask for the address's network.
+ </p>
+ <p>
+ <code class="literal">hostmask(inet '192.168.23.20/30')</code>
+ → <code class="returnvalue">0.0.0.3</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.7.1.1.1" class="indexterm"></a>
+ <code class="function">inet_merge</code> ( <code class="type">inet</code>, <code class="type">inet</code> )
+ → <code class="returnvalue">cidr</code>
+ </p>
+ <p>
+ Computes the smallest network that includes both of the given networks.
+ </p>
+ <p>
+ <code class="literal">inet_merge(inet '192.168.1.5/24', inet '192.168.2.5/24')</code>
+ → <code class="returnvalue">192.168.0.0/22</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.8.1.1.1" class="indexterm"></a>
+ <code class="function">inet_same_family</code> ( <code class="type">inet</code>, <code class="type">inet</code> )
+ → <code class="returnvalue">boolean</code>
+ </p>
+ <p>
+ Tests whether the addresses belong to the same IP family.
+ </p>
+ <p>
+ <code class="literal">inet_same_family(inet '192.168.1.5/24', inet '::1')</code>
+ → <code class="returnvalue">f</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.9.1.1.1" class="indexterm"></a>
+ <code class="function">masklen</code> ( <code class="type">inet</code> )
+ → <code class="returnvalue">integer</code>
+ </p>
+ <p>
+ Returns the netmask length in bits.
+ </p>
+ <p>
+ <code class="literal">masklen(inet '192.168.1.5/24')</code>
+ → <code class="returnvalue">24</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.10.1.1.1" class="indexterm"></a>
+ <code class="function">netmask</code> ( <code class="type">inet</code> )
+ → <code class="returnvalue">inet</code>
+ </p>
+ <p>
+ Computes the network mask for the address's network.
+ </p>
+ <p>
+ <code class="literal">netmask(inet '192.168.1.5/24')</code>
+ → <code class="returnvalue">255.255.255.0</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.11.1.1.1" class="indexterm"></a>
+ <code class="function">network</code> ( <code class="type">inet</code> )
+ → <code class="returnvalue">cidr</code>
+ </p>
+ <p>
+ Returns the network part of the address, zeroing out
+ whatever is to the right of the netmask.
+ (This is equivalent to casting the value to <code class="type">cidr</code>.)
+ </p>
+ <p>
+ <code class="literal">network(inet '192.168.1.5/24')</code>
+ → <code class="returnvalue">192.168.1.0/24</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.12.1.1.1" class="indexterm"></a>
+ <code class="function">set_masklen</code> ( <code class="type">inet</code>, <code class="type">integer</code> )
+ → <code class="returnvalue">inet</code>
+ </p>
+ <p>
+ Sets the netmask length for an <code class="type">inet</code> value.
+ The address part does not change.
+ </p>
+ <p>
+ <code class="literal">set_masklen(inet '192.168.1.5/24', 16)</code>
+ → <code class="returnvalue">192.168.1.5/16</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="function">set_masklen</code> ( <code class="type">cidr</code>, <code class="type">integer</code> )
+ → <code class="returnvalue">cidr</code>
+ </p>
+ <p>
+ Sets the netmask length for a <code class="type">cidr</code> value.
+ Address bits to the right of the new netmask are set to zero.
+ </p>
+ <p>
+ <code class="literal">set_masklen(cidr '192.168.1.0/24', 16)</code>
+ → <code class="returnvalue">192.168.0.0/16</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.5.2.2.14.1.1.1" class="indexterm"></a>
+ <code class="function">text</code> ( <code class="type">inet</code> )
+ → <code class="returnvalue">text</code>
+ </p>
+ <p>
+ Returns the unabbreviated IP address and netmask length as text.
+ (This has the same result as an explicit cast to <code class="type">text</code>.)
+ </p>
+ <p>
+ <code class="literal">text(inet '192.168.1.5')</code>
+ → <code class="returnvalue">192.168.1.5/32</code>
+ </p></td></tr></tbody></table></div></div><br class="table-break" /><div class="tip"><h3 class="title">Tip</h3><p>
+ The <code class="function">abbrev</code>, <code class="function">host</code>,
+ and <code class="function">text</code> functions are primarily intended to offer
+ alternative display formats for IP addresses.
+ </p></div><p>
+ The MAC address types, <code class="type">macaddr</code> and <code class="type">macaddr8</code>,
+ support the usual comparison operators shown in
+ <a class="xref" href="functions-comparison.html#FUNCTIONS-COMPARISON-OP-TABLE" title="Table 9.1. Comparison Operators">Table 9.1</a>
+ as well as the specialized functions shown in
+ <a class="xref" href="functions-net.html#MACADDR-FUNCTIONS-TABLE" title="Table 9.41. MAC Address Functions">Table 9.41</a>.
+ In addition, they support the bitwise logical operators
+ <code class="literal">~</code>, <code class="literal">&amp;</code> and <code class="literal">|</code>
+ (NOT, AND and OR), just as shown above for IP addresses.
+ </p><div class="table" id="MACADDR-FUNCTIONS-TABLE"><p class="title"><strong>Table 9.41. MAC Address Functions</strong></p><div class="table-contents"><table class="table" summary="MAC Address Functions" border="1"><colgroup><col /></colgroup><thead><tr><th class="func_table_entry"><p class="func_signature">
+ Function
+ </p>
+ <p>
+ Description
+ </p>
+ <p>
+ Example(s)
+ </p></th></tr></thead><tbody><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.8.2.2.1.1.1.1" class="indexterm"></a>
+ <code class="function">trunc</code> ( <code class="type">macaddr</code> )
+ → <code class="returnvalue">macaddr</code>
+ </p>
+ <p>
+ Sets the last 3 bytes of the address to zero. The remaining prefix
+ can be associated with a particular manufacturer (using data not
+ included in <span class="productname">PostgreSQL</span>).
+ </p>
+ <p>
+ <code class="literal">trunc(macaddr '12:34:56:78:90:ab')</code>
+ → <code class="returnvalue">12:34:56:00:00:00</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <code class="function">trunc</code> ( <code class="type">macaddr8</code> )
+ → <code class="returnvalue">macaddr8</code>
+ </p>
+ <p>
+ Sets the last 5 bytes of the address to zero. The remaining prefix
+ can be associated with a particular manufacturer (using data not
+ included in <span class="productname">PostgreSQL</span>).
+ </p>
+ <p>
+ <code class="literal">trunc(macaddr8 '12:34:56:78:90:ab:cd:ef')</code>
+ → <code class="returnvalue">12:34:56:00:00:00:00:00</code>
+ </p></td></tr><tr><td class="func_table_entry"><p class="func_signature">
+ <a id="id-1.5.8.18.8.2.2.3.1.1.1" class="indexterm"></a>
+ <code class="function">macaddr8_set7bit</code> ( <code class="type">macaddr8</code> )
+ → <code class="returnvalue">macaddr8</code>
+ </p>
+ <p>
+ Sets the 7th bit of the address to one, creating what is known as
+ modified EUI-64, for inclusion in an IPv6 address.
+ </p>
+ <p>
+ <code class="literal">macaddr8_set7bit(macaddr8 '00:34:56:ab:cd:ef')</code>
+ → <code class="returnvalue">02:34:56:ff:fe:ab:cd:ef</code>
+ </p></td></tr></tbody></table></div></div><br class="table-break" /></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-geometry.html" title="9.11. Geometric Functions and Operators">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-textsearch.html" title="9.13. Text Search Functions and Operators">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.11. Geometric Functions and Operators </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 15.4 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 9.13. Text Search Functions and Operators</td></tr></table></div></body></html> \ No newline at end of file