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.
Given your subsequent descriptions I'm confused as to your claim that you have a working SQL query when not used as part of a create materialized view. You should have found that running the same simple select by itself was always returning empty foo strings instead of bar.