From: Oliveiros C, <oliveiros.cristina@marktest.pt>
To: Alvaro Herrera <alvherre@commandprompt.com>
To: hari.fuchs@gmail.com
Cc: pgsql-sql@postgresql.org
Cc: fhevia@ip-tel.com.ar
Subject: Re: Is there any function to test for numeric ips?
Date: Fri, 11 Dec 2009 17:40:00 -0000
Message-ID: <78D47C9DA237489C8622D26C75548FAA@marktestcr.marktest.pt> (raw)
References: <E94D918326D044C69895D829038E31B2@marktestcr.marktest.pt>
<20091211162847.GD30833@alvh.no-ip.org>
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" <alvherre@commandprompt.com>
To: "Oliveiros C," <oliveiros.cristina@marktest.pt>
Cc: <pgsql-sql@postgresql.org>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: oliveiros.cristina@marktest.pt, alvherre@commandprompt.com, hari.fuchs@gmail.com, fhevia@ip-tel.com.ar
Subject: Re: Is there any function to test for numeric ips?
In-Reply-To: <78D47C9DA237489C8622D26C75548FAA@marktestcr.marktest.pt>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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