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

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



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

Предыдущее
От: "Fernando Hevia"
Дата:
Сообщение: Re: Is there any function to test for numeric ips?
Следующее
От: "Fernando Hevia"
Дата:
Сообщение: Re: Is there any function to test for numeric ips?