From: | Mike Mascari <mascarm(at)mascari(dot)com> |
---|---|
To: | Simon Windsor <simon(dot)windsor(at)cornfield(dot)org(dot)uk> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: coalesce and nvl question |
Date: | 2004-06-23 17:05:14 |
Message-ID: | 40D9B84A.6020009@mascari.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Simon Windsor | 2004-06-23 18:10:05 | Re: coalesce and nvl question |
Previous Message | DeJuan Jackson | 2004-06-23 16:48:10 | Re: User Privileges using dblink |