1

We are using Amazon-Redshift (PostgreSQL compliant syntax), we have the following string in a table

"TOTO;"
"TOTO;;"
"TOTO;;;"
"TOTO;;;;"

I would like to 'rtrim' double semicolons. So I would like to have

"TOTO;"
"TOTO"
"TOTO;"
"TOTO"

How to do it?

2 Answers2

2

Use the regexp_replace function with the (;;)*$ regex (any number of ;; followed by the end of the line):

SELECT regexp_replace(';;test;;;', '(;;)*$'), regexp_replace(';;test;;;;', '(;;)*$');
┌────────────────┬────────────────┐
│ regexp_replace │ regexp_replace │
├────────────────┼────────────────┤
│ ;;test;        │ ;;test         │
└────────────────┴────────────────┘
(1 row)
Marth
  • 23,920
  • 3
  • 60
  • 72
0
select replace('TODO;;;',';;','')

If I’ve made a bad assumption please comment and I’ll refocus my answer.

Rahul Gupta
  • 1,744
  • 2
  • 17
  • 28