Reputation: 45
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?
Upvotes: 1
Views: 503
Reputation: 1802
select replace('TODO;;;',';;','')
If I’ve made a bad assumption please comment and I’ll refocus my answer.
Upvotes: 0
Reputation: 24812
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)
Upvotes: 2