Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order by in Postgresql to sort IP address?

I wish to sort a list of IP address.

Is there any function in Postgresql to use with the order by like INET_ATON in MySql ?

My current IP is on string format.

like image 988
user301089 Avatar asked Apr 15 '10 15:04

user301089


1 Answers

You can order your IP address column IP_Address with something like this:

SELECT * FROM MyTable ORDER BY inet(IP_Address)

See the documnetation for further reference.

Edit:

This is actually not a function but a type cast to the postgres integrated type for IP addresses.

like image 124
Frank Bollack Avatar answered Nov 14 '22 21:11

Frank Bollack