Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 52EC9632CD3 for ; Fri, 11 Dec 2009 13:40:15 -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 89942-02 for ; Fri, 11 Dec 2009 17:40:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id 2BCE36329AA for ; Fri, 11 Dec 2009 13:40:03 -0400 (AST) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id 4R8T9NYR; Fri, 11 Dec 2009 17:40:01 -0000 Message-ID: <78D47C9DA237489C8622D26C75548FAA@marktestcr.marktest.pt> From: "Oliveiros C," To: "Alvaro Herrera" , Cc: , References: <20091211162847.GD30833@alvh.no-ip.org> Subject: Re: Is there any function to test for numeric ips? Date: Fri, 11 Dec 2009 17:40:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.385 tagged_above=-10 required=5 tests=AWL=0.354, BAYES_20=-0.74, STOX_REPLY_TYPE=0.001 X-Spam-Level: X-Archive-Number: 200912/42 X-Sequence-Number: 33480 Howdy, Alvaro, Fernando and Harald. Thanks a lot for your prompt reply. As I'm in a big hurry with this I used the regular expressions thing, it worked fine. But your solution looks good as well, Alvaro, the problem is my poor knowledge on pgplsql Definitely, I have to study in more depth subjects like pgplsql not to mention regular expressions Thanx a lot for your fast help, Best, Oliveiros ----- Original Message ----- From: "Alvaro Herrera" To: "Oliveiros C," Cc: Sent: Friday, December 11, 2009 4:28 PM Subject: Re: [SQL] Is there any function to test for numeric ips? > 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 > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql