Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id BEA2F632CE7 for ; Fri, 11 Dec 2009 12:24:18 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 99845-08 for ; Fri, 11 Dec 2009 16:24:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id 01430632CD3 for ; Fri, 11 Dec 2009 12:24:10 -0400 (AST) Received: from list by lo.gmane.org with local (Exim 4.50) id 1NJ8Ho-00021y-RV for pgsql-sql@postgresql.org; Fri, 11 Dec 2009 17:24:08 +0100 Received: from srv.protecting.net ([212.126.218.242]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Dec 2009 17:24:08 +0100 Received: from hari.fuchs by srv.protecting.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Dec 2009 17:24:08 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Harald Fuchs Subject: Re: Is there any function to test for numeric ips? Date: Fri, 11 Dec 2009 17:23:47 +0100 Lines: 28 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: srv.protecting.net X-Archive: encrypt User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:x+Mv3D3P4eY5G9c2EL5qiihGTbE= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/39 X-Sequence-Number: 33477 In article , "Oliveiros C," writes: > 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 use a regular expression match: SELECT host FROM t1 WHERE host ~ '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'