1

For Example let's take The quick brown fox jumps over the lazy dog is the string.
In this string I need to append _ instead of spaces in between two words and append word tag: in front of each word.

i.e
tag:The_tag:quick_tag:brown_tag:fox_tag:jumps_tag:over_tag:the_tag:lazy_tag:dog

How to do this with Postgresql


I've tried

select replace('The quick brown fox jumps over the lazy dog', ' ', '_')
1
  • 1
    Have you consulted the fine manual? Commented Sep 16, 2014 at 6:09

1 Answer 1

1

Try,

SELECT 
     string_agg (b.tag,'_') as my_string
FROM (
      select  'tag:'||c.unnest||''  as tag 
      from (select unnest(string_to_array('The quick brown fox jumps over the lazy dog', ' '))) c
) b
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.