host()

一个返回不带主机掩码的 IP 地址的函数

host() 是一个系统函数,返回 IP 地址,如果存在则去除网络掩码。

host() 函数已在 PostgreSQL 6.4 中添加。

用法

host ( inet ) → text

如果提供了无效值,则会引发 ERROR 错误。

变更历史

示例

host() 的基本用法示例

postgres=# SELECT host('192.168.1.2/32');
    host     
-------------
 192.168.1.2
(1 row)

如果提供的地址不包含网络掩码,则按原样返回

postgres=# SELECT host('192.168.1.2');
    host     
-------------
 192.168.1.2
(1 row)

如果提供了无效地址,则会引发 ERROR 错误

postgres=# SELECT host('192.168.1.2/99');
ERROR:  invalid input syntax for type inet: "192.168.1.2/99"
LINE 1: SELECT host('192.168.1.2/99');

分类

网络, 系统函数

另请参阅

text(), hostmask(), abbrev(), broadcast()

反馈

请在此处提交关于“host()”的任何评论、建议或更正。 here.