order by

Started by Kaj-Michael Langalmost 28 years ago4 messagesgeneral
Jump to latest
#1Kaj-Michael Lang
milang@tal.org

I have stored IP's in a table using a varchar(15) field. My problem is how
to make the order by list the IP's the correct order like:

192.168.1.1
192.168.1.6
192.168.1.10

now it sorts them like:

192.168.1.1
192.168.1.10
192.168.1.6

is it possible to get them sorted the right way ?

------------------------------------------------------------------------------
Kaj-Michael Lang milang@tal.org
Kaskentie 5 C9 http://www.tal.org/
20720 Turku ftp://ftp.tal.org/
FINLAND klang@abo.fi
------------------------------------------------------------------------------
Keyboard not found - press any key to continue
------------------------------------------------------------------------------

#2Oleg Broytmann
phd@comus.ru
In reply to: Kaj-Michael Lang (#1)
Re: [GENERAL] order by

Hello!

On Thu, 11 Jun 1998, Kaj-Michael Lang wrote:

I have stored IP's in a table using a varchar(15) field. My problem is how

Relcom (Russian Moscow ISP) developed IP type for Postgres:
http://relcom.eu.net/ipaddr.html

Oleg.
----
Oleg Broytmann http://members.tripod.com/~phd2/ phd2@earthling.net
Programmers don't die, they just GOSUB without RETURN.

#3dave madden
dhm@paradigm.webvision.com
In reply to: Kaj-Michael Lang (#1)
Re: [GENERAL] order by

=>From: Kaj-Michael Lang <milang@tal.org>
=>...
=>I have stored IP's in a table using a varchar(15) field. My problem is how
=>to make the order by list the IP's the correct order like:
=>
=>192.168.1.1
=>192.168.1.6
=>192.168.1.10
=>
=>now it sorts them like:
=>
=>192.168.1.1
=>192.168.1.10
=>192.168.1.6
=>
=>is it possible to get them sorted the right way ?

There may be a special function (or you could write one) to sort
numbers which are represented as varchars, but a better solution would
be to re-store the IP numbers as integers. This will also allow you
to work on them with netmasks and so forth. Convert them back to
A.B.C.D when you print them out.

d.

#4Bruce Momjian
bruce@momjian.us
In reply to: dave madden (#3)
Re: [GENERAL] order by

There may be a special function (or you could write one) to sort
numbers which are represented as varchars, but a better solution would
be to re-store the IP numbers as integers. This will also allow you
to work on them with netmasks and so forth. Convert them back to
A.B.C.D when you print them out.

See contrib/ip_and_mac.

-- 
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)