From: | Rick Genter <rick(dot)genter(at)gmail(dot)com> |
---|---|
To: | rick(dot)genter(at)gmail(dot)com |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: In a view, how do I cause fields with possible NULLs to be treated as a blank string in a replace operation? |
Date: | 2011-06-27 16:59:40 |
Message-ID: | BANLkTin7uCqZ3JdmCDx2GSm2R3gRLvynGw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Either use '' as some_type, or use COALESCE(some_type, '').
On Mon, Jun 27, 2011 at 9:53 AM, Asfand Qazi (Sanger Institute) <
aq2(dot)sanger(at)gmail(dot)com> wrote:
> Hello,
>
> So I have am playing with a view to test the feasibility of a
> technique for storing some data.
>
> It basically goes something like this:
>
> CREATE VIEW formatted_table AS
> SELECT name,
> replace(some_template, '@', some_type) AS some_field
> FROM some_table;
>
> some_template is something like 'foo(at)bar' or 'foobar' (note the
> missing template character).
>
> some_type is a single letter like 'a' or 'b', or it can be NULL.
>
> The above view works fine for rows where some_type is a letter, and
> some_field ends up as 'fooabar' or whatever.
>
> However, when some_type is NULL, some_field ends up as NULL as well.
> I understand that this is expected behaviour, but how do I cause the
> view to treat a some_type of NULL as an empty string, so that
> some_field simply ends up as 'foobar'?
>
> Hope that was clear.
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
--
Rick Genter
rick(dot)genter(at)gmail(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Rob Sargent | 2011-06-27 17:23:07 | Re: glitch installing xml support in 9.1.beta2 |
Previous Message | Thom Brown | 2011-06-27 16:58:07 | Re: In a view, how do I cause fields with possible NULLs to be treated as a blank string in a replace operation? |