Postgres 9.11 网络地址类型函数和操作符
9.11. 网络地址类型函数和操作符
Table 9-31 显示了可以用于 cidr 和 inet 的操作符。 操作符 <<,<<= >>,和 >>= 用于计算子网包含:它们只考虑两个地址的网络部分,忽略任何主机部分, 然后判断其中一个网络部分是等于另外一个还是另外一个的子网。
Table 9-31. cidr 和 inet 操作符
| 操作符 | 描述 | 例子 |
|---|---|---|
| < | 小于吗 | inet '192.168.1.5' < inet '192.168.1.6' |
| <= | 小于或等于 | inet '192.168.1.5' <= inet '192.168.1.5' |
| = | 等于 | inet '192.168.1.5' = inet '192.168.1.5' |
| >= | 大于或等于 | inet '192.168.1.5' >= inet '192.168.1.5' |
| > | 大于 | inet '192.168.1.5' > inet '192.168.1.4' |
| <> | 不等于 | inet '192.168.1.5' <> inet '192.168.1.4' |
| << | 包含于 | inet '192.168.1.5' << inet '192.168.1/24' |
| <<= | 包含于或等于 | inet '192.168.1/24' <<= inet '192.168.1/24' |
| >> | 包含 | inet '192.168.1/24' >> inet '192.168.1.5' |
| >>= | 包含或等于 | inet '192.168.1/24' >>= inet '192.168.1/24' |
Table 9-32 显示了所有可以用于 cidr 和 inet 的函数。 函数 host,text 和 abbrev 主要是为了提供可选的显示格式用的。 你可以用普通的类型转换语法∶ inet(expression) 或者 colname::inet 把一个文本数域转换成inet。
Table 9-32. cidr 和 inet 函数
| 函数 | 返回类型 | 描述 | 例子 | 结果 |
|---|---|---|---|---|
| broadcast(inet) | inet | 网络广播地址 | broadcast('192.168.1.5/24') | 192.168.1.255/24 |
| host(inet) | text | 将主机地址类型抽出为文本 | host('192.168.1.5/24') | 192.168.1.5 |
| masklen(inet) | int | 抽取网络掩码长度 | masklen('192.168.1.5/24') | 24 |
| set_masklen(inet,int) | inet | 为inet数值设置网络掩码长度 | set_masklen('192.168.1.5/24',16) | 192.168.1.5/16 |
| netmask(inet) | inet | 为网络构造网络掩码 | netmask('192.168.1.5/24') | 255.255.255.0 |
| hostmask(inet) | inet | 为网络构造主机掩码 | hostmask('192.168.23.20/30') | 0.0.0.3 |
| network(inet) | cidr | 抽取地址的网络部分 | network('192.168.1.5/24') | 192.168.1.0/24 |
| text(inet) | text | 把 IP 地址和掩码长度抽取为文本 | text(inet '192.168.1.5') | 192.168.1.5/32 |
| abbrev(inet) | text | 抽取缩写显示为文本 | abbrev(cidr '10.1.0.0/16') | 10.1/16 |
| family(inet) | int | 抽取地址族 4 for IPv4, 6 for IPv6 | family('::1') | 6 |
Table 9-33 显示了可以用于 macaddr 类型的函数。 函数 trunc(macaddr) 返回一个 MAC 地址,该地址的最后三个字节设置为零。 这样可以把剩下的前缀与一个制造商相关联。 源程序目录 contrib/mac 里有一些用于创建和维护这样的 关联表的工具。
Table 9-33. macaddr 函数
| 函数 | 返回类型 | 描述 | 例子 | 结果 |
|---|---|---|---|---|
| trunc(macaddr) | macaddr | 把后三个字节置为零 | trunc(macaddr '12:34:56:78:90:ab') | 12:34:56:00:00:00 |
macaddr 类型还支持标准关系操作符 (>,<=,等) 用于词法排序。
8.8. Network Address Types
PostgreSQL offers data types to store IPv4, IPv6, and MAC addresses, as shown in Table 8-17. It is preferable to use these types instead of plain text types to store network addresses, because these types offer input error checking and several specialized operators and functions (see Section 9.11).
Table 8-17. Network Address Types
| Name | Storage Size | Description |
|---|---|---|
| cidr | 12 or 24 bytes | IPv4 and IPv6 networks |
| inet | 12 or 24 bytes | IPv4 and IPv6 hosts and networks |
| macaddr | 6 bytes | MAC addresses |
When sorting inet or cidr data types, IPv4 addresses will always sort before IPv6 addresses, including IPv4 addresses encapsulated or mapped into IPv6 addresses, such as ::10.2.3.4 or ::ffff:10.4.3.2.
8.8.1. inet
The inet type holds an IPv4 or IPv6 host address, and optionally the identity of the subnet it is in, all in one field. The subnet identity is represented by stating how many bits of the host address represent the network address (the "netmask"). If the netmask is 32 and the address is IPv4, then the value does not indicate a subnet, only a single host. In IPv6, the address length is 128 bits, so 128 bits specify a unique host address. Note that if you want to accept networks only, you should use the cidr type rather than inet.
The input format for this type is address/y where address is an IPv4 or IPv6 address and y is the number of bits in the netmask. If the /y part is left off, then the netmask is 32 for IPv4 and 128 for IPv6, so the value represents just a single host. On display, the /y portion is suppressed if the netmask specifies a single host.
8.8.2. cidr
The cidr type holds an IPv4 or IPv6 network specification. Input and output formats follow Classless Internet Domain Routing conventions. The format for specifying networks is address/y where address is the network represented as an IPv4 or IPv6 address, and y is the number of bits in the netmask. If y is omitted, it is calculated using assumptions from the older classful network numbering system, except that it will be at least large enough to include all of the octets written in the input. It is an error to specify a network address that has bits set to the right of the specified netmask.
Table 8-18 shows some examples.
Table 8-18. cidr Type Input Examples
| cidr Input | cidr Output | abbrev(cidr) |
|---|---|---|
| 192.168.100.128/25 | 192.168.100.128/25 | 192.168.100.128/25 |
| 192.168/24 | 192.168.0.0/24 | 192.168.0/24 |
| 192.168/25 | 192.168.0.0/25 | 192.168.0.0/25 |
| 192.168.1 | 192.168.1.0/24 | 192.168.1/24 |
| 192.168 | 192.168.0.0/24 | 192.168.0/24 |
| 128.1 | 128.1.0.0/16 | 128.1/16 |
| 128 | 128.0.0.0/16 | 128.0/16 |
| 128.1.2 | 128.1.2.0/24 | 128.1.2/24 |
| 10.1.2 | 10.1.2.0/24 | 10.1.2/24 |
| 10.1 | 10.1.0.0/16 | 10.1/16 |
| 10 | 10.0.0.0/8 | 10/8 |
| 10.1.2.3/32 | 10.1.2.3/32 | 10.1.2.3/32 |
| 2001:4f8:3:ba::/64 | 2001:4f8:3:ba::/64 | 2001:4f8:3:ba::/64 |
| 2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128 | 2001:4f8:3:ba:2e0:81ff:fe22:d1f1/128 | 2001:4f8:3:ba:2e0:81ff:fe22:d1f1 |
| ::ffff:1.2.3.0/120 | ::ffff:1.2.3.0/120 | ::ffff:1.2.3/120 |
| ::ffff:1.2.3.0/128 | ::ffff:1.2.3.0/128 | ::ffff:1.2.3.0/128 |
8.8.3. inet vs. cidr
The essential difference between inet and cidr data types is that inet accepts values with nonzero bits to the right of the netmask, whereas cidr does not.
Tip: If you do not like the output format for inet or cidr values, try the functions
host,text, andabbrev.
8.8.4. macaddr
The 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
| '08002b:010203' |
| '08002b-010203' |
| '0800.2b01.0203' |
| '08-00-2b-01-02-03' |
| '08:00:2b:01:02:03' |
Postgres 9.11 网络地址类型函数和操作符的更多相关文章
- C++11用于计算函数对象返回类型的统一方法
[C++11用于计算函数对象返回类型的统一方法] 模板 std::result_of 被TR1 引进且被 C++11 所采纳,可允许我们决定和使用一个仿函数其回返值的类别.底下,CalculusVer ...
- scala快速学习笔记(一):变量函数,操作符,基本类型
为了用spark,先学下scala. 参考教程:http://meetfp.com/zh/scala-basic doc查询:http://docs.scala-lang.org 其它资料:http: ...
- [转] PostgreSQL学习手册(函数和操作符)
一.逻辑操作符: 常用的逻辑操作符有:AND.OR和NOT.其语义与其它编程语言中的逻辑操作符完全相同. 二.比较操作符: 下面是PostgreSQL中提供的比较操作符列表: 操作符 描述 < ...
- 【足迹C++primer】48、函数引用操作符
函数引用操作符 struct absInt { int operator()(int val) const { cout<<val<<"<->!!!&qu ...
- PostgreSQL学习手册(五) 函数和操作符
PostgreSQL学习手册(五) 函数和操作符 一.逻辑操作符: 常用的逻辑操作符有:AND.OR和NOT.其语义与其它编程语言中的逻辑操作符完全相同. 二.比较操作符: 下面是Post ...
- C++基础 (4) 第四天 this指针 全局函数和成员函数 友元 操作符重载
1static强化练习-仓库进货和出货 #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; c ...
- PostgreSql字符串函数和操作符
本节描述了用于检查和操作字符串数值的函数和操作符.在这个环境中的字符串包括所有 character, character varying, text 类型的值.除非另外说明,所有下面列出的函数都可以处 ...
- c++11 类默认函数的控制:"=default" 和 "=delete"函数
c++11 类默认函数的控制:"=default" 和 "=delete"函数 #define _CRT_SECURE_NO_WARNINGS #include ...
- c++11 类默认函数的控制:"=default" 和 "=delete"函数 void fun() = default; void fun()=delete;
转自:lsgxeva #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #includ ...
随机推荐
- JavaScript高级程序设计学习笔记第八章--BOM
1.间歇调用和超时调用: 超时调用:需要使用 window 对象的 setTimeout()方法,它接受两个参数:要执行的代码和以毫秒表示的时间(即在执行代码前需要等待多少毫秒).其中,第一个参数可以 ...
- CodeForces 1131G. Most Dangerous Shark
题目简述:从左到右依次有$n \leq 10^7$个Domino骨牌,高度为$h_i$,手动推倒他的花费为$c_i$.每个骨牌之间的距离为$1$.一个骨牌可以被向左或者向右推倒.当第$i$个骨牌被推倒 ...
- Python绘制正态分布曲线
使用Python绘制正态分布曲线,借助matplotlib绘图工具: \[ f(x) = \dfrac{1}{\sqrt{2\pi}\sigma}\exp(-\dfrac{(x-\mu)^2}{2 ...
- 盛大游戏技术总监徐峥:Unity引擎使用的三种方式
在5月13日Unite 2017 案例分享专场上,盛大游戏技术总监徐峥分享了使用Unity引擎的三种方式,以下为详细内容: 大家好,我先简单介绍一下我自己,我是盛大游戏的技术总监徐峥.我今天想分享的主 ...
- ue4 改c++类名
http://blog.csdn.net/chinahaerbin/article/details/50855135
- untiy AnimationEvent添加返回参数
using UnityEngine; using System.Collections; public class Try : MonoBehaviour { public class Action ...
- CF1119F Niyaz and Small Degrees【treedp+堆】
如果枚举d来dp,那么就是设f[u][0/1]为u点不断/断掉和父亲的边,然后优先选取f[v][1]+w(u,v)<=f[v][0]的,如果断掉这些度数还是多就用一个堆维护剩下的按f[v][1] ...
- Java基础--基本规则、语法
一.关键字.保留字.标识符.常量.变量 1.关键字:使用某种语言赋予特殊含义的单词. 2.保留字:没有赋予特殊含义,但以后可能会使用的单词. 3.标识符:自定义的单词,以数字.字母.下划线以及$符组成 ...
- 剖析js中的数据类型
首先说一下八种常见的数据类型:五种简单的数据类型和三种复杂数据类型. 简单数据类型 Number:数字类型 String:字符串 Boolean:布尔类型 Undefined:未定义 Null:空 复 ...
- (转)COBBLER无人值守安装
COBBLER无人值守安装 说在最前面的话 在看Cobbler之前请大家先看一下Kickstart无人值守安装,了解一下Cobbler的实现原理.但是Cobbler是独立的,不需要先安装Kicksta ...