Re: Is there any function to test for numeric ips?

Поиск
Список
Период
Сортировка
От Oliveiros C,
Тема Re: Is there any function to test for numeric ips?
Дата
Msg-id 78D47C9DA237489C8622D26C75548FAA@marktestcr.marktest.pt
обсуждение исходный текст
Ответ на Is there any function to test for numeric ips?  ("Oliveiros C," <oliveiros.cristina@marktest.pt>)
Список pgsql-sql
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 



В списке pgsql-sql по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: Is there any function to test for numeric ips?
Следующее
От: Britt Piehler
Дата:
Сообщение: 8.3/8.4 SQL incompatibility?