How to remove carriage returns and new lines in Postgresql?

前端 未结 4 738
太阳男子
太阳男子 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:16

    OP asked specifically about regexes since it would appear there's concern for a number of other characters as well as newlines, but for those just wanting strip out newlines, you don't even need to go to a regex. You can simply do:

    select replace(field,E'\n','');
    

    I think this is an SQL-standard behavior, so it should extend back to all but perhaps the very earliest versions of Postgres. The above tested fine for me in 9.4 and 9.2

提交回复
热议问题