如何在postgresql中将其他字符附加到字符串中

时间:2014-09-16 05:59:42

标签: sql postgresql postgresql-9.2

例如,我们将The quick brown fox jumps over the lazy dog作为字符串
在此字符串中,我需要在两个_之间追加spaces而不是words {1}}并在每个tag:前附加单词word


tag:The_tag:quick_tag:brown_tag:fox_tag:jumps_tag:over_tag:the_tag:lazy_tag:dog

如何使用Postgresql

执行此操作

我试过

select replace('The quick brown fox jumps over the lazy dog', ' ', '_')

1 个答案:

答案 0 :(得分:0)

尝试,

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