1

If I run the following query in Postgres or Snowflake, it will remove test from the end of the input string, even though the trimming text is best:

SELECT rtrim('rtrimtest', 'best');

See:

https://www.db-fiddle.com/f/kKYwe5tNLpVoacM2q1nJY7/0

However, I need to rtrim to only remove if the trimming text is an exact match. How do I do that?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
Saqib Ali
  • 3,953
  • 10
  • 55
  • 100

1 Answers1

3

The order of the characters doesn't matter for rtrim().
rtrim('rtrimtest', 'best') is the same as rtrim('rtrimtest', 'stbe')

On Postgres you can use regex_replace() for what you want to do:

regexp_replace('rtrimtest', 'best$', '');

Online example