PostgreSQL: Network Address Type – INET to IP Addresses (IPv4, IPv6)

PostgreSQL provides Network Address related data types for storing information like IP Addresses, Mac Addresses.

If you are planning to store the IP Address in PostgreSQL Database, you should declare the INET data type for that column.
Internally, It checks the format of data so you cannot insert invalid format of data.

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 portion is missing, the netmask is 32 for IPv4 and 128 for IPv6, so the value represents just a single host.

Small Demonstration:
Create a sample table:

Insert few sample Network related records:

Check the inserted data:

Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of