首页 > 解决方案 > 如何删除 PostgreSQL 中两个字符之间的字符串?

问题描述

我有一列包含地址信息。我想删除 和 之间的所有内容#,但也要删除#并离开,.

编辑:我还需要删除#.

这是我的专栏的样子:

ADDRESS
123 abc st. #123, city, zipcode
321 def road #321, city, zipcode

所以我的专栏看起来像这样:

ADDRESS
123 abc st., city, zipcode
321 def road, city, zipcode

标签: sqlpostgresql

解决方案


根据您的示例,您还希望删除之前的空格#

select str, regexp_replace(str, ' #[^,]+,', ',')
from (values ('321 def road #321, city, zipcode')) v(str)

推荐阅读