Re: Help Data-Types

From: Paul G. Brown <paul_geoffrey_brown_at_yahoo.com>
Date: 17 Aug 2002 23:33:01 -0700
Message-ID: <57da7b56.0208172233.4e0d53ab_at_posting.google.com>


"Dave" <dave_at_dmcomm.com> wrote in message news:<_Ug79.27$Tl4.10801289_at_news.incc.net>...
> Just a quick question on a datatypes since I'm a young novice.
> What the heck would an IP address go under? Text? Integer (long, short?) ??

  Depending on the DBMS you're using, you might like to implement this as a  user-defined type. This would permit you to a) enforce a degree of data  integrity that you can't get with the plain SQL types (like preventing  19.2168.1.1), b) reason about IP addresses (show me all IP addresses which  are under the class 'C' license 192.168.0.0, or all addresses reachable from  192.168.1.1 with a mask of 255.255.255.0).

   Internally, as other posters have pointed out, you have several alternatives.  You can use a 32-bit unsigned integer, or 15 character bytes. The former will be  more efficient in terms of space (though you will have to change it when IP V6  comes along) while the later has the advantage that it's easier to read  (although you will still have to change it when IP V6 comes along). My vote  would be for a byte array say 8 bytes in length with all of the initial bytes  set to 0 in the case of a 32-bit address. Waste a bit of space now saves you  much time later. If you're storing 10,000,000 IP addresses, you will add  320,000,000 bytes, or 320 Meg of storage, which is worth about $32. Fixing  this later will take you days.

    Just a suggestion. I'm sure your application developers will have  'C' or Java code to make sense out of IP addresses. Slap it into the DBMS  and see how you go.

    KR

                  Pb
Received on Sun Aug 18 2002 - 08:33:01 CEST

Original text of this message