我怎样才能改变“Odenwaldstr”。到“Odenwald Strasse”。
在德语中,人们可以这样或者这样写。对于我的项目,我需要以一种方式。意味着以“... str”结尾的所有街道名称。需要以“... Strasse”结束
答案 0 :(得分:1)
你需要非常小心,以免在单词的其他部分替换str
。假设str
位于列的末尾,我建议采用更安全的方法:
select (case when col like '%str.' then substr(col, length(col) - 4) || ' Strasse'
when col like '%str' then substr(col, length(col) - 3) || ' Strasse'
else col
end) as ColWithStrasse
答案 1 :(得分:0)
请在构建的replace方法中使用postgres,因为REGEXP_REPLACE而不是REPLACE方法将替换字符串的所有部分
SELECT REGEXP_REPLACE(column_name,'.(str?)$', 'Strasse');
而不是
SELECT REPLACE(column_name , 'str', ' Strasse')
在此处查看有关postgres字符串处理的更多信息 http://www.postgresql.org/docs/current/static/functions-string.html