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.
Create a sample table:
CREATE TABLE tbl_TestNetworkDataType
Insert few sample Network related records:
INSERT INTO tbl_TestNetworkDataType
Check the inserted data:
SELECT *FROM tbl_TestNetworkDataType;
id | myipaddress | mymacaddress
1 | 10.0.2.8/16 | 08:00:8b:01:08:03
2 | 192.168.1.0/24 | 08:00:2b:01:02:03
3 | 220.127.116.11 | 08:00:2b:01:02:03
4 | 18.104.22.168/16 | 08:00:2b:01:02:03
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.