[nflug] really dumb SQL question

Roelant Ossewaarde rao3 at buffalo.edu
Fri Dec 16 13:33:48 EST 2005


Don't know about mysql, but postgresql has a specific data type for  
IP-addresses (inet, cidr). That should solve all your problems, since  
most often sorting is then specific for that data-type.


On Dec 16, 2005, at 1:29 PM, John Nichel wrote:

> Eric Benoit wrote:
>
>> I know this is slightly off the topic of this list,
>> but I know there are some programmers out there ;)
>> I have a column labled ip address, it is varchar, oddly enough I  
>> input ...ip addresses in it. ha ha ha
>> Here's my question:
>> When I query the column and do an "order by ip_address ASC" the  
>> records won't ascend the way I want ex: 192.0.0.20, 192.0.0.112   
>> and so on
>> instead they ascend this way: 192.0.0.112, 192.0.0.20
>> I am guessing this is because ASC doesn't like the periods?
>> A finger pointed in some general direction would be great.
>>
>
> It is comparing them as a string.  I would change the field to an  
> INT, and store the IP's in long format.
>
> -- 
> John C. Nichel IV
> Programmer/System Admin (ÜberGeek)
> Dot Com Holdings of Buffalo
> 716.856.9675
> jnichel at dotcomholdingsofbuffalo.com
> _______________________________________________
> nflug mailing list
> nflug at nflug.org
> http://www.nflug.org/mailman/listinfo/nflug
>
>

_______________________________________________
nflug mailing list
nflug at nflug.org
http://www.nflug.org/mailman/listinfo/nflug



More information about the nflug mailing list