In a view, how do I cause fields with possible NULLs to be treated as a blank string in a replace operation? - Mailing list pgsql-general

From Asfand Qazi (Sanger Institute)
Subject In a view, how do I cause fields with possible NULLs to be treated as a blank string in a replace operation?
Date
Msg-id BANLkTinr7YRJRwWGLKcCB9ahVFHVNof8ww@mail.gmail.com
Whole thread Raw
Responses Re: In a view, how do I cause fields with possible NULLs to be treated as a blank string in a replace operation?  (Thom Brown <thom@linux.com>)
Re: In a view, how do I cause fields with possible NULLs to be treated as a blank string in a replace operation?  (Rick Genter <rick.genter@gmail.com>)
List pgsql-general
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@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.

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Custom types as parameter in stored function
Next
From: Thom Brown
Date:
Subject: Re: In a view, how do I cause fields with possible NULLs to be treated as a blank string in a replace operation?