Re: problem casting varchar to inet

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: problem casting varchar to inet
Date: 2005-07-22 12:50:58
Message-ID: 20050722125058.GA18703@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jul 22, 2005 at 02:20:31PM +0200, Roman Neuhauser wrote:
>
> select cast(coalesce(nullif('', trim(callingip)), '127.0.0.1') as inet)
>
> ERROR: invalid input syntax for type inet: ""
>
> what is it trying to tell me?

NULLIF returns the first argument if the arguments aren't equal,
so in this case if they aren't equal then NULLIF returns ''. COALESCE
then returns '' because its first argument isn't NULL, and that
value is then cast to inet and fails. Try reversing the order of
arguments to NULLIF:

select cast(coalesce(nullif(trim(callingip), ''), '127.0.0.1') as inet);

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Wells 2005-07-22 13:01:46 Copying bytea data out via pgsql
Previous Message Roman Neuhauser 2005-07-22 12:20:31 problem casting varchar to inet