Re: problem casting varchar to inet - Mailing list pgsql-general

From Michael Fuhr
Subject Re: problem casting varchar to inet
Date
Msg-id 20050722125058.GA18703@winnie.fuhr.org
Whole thread Raw
In response to problem casting varchar to inet  (Roman Neuhauser <neuhauser@sigpipe.cz>)
Responses Re: problem casting varchar to inet
List 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/

pgsql-general by date:

Previous
From: Roman Neuhauser
Date:
Subject: problem casting varchar to inet
Next
From: "John Wells"
Date:
Subject: Copying bytea data out via pgsql