Re: [GENERAL] Comparing first 3 numbers of a IPv4 address?

2010-11-30 Thread Jasen Betts
On 2010-11-20, Alexander Farber alexander.far...@gmail.com wrote: 1) if I'd like to compare just the first 3 numbers of the IP address instead of the 4, how can I do it? (yes, I know about the A,B,C type of IPv4 networks...) have you heard of CIDR (what about IPV6, which I'm going to

[GENERAL] Comparing first 3 numbers of a IPv4 address?

2010-11-20 Thread Alexander Farber
Hello, I'm trying to program a PHP-script, where users can rate the goodness of the other players: create table pref_rep ( id varchar(32) references pref_users(id) check (id author), author varchar(32) references pref_users(id), author_ip

Re: [GENERAL] Comparing first 3 numbers of a IPv4 address?

2010-11-20 Thread Dmitriy Igrishin
Hey Alexander, 2010/11/20 Alexander Farber alexander.far...@gmail.com Hello, I'm trying to program a PHP-script, where users can rate the goodness of the other players: create table pref_rep ( id varchar(32) references pref_users(id) check (id author),

Re: [GENERAL] Comparing first 3 numbers of a IPv4 address?

2010-11-20 Thread Alexander Farber
I'm actually hoping to use inet (or cidr?) instead of strings... On 11/20/10, Dmitriy Igrishin dmit...@gmail.com wrote: Hey Alexander, 2010/11/20 Alexander Farber alexander.far...@gmail.com Hello, I'm trying to program a PHP-script, where users can rate the goodness of the other

Re: [GENERAL] Comparing first 3 numbers of a IPv4 address?

2010-11-20 Thread Dmitriy Igrishin
You can. host() just extract IP address from a value of inet type as text, string_to_array() converts this text to text[], and it makes it possible to compare with another text[]... I see no problem here. It works just fine. But probably there is another (better) solution... 2010/11/20 Alexander

Re: [GENERAL] Comparing first 3 numbers of a IPv4 address?

2010-11-20 Thread Alexander Farber
I think inet is a number internally, there is probably a more effective way... On 11/20/10, Dmitriy Igrishin dmit...@gmail.com wrote: You can. host() just extract IP address from a value of inet type as text, string_to_array() converts this text to text[], and it makes it possible to compare

Re: [GENERAL] Comparing first 3 numbers of a IPv4 address?

2010-11-20 Thread Dmitriy Igrishin
I will be glad to see the best solution, so if you find it please share. :-) But you want to compare IP addresses by 3 first parts. I don't see any function or operator at SQL level which allow to do it without converting to text. Probably, you can do it by manipulating a binary form (from

Re: [GENERAL] Comparing first 3 numbers of a IPv4 address?

2010-11-20 Thread Tom Lane
Alexander Farber alexander.far...@gmail.com writes: 1) if I'd like to compare just the first 3 numbers of the IP address instead of the 4, how can I do it? regression=# select network(set_masklen('123.45.67.42'::inet, 24)) = regression-# network(set_masklen('123.45.67.56'::inet, 24));

Re: [GENERAL] Comparing first 3 numbers of a IPv4 address?

2010-11-20 Thread Alexander Farber
Thank you. Or maybe also? (author_ip '255.255.255.0'::inet) = (_author_ip '255.255.255.0'::inet) On Sat, Nov 20, 2010 at 4:47 PM, Tom Lane t...@sss.pgh.pa.us wrote: Alexander Farber alexander.far...@gmail.com writes: 1) if I'd like to compare just the first 3 numbers of the IP address

Re: [GENERAL] Comparing first 3 numbers of a IPv4 address?

2010-11-20 Thread Dmitriy Igrishin
Hey Tom, Thanks for you solution! 2010/11/20 Tom Lane t...@sss.pgh.pa.us Alexander Farber alexander.far...@gmail.com writes: 1) if I'd like to compare just the first 3 numbers of the IP address instead of the 4, how can I do it? regression=# select