Re: coalesce and nvl question - Mailing list pgsql-general

From Mike Mascari
Subject Re: coalesce and nvl question
Date
Msg-id 40D9B84A.6020009@mascari.com
Whole thread Raw
In response to coalesce and nvl question  (Simon Windsor <simon.windsor@cornfield.org.uk>)
Responses Re: coalesce and nvl question  (Simon Windsor <simon.windsor@cornfield.org.uk>)
List pgsql-general
Simon Windsor wrote:
> Hi
>
> Is there a standard postgres method of replacing empty strings.
>
> In Oracle, nvl handles nulls and empty strings, as does ifnull() in
> MySQL, but with postgres coalesce only handles null strings.
>
> If, not is the best solution to create a plpgsql function, ie
>
> CREATE FUNCTION isEmpty (character varying, character varying) RETURNS
> character varying

This all depends upon what you mean by handle. Do you want to treat
empty strings as NULL or NULL as empty strings? As you said, you can
treat NULL as empty strings using COALESCE:

SELECT COALESCE(x, '');

You can treat empty strings as NULL

SELECT NULLIF(x, '');

But I'd guess most on this list are wondering why you want to equate
an empty string with NULL, as they have two distinct meanings.
Oracle's treatment of empty strings as NULL is world-renowned for
being insane...

HTH

Mike Mascari



pgsql-general by date:

Previous
From: alltest1@covad.net
Date:
Subject: Re: simultaneous use of JDBC and libpq
Next
From: Simon Windsor
Date:
Subject: Re: coalesce and nvl question