Emil Dumbazu
Emil Dumbazu

Reputation: 662

Edit rows where column contains strings+ empty spaces

I have some rows ( > 50.000) in my database which contains columns with strings + '\n'. I mean the records looks like this:

  abcd\n or \nabcd

Because of that sometimes my application does not work correctly. My question is: How could i update this rows with the correct value and eliminate '\n' spaces besides going to every row and update it manually ?

Upvotes: 0

Views: 68

Answers (3)

Magd Kudama
Magd Kudama

Reputation: 3469

Have you tried this?

UPDATE table SET column=REPLACE(column,'\\n','') WHERE column LIKE '%\\n' OR column LIKE '\\n%'

If you don't know where the new line is, simply:

UPDATE table SET column=REPLACE(column,'\\n','')

Upvotes: 0

juergen d
juergen d

Reputation: 204844

update your_table set somecolumn = replace(somecolumn, '\n', '')

Upvotes: 1

Paul Denisevich
Paul Denisevich

Reputation: 2414

update mytable SET title = TRIM(TRAILING '\n' FROM title)

Upvotes: 0

Related Questions