Appearance
TEXT
Return an IPV4 or IPV6 address as a VARCHAR
character string.
TEXT(address [,integer])
where address
is an IPV4
or IPV6
column, expression, or constant. To specify a constant value for the address, use the IPV4
or IPV6
keyword.
Optionally, you can also specify a second integer
argument that represents the subnet mask (in the range of 0
to 32
for IPV4
or 0
to 128
for IPV6
).
For example:
premdb=# select hostip, text(hostip) from myhosts;
hostip | text
-------------+-------------
10.10.10.5 | 10.10.10.5
10.10.10.6 | 10.10.10.6
10.10.10.10 | 10.10.10.10
10.10.190.1 | 10.10.190.1
(4 rows)
premdb=# select hostip, text(hostip,16) from myhosts;
hostip | text
-------------+----------------
10.10.10.5 | 10.10.10.5/16
10.10.10.6 | 10.10.10.6/16
10.10.10.10 | 10.10.10.10/16
10.10.190.1 | 10.10.190.1/16
(4 rows)
premdb=# select text(ipv6 '2001:0db8:85a3:0000:0000:8a2e:0370:0000') from sys.const;
text
-----------------------------------------
2001:0db8:85a3:0000:0000:8a2e:0370:0000
(1 row)
premdb=# select text(ipv6 '2001:0db8:85a3:0000:0000:8a2e:0370:0000',128) from sys.const;
text
---------------------------------------------
2001:0db8:85a3:0000:0000:8a2e:0370:0000/128
(1 row)
Parent topic:Network Address Functions