Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redshift: how to remove all newline characters in a field

I am wondering how I can remove all newline characters in Redshift from a field. I tried something like this:

replace(replace(body, '\n', ' '), '\r', ' ')

and

regexp_replace(body, '[\n\r]+', ' ')

But it didn't work. Please share if you know how to do this.

like image 723
kee Avatar asked Jan 07 '23 15:01

kee


2 Answers

Use chr(10) instead of \n

example:

select replace(CONCAT('Text 1' , chr(10), 'Text 2'), chr(10), '-') as txt
like image 129
Mani Deep Avatar answered Jan 19 '23 05:01

Mani Deep


This should help

regexp_replace(column, '\r|\n', '')

like image 24
Gaurav Avatar answered Jan 19 '23 06:01

Gaurav