Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,585 members, 7,827,174 topics. Date: Tuesday, 14 May 2024 at 08:25 AM

Best Data Type For Ip Address? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Best Data Type For Ip Address? (1229 Views)

How Do I Get Real IP Address / Invalid Field Data Type (error 3259) / Come Join Us!! Let's Build The Best Data Analytics Firm In Nigeria (2) (3) (4)

(1) (Reply) (Go Down)

Best Data Type For Ip Address? by imustsaymymindo: 9:27am On Sep 06, 2016
Good morning everyone,

I am designing a website which I need to use the IPv4 and IPv6 and order them in a database. Integer and floating point datatype seem not to be working because of the character "." in the IP addresses e.g 10.0.0.4.

Concatenating a prefix of "10.0.0" before the integer data type would not work too because IP address vary e.g there may be an ip address "10.20.0.4".

The only option was to use varchar which works perfectly but unfortunately varchar cannot order IP addresses the way it should be ordered.

When I googled, the data type to use, the BIT data type is said to be best but when I tried it although it worked but it changed the IP addresses to funny binary digits. I want to know maybe there is any other way around this. Thank you for your help.
Re: Best Data Type For Ip Address? by Codenister: 9:44am On Sep 06, 2016
I think your best option is still varchar.
And where do you want to sort the rows by IP? Is it I'm the dB or in your server side code?
If in the server code, you can retrieve the rows first and then order by IP in the code
Re: Best Data Type For Ip Address? by Javanian: 2:12pm On Sep 06, 2016
Varchar should work. Create an array of strings containing all the IP addresses and sort the array.
Re: Best Data Type For Ip Address? by talk2hb1(m): 9:52pm On Sep 06, 2016
varchar all the way, any value not meant for calculation should be saved as a string and char type undecided
Re: Best Data Type For Ip Address? by imustsaymymindo: 9:35am On Sep 09, 2016
Codenister:
I think your best option is still varchar.
And where do you want to sort the rows by IP? Is it I'm the dB or in your server side code?
If in the server code, you can retrieve the rows first and then order by IP in the code

In the server side code. User would assign new IP addresses. So, even if sorted in the database it would still get unsorted after new IP address inputs.
Re: Best Data Type For Ip Address? by imustsaymymindo: 9:37am On Sep 09, 2016
Javanian:
Varchar should work. Create an array of strings containing all the IP addresses and sort the array.

I guess I have no other choice then than to go with VarChar.

(1) (Reply)

Front End Developer And Backend Developer Needed. / Check Out This Brief Fact About Mobile App / Web Design Is Technically Not Programming

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.