3 ms·
And vast. IME, people often underestimate what it can do. For example, if you need to store IP addresses in a DB, you can use the stdlib library ipaddress to va
by sgarland 2y ago
And vast. IME, people often underestimate what it can do. For example, if you need to store IP addresses in a DB, you can use the stdlib library ipaddress to validate them, then store them as an INT, casting it back to dotted-quad with Python if needed.
Also, of course, Postgres has a native inet type, which performs validation and other operations, storing a v4 in 7 bytes – not quite as good as 4 bytes for an INT, but much better than the maximum 16 bytes to store a dotted-quad as a VARCHAR. But if you’ve got MySQL (or anything else without a native type), this is a solid way to save space – and more importantly, memory – that can add up over hundreds of millions of rows (session information for a large SaaS product, for example).