How to remove carriage returns and new lines in Postgresql?

前端 未结 4 735
太阳男子
太阳男子 2020-12-07 17:41

All,

I am stuck again trying to get my data in a format that I need it in. I have a text field that looks like this.

\"deangelo 001 deangelo

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 18:02

    select regexp_replace(field, E'[\\n\\r\\u2028]+', ' ', 'g' )
    

    I had the same problem in my postgres d/b, but the newline in question wasn't the traditional ascii CRLF, it was a unicode line separator, character U2028. The above code snippet will capture that unicode variation as well.

    Update... although I've only ever encountered the aforementioned characters "in the wild", to follow lmichelbacher's advice to translate even more unicode newline-like characters, use this:

    select regexp_replace(field, E'[\\n\\r\\f\\u000B\\u0085\\u2028\\u2029]+', ' ', 'g' )
    

提交回复
热议问题