Re:A terrible schema from a clueless programmer
by ryandrake on Sunday November 07, 2021 @11:35AM
(#29140883)
Also, the "better" solution assumes IPv4 addresses and is not robust to a sudden requirements change to support IPv6. Best to keep IP address as a string unless you really, REALLY need to do something numerical with one or more of the octets.
[ Parent
| on HN ]
Re:A terrible schema from a clueless programmer
by pilif on Sunday November 07, 2021 @12:26PM
(#29141431)
Based on my experience I disagree. If there is a native data type that represents your data, you should really use it.
It will make sure that incorrect data is detected at the time of storage rather than at some indeterminate time in the future and it will likely be more efficient than arbitrary strings.
And in case of IP addresses, when you are using Postgres, it comes with an inet type that covers both ipv4 and ipv6, so you will be save from requirement changes
Re:A terrible schema from a clueless programmer
by johannes1234321 on Sunday November 07, 2021 @05:31PM
(#29144211)
Keeping IP addresses as string isn't trivial. You can write those in many ways. Even with IPv4. IPv6 just brings new variations. And when talking about migration to IPv6 you have to decide if you keep IPv4 Addresses as such or prefix with ::ffff:.
In the end you have to normalize anyways. Some databases have specific types. If not you have to pick a scheme and then ideally verify.