云数据库 GAUSSDB-网络地址函数和操作符:cidr和inet函数

时间:2024-01-23 20:08:42

cidr和inet函数

函数abbrev,host,text主要是为了提供可选的显示格式。

  • abbrev(inet)

    描述:缩写显示格式文本。

    返回类型:text

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT abbrev(inet '10.1.0.0/16') AS RESULT;
       result    
    -------------
     10.1.0.0/16
    (1 row)
    
  • abbrev(cidr)

    描述:缩写显示格式文本。

    返回类型:text

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT abbrev(cidr '10.1.0.0/16') AS RESULT;
     result  
    ---------
     10.1/16
    (1 row)
    
  • broadcast(inet)

    描述:网络广播地址。

    返回类型:inet

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT broadcast('192.168.1.5/24') AS RESULT;
          result      
    ------------------
     192.168.1.255/24
    (1 row)
    
  • family(inet)

    描述:抽取地址族,4为IPv4,6为IPv6。

    返回类型:int

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT family('::1') AS RESULT;
     result 
    --------
          6
    (1 row)
    
  • host(inet)

    描述:将主机地址类型抽出为文本。

    返回类型:text

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT host('192.168.1.5/24') AS RESULT;
       result    
    -------------
     192.168.1.5
    (1 row)
    
  • hostmask(inet)

    描述:为网络构造主机掩码。

    返回类型:inet

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT hostmask('192.168.23.20/30') AS RESULT;
     result  
    ---------
     0.0.0.3
    (1 row)
    
  • masklen(inet)

    描述:抽取子网掩码长度。

    返回类型:int

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT masklen('192.168.1.5/24') AS RESULT;
     result 
    --------
         24
    (1 row)
    
  • netmask(inet)

    描述:为网络构造子网掩码。

    返回类型:inet

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT netmask('192.168.1.5/24') AS RESULT;
        result     
    ---------------
     255.255.255.0
    (1 row)
    
  • network(inet)

    描述:抽取地址的网络部分。

    返回类型:cidr

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT network('192.168.1.5/24') AS RESULT;
         result     
    ----------------
     192.168.1.0/24
    (1 row)
    
  • set_masklen(inet, int)

    描述:为inet数值设置子网掩码长度。

    返回类型:inet

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT set_masklen('192.168.1.5/24', 16) AS RESULT;
         result     
    ----------------
     192.168.1.5/16
    (1 row)
    
  • set_masklen(cidr, int)

    描述:为cidr数值设置子网掩码长度。

    返回类型:cidr

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT set_masklen('192.168.1.0/24'::cidr, 16) AS RESULT;
         result     
    ----------------
     192.168.0.0/16
    (1 row)
    
  • text(inet)

    描述:把IP地址和掩码长度抽取为文本。

    返回类型:text

    示例:

    1
    2
    3
    4
    5
    postgres=# SELECT text(inet '192.168.1.5') AS RESULT;
         result     
    ----------------
     192.168.1.5/32
    (1 row)
    
support.huaweicloud.com/devg-v1-gaussdb/gaussdb_devg_0392.html