0

I'd like to store ip2location database in a postgres database.

Guide on ip2location website suggests to store IP addresses that specify the range (ip_from and ip_to) in columns of type DECIMAL(39, 0).

I would have expected this to be of type INET.

Is there any advantage (e.g. in terms of speed, size, ...) to use DECIMAL(39, 0) instead of INET? Other than the ip2location database format contains IPs converted to integers already and one would have to convert that back to IP addresses obviously.

some-user
  • 3,888
  • 5
  • 19
  • 43
  • 1
    They probably come from a MySQL background and don't even know that there are database that support proper data types for IP addresses. I am storing those CSV files without problems in tables using `inet`. Or maybe PHP can not handle more advanced data types. –  Oct 17 '22 at 10:36
  • 1
    I would not discard that whoever wrote the article was binge-writing articles for all major DBMS and just copied the same information over and over. But both formats are much better than `VARCHAR`. – Álvaro González Oct 17 '22 at 10:37
  • Makes sense! Do you if there is any public code to load the CSV/do the conversion from integer to inet? – some-user Oct 17 '22 at 10:47

1 Answers1

0

The advantage of using the inet data type are

There is no advantage in using NUMERIC(39), except that it seems to be required by the software you want to use.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • 1
    I think some-user knows that. They are (rightfully) questioning the usage of the `decimal` type in that blog post. –  Oct 17 '22 at 10:44
  • @a_horse_with_no_name The question I saw was "Is there any advantage (e.g. in terms of speed, size, ...) to use DECIMAL(39, 0) instead of INET? " – Laurenz Albe Oct 17 '22 at 10:59