1

When I do a select like this

select
replace(replace(t.field,'{0}',t.parameter01), '{1}', t.parameter02)
from table t

I obtain a null result even if t.field contain text without any placeholders. Can somebody explain why this happens?

3
  • Add Postgres version. Who is e.parameter02?? Commented Nov 28, 2014 at 10:17
  • "PostgreSQL 9.3.3"", edited: it's a t parameter, a column of type char with no value Commented Nov 28, 2014 at 10:19
  • Please show us a complete example including sample data (insert into...) Commented Nov 28, 2014 at 10:40

1 Answer 1

1

I already figured out. If the third parameter of replace function is null, the result will be null although the second one doesn't match anything in the first one. An workaround is to replace the value of third parameter if it is null:

select 
replace(t.field, t.parameter01, coalesce(t.parameter02, ''))
from table t
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.