用 space 填充标点符号和其他非字母数字字符

Pad punctuation and other non alphanumeric characters with space

我想用 space || 替换所有非字母数字字符(如逗号) this_character || space。 所以执行查询后:

SELECT 'the quick, brown, fox jumps over the lazy dog'

我想获得以下输出:

the quick , brown , fox jumps over the lazy dog

您可以使用它在任何非字母数字字符(非白色 space)之前和之后插入一个 space,这与该字符中是否已经存在 space 无关位置:

SELECT regexp_replace('the quick, brown, fox jumps over the lazy dog', 
                      E'[^\w\s]', E' \& ', 'g')