I have a requirement where I need to store an IP address in the table on a rails app. The format could be of IPv4 or IPv6. Currently I thought of storing them as ‘strings’. But is this a good approach. Could there be a better alternative here that could accomodate both?
Question posted in PostgreSQL
The official documentation can be found here.
The official documentation can be found here.
2
Answers
The appropriate PostgreSQL data type is clearly
inet
.While
inet
can also represent a subnet, it is also the appropriate type for a single IP address:string
works as well.