1

I want to trim dot (.) from a column value. Just say string is "Mr." and I need to trim the dot from the string. I am expecting "Mr"

Lets say,

I have two fields in my table

 id   |  value
 1       Mr.
 2       Ms.
 11      Mr.
 12      Ms.

But while running below query, not getting as i expected.

 select trim(value, '.') from mytable

 value
 (text)
 Mr
 Ms
 Mr.
 Ms.

And noticed, for id 1 & 2 values is coming as expected. but for id 11 & 12 still the dot is coming. I really could not understand what is the issue.

(Using Postgresql 9.1)

2

I looked at the trim function and it removes the character from the beginning or the end of the string. I'd bet that the two where it's not working have spaces after the ".". Try trimming spaces off the end first then trim the "."

select trim(trim(value,' '), '.') from mytable
-1

I haven't used Postgresql any, but generally the syntax for trim follows: TRIM( [ [{LEADING | TRAILING | BOTH}] [removal_char] FROM ] target_string [COLLATE collation_name])

TRIM ('.' FROM 'STRING') would be more like what you'd want, think you have it reversed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.