Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 9CA46632CE7 for ; Fri, 11 Dec 2009 12:29:03 -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 78879-02 for ; Fri, 11 Dec 2009 16:28:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from spinlock.commandprompt.com (host-215.commandprompt.net [207.173.203.215]) by mail.postgresql.org (Postfix) with ESMTP id 3558A63303D for ; Fri, 11 Dec 2009 12:28:51 -0400 (AST) Received: from perhan.alvh.no-ip.org (190-95-19-31.bk17-dsl.surnet.cl [190.95.19.31]) by spinlock.commandprompt.com (Postfix) with ESMTPSA id 9D23B348043; Fri, 11 Dec 2009 08:28:49 -0800 (PST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 1F5896E36E; Fri, 11 Dec 2009 13:28:47 -0300 (CLST) Date: Fri, 11 Dec 2009 13:28:47 -0300 From: Alvaro Herrera To: "Oliveiros C," Cc: pgsql-sql@postgresql.org Subject: Re: Is there any function to test for numeric ips? Message-ID: <20091211162847.GD30833@alvh.no-ip.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.555 tagged_above=-10 required=5 tests=AWL=0.044, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/41 X-Sequence-Number: 33479 Oliveiros C, wrote: > 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? Yes, you can create a plpgsql function with an exception block; return false inside the exception, true otherwise. It looks something like begin perform $1::inet; return true; exception when invalid_something then return false end; I don't remember the exact syntax and the exception name but that should get you started. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support