2

I have a location model with an attribute name. I want to trim(remove extra white spaces) the entire name attribute.

I tried to run

Location.TRIM(name)

But it isnt working. is the query wrong?

4
  • what is trim means? Commented May 18, 2016 at 9:18
  • to remove extra white spaces before after and in between Commented May 18, 2016 at 9:19
  • 1
    Why has this been marked as a duplicate of a question about stripping using Ruby, when this is clearly about the TRIM in sql? Commented May 18, 2016 at 12:19
  • @Ilya yes the question is about sql not string object. Could you remove the duplicate? In this case it update all the already saved Location in database with a sql method. Commented Jul 18, 2016 at 10:15

1 Answer 1

6

This is what you are looking for:

Location.update_all('name = TRIM(name)')

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks .. It worked! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.