I have loaded data into table using copy into from stage file(CSV).
+--------------------------------------------------------------------+--------+
| STRING | RESULT |
+--------------------------------------------------------------------+--------+
| hhhhrerererereNRD\r\n\r\nthe 193how (test) testtest peo\r\n\r\n | 30.00 |
+--------------------------------------------------------------------+--------+
my select query expected output is like below:
+---------------------------------------------------------+--------+
| STRING | RESULT |
+---------------------------------------------------------+--------+
| hhhhrerererereNRDthe 193how (test) testtest peo | 30.00 |
+---------------------------------------------------------+--------+
I have tried following option like :
SELECT
regexp_replace(STRING,'\r\n\r\n','')
FROM test;
It is not producing expected output.
step one, reproduce "the problem"
gives:
which shows that \r and \n in the input is parsed by the SQL parser to mean newline and carriage return, thus we need to escape them to get them into the output:
what is worth noting is that in the output panel we can see the first is actually have new lines shown to be present and effecting stuff:
so now we can do the replacements we want
we can see using the replace you have, does have impact:
so if you output looks like the second row, then you don't have a cariage return but
\&\rin your string. Thus to match that we need to match\\ror\\nBUT regexp also has a parser, so the input needs to be\\\\rto match\&\rnow in the lower row we see
\nor\rremoved, now to match ether, we need to put an Grouping and OR in the regexp:so if you really want to remove embedded newlines and carriage returns, AND escaped, you will want more OR clauses:
and now we can see both have correctly be stripped out.