pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
CIdr query qestion
3+ messages / 3 participants
[nested] [flat]

* CIdr query qestion
@ 2007-07-10 07:36 Michele Petrazzo - Unipex srl <michele.petrazzo@unipex.it>
  2007-07-10 09:00 ` Re: CIdr query qestion Jesper K. Pedersen <jkp@solnet.homeip.net>
  2007-07-10 09:16 ` Re: CIdr query qestion Michael Fuhr <mike@fuhr.org>
  0 siblings, 2 replies; 3+ messages in thread

From: Michele Petrazzo - Unipex srl @ 2007-07-10 07:36 UTC (permalink / raw)
  To: pgsql-sql

Hi ml!

A question about cidr query. I'm tring to use the various cidr functions
to exclude a A sub class, but I don't understand how use it:

SELECT count(ip_addr), ip_addr from wi_log_network where ip_addr !=
network('10.10.0.0/16', 16) group by (ip_addr);

it don't exclude the 10.10 ! Tried also the abbr or set_masklen keyword,
but the same. How do it?

P.s. Tried the >>, but it only include the values that I want to
exclude! (And I don't found how to do the opposite!)

Thanks,
Michele

Attachments:

  smime.p7s (application/x-pkcs7-signature, 3.2K) download

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: CIdr query qestion
  2007-07-10 07:36 CIdr query qestion Michele Petrazzo - Unipex srl <michele.petrazzo@unipex.it>
@ 2007-07-10 09:00 ` Jesper K. Pedersen <jkp@solnet.homeip.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Jesper K. Pedersen @ 2007-07-10 09:00 UTC (permalink / raw)
  To: pgsql-sql

On Tue, 10 Jul 2007 09:36:49 +0200
Michele Petrazzo - Unipex srl <michele.petrazzo@unipex.it> wrote:

> Hi ml!
> 
> A question about cidr query. I'm tring to use the various cidr
> functions to exclude a A sub class, but I don't understand how use it:
> 
> SELECT count(ip_addr), ip_addr from wi_log_network where ip_addr !=
> network('10.10.0.0/16', 16) group by (ip_addr);
> 
> it don't exclude the 10.10 ! Tried also the abbr or set_masklen
> keyword, but the same. How do it?
> 
> P.s. Tried the >>, but it only include the values that I want to
> exclude! (And I don't found how to do the opposite!)
> 


Couldnt you do a :

select count(ip_addr), ip_addr from wi_log_network where not (ip_addr
<< '10.10.0.0/16') group by (ip_addr);


Best regards 
Jesper K. Pedersen



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: CIdr query qestion
  2007-07-10 07:36 CIdr query qestion Michele Petrazzo - Unipex srl <michele.petrazzo@unipex.it>
@ 2007-07-10 09:16 ` Michael Fuhr <mike@fuhr.org>
  1 sibling, 0 replies; 3+ messages in thread

From: Michael Fuhr @ 2007-07-10 09:16 UTC (permalink / raw)
  To: Michele Petrazzo - Unipex srl <michele.petrazzo@unipex.it>; +Cc: pgsql-sql

On Tue, Jul 10, 2007 at 09:36:49AM +0200, Michele Petrazzo - Unipex srl wrote:
> A question about cidr query. I'm tring to use the various cidr functions
> to exclude a A sub class, but I don't understand how use it:
> 
> SELECT count(ip_addr), ip_addr from wi_log_network where ip_addr !=
> network('10.10.0.0/16', 16) group by (ip_addr);
> 
> it don't exclude the 10.10 ! Tried also the abbr or set_masklen keyword,
> but the same. How do it?

Please post the actual query you're running.  The above fails with

ERROR:  function network("unknown", integer) does not exist

Does the following help?

CREATE TABLE test (id integer PRIMARY KEY, ip_addr inet NOT NULL);
INSERT INTO test (id, ip_addr) VALUES (1, '10.2.3.4');
INSERT INTO test (id, ip_addr) VALUES (2, '10.10.5.6');

SELECT id,
       ip_addr,
       set_masklen(ip_addr, 16),
       network(set_masklen(ip_addr, 16)),
       network(set_masklen(ip_addr, 16)) = '10.10.0.0/16',
       '10.10.0.0/16'::cidr >> ip_addr,
       NOT '10.10.0.0/16'::cidr >> ip_addr
  FROM test;

 id |  ip_addr  | set_masklen  |   network    | ?column? | ?column? | ?column? 
----+-----------+--------------+--------------+----------+----------+----------
  1 | 10.2.3.4  | 10.2.3.4/16  | 10.2.0.0/16  | f        | f        | t
  2 | 10.10.5.6 | 10.10.5.6/16 | 10.10.0.0/16 | t        | t        | f
(2 rows)

> P.s. Tried the >>, but it only include the values that I want to
> exclude! (And I don't found how to do the opposite!)

You can use NOT to negate a boolean expression; see above.

-- 
Michael Fuhr



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2007-07-10 09:16 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-07-10 07:36 CIdr query qestion Michele Petrazzo - Unipex srl <michele.petrazzo@unipex.it>
2007-07-10 09:00 ` Jesper K. Pedersen <jkp@solnet.homeip.net>
2007-07-10 09:16 ` Michael Fuhr <mike@fuhr.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox