3

I want to do string replace in some data in pgsql database column. I tried

CASE
    WHEN (po.siteid IS NOT NULL) THEN replace('po.html_content', 'abcd', 'xxx')
        ELSE pc.html_content
 END  

I want to replace string in po.html_content column. But above code is not working. Query get the data in po.html_content column without replacing. Is my code is wrong or any idea...

1
  • You should show some the data that isn't being processed as you expect. The output of SELECT po.html_content, replace(po.html_content, 'abcd', 'xxx') FROM po showing some of the rows where it hasn't been replaced. Commented Sep 21, 2012 at 2:44

1 Answer 1

5

Don't enclosed the column name in a single quote, in that case, it is not a column anymore but a regular string.

CASE
    WHEN (po.siteid IS NOT NULL) THEN replace(po.html_content, 'abcd', 'xxx')
    ELSE pc.html_content
END 
Sign up to request clarification or add additional context in comments.

8 Comments

@miuranga can you post the whole query?
@miuranga do you want to update the row or only select the row?
@miuranga are you aware that REPLACE is case sensitive?
I think it is lower case. I get it from PGSQL doc postgresql.org/docs/9.1/static/functions-string.html
@miuranga no, that's not what i mean. for example you have value of HELLO world, if you try to execute this: replace('HELLO world', 'hello', 'not') the result is nothing since HELLO is not the same as hello
|

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.