Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 8BE7563237F for ; Fri, 11 Dec 2009 12:19:01 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 60867-04 for ; Fri, 11 Dec 2009 16:18:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from pyxis.powervt.com.ar (unknown [190.11.152.66]) by mail.postgresql.org (Postfix) with ESMTP id 9F17C6315D5 for ; Fri, 11 Dec 2009 12:18:50 -0400 (AST) Received: from pcfhevia ([186.124.123.2]) by pyxis.powervt.com.ar (IPGroup Mail Server) with ASMTP id 1OT48953; Fri, 11 Dec 2009 13:18:43 -0300 From: "Fernando Hevia" To: "'Oliveiros C,'" , References: Subject: Re: Is there any function to test for numeric ips? Date: Fri, 11 Dec 2009 13:20:03 -0300 Organization: IP-TEL Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 thread-index: Acp6e9GgFlceBlI8R9G0RypN/8nHqwAAO/Wg In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.157 tagged_above=-10 required=5 tests=AWL=0.242, BAYES_40=-0.185, RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200912/38 X-Sequence-Number: 33476 > -----Mensaje original----- > De: de Oliveiros C, > > Dear All, > > I have a table with host names and some happen to be numeric IPs. > > I would like to be able to filter out the later. > > Is there any function pre-defined in the system that can test > a particular text type value to see if it is a numeric ip? > > Something that returns true if applied to '192.168.1.1' but > false if applied to 'videos.sapo.pt' ? > > I considered NOT LIKE '%.%.%.%' but I'm affraid it will > filter out host names like 'www.google.com.br' > > I've realized that, for ex, inet 'x.x.x.x' will fail if the > input is not a numeric IP, is there any simple and direct way > to somewhat trap that error and convert it to a false value > that can be used in a WHERE clause? > You could filter IP out with a regular expression: select hostname as hosts_not_ip from table where hostname !~ '^[0-9]\.[0-9]\.[0-9]\.[0-9]$' Cheers, Fernando.