Re: BUG #14693: create materialized view forces btrim

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: isb0459(at)gmail(dot)com
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14693: create materialized view forces btrim
Date: 2017-06-06 20:51:46
Message-ID: CAKFQuwbXXYVKnsr2G+y-WxJcWNnBzCn==7FoCVjCpn4PReZ9bQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Jun 6, 2017 at 1:25 PM, <isb0459(at)gmail(dot)com> wrote:

> I am trying to create a materialized view. I have a working SQL query that
> uses this expression: coalesce(trim(foo), bar). When I use that in the
> definition for create materialized view, Postgres force replaces the trim()
> call into a btrim() and breaks the query result. In my specific case, all
> the values become empty instead of yielding either the trimmed "foo" or the
> "bar" fields if trimmed "foo" is empty. Is there a way to make Postgres use
> the function trim as I require?
>

​COALESCE returns the first non-null value. The empty string is non-null
and so it will be returned.

try:

COALESCE(NULLIF(trim(foo), ''), bar);

David J.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Ian Boardman 2017-06-06 21:40:44 Re: BUG #14693: create materialized view forces btrim
Previous Message Tom Lane 2017-06-06 20:46:52 Re: BUG #14693: create materialized view forces btrim