We are using Amazon-Redshift (PostgreSQL compliant syntax), we have the following string in a table
我们正在使用Amazon-Redshift(符合PostgreSQL的语法),我们在表中有以下字符串
"TOTO;"
"TOTO;;"
"TOTO;;;"
"TOTO;;;;"
I would like to 'rtrim' double semicolons. So I would like to have
我想'rtrim'双分号。所以我想拥有
"TOTO;"
"TOTO"
"TOTO;"
"TOTO"
How to do it?
怎么做?
2 个解决方案
#1
2
Use the regexp_replace
function with the (;;)*$
regex (any number of ;;
followed by the end of the line):
将regexp_replace函数与(;;)* $ regex(任意数量的;;后跟行尾)一起使用:
SELECT regexp_replace(';;test;;;', '(;;)*$'), regexp_replace(';;test;;;;', '(;;)*$');
┌────────────────┬────────────────┐
│ regexp_replace │ regexp_replace │
├────────────────┼────────────────┤
│ ;;test; │ ;;test │
└────────────────┴────────────────┘
(1 row)
#2
0
select replace('TODO;;;',';;','')
If I’ve made a bad assumption please comment and I’ll refocus my answer.
如果我做了一个错误的假设请评论,我将重新调整我的答案。
#1
2
Use the regexp_replace
function with the (;;)*$
regex (any number of ;;
followed by the end of the line):
将regexp_replace函数与(;;)* $ regex(任意数量的;;后跟行尾)一起使用:
SELECT regexp_replace(';;test;;;', '(;;)*$'), regexp_replace(';;test;;;;', '(;;)*$');
┌────────────────┬────────────────┐
│ regexp_replace │ regexp_replace │
├────────────────┼────────────────┤
│ ;;test; │ ;;test │
└────────────────┴────────────────┘
(1 row)
#2
0
select replace('TODO;;;',';;','')
If I’ve made a bad assumption please comment and I’ll refocus my answer.
如果我做了一个错误的假设请评论,我将重新调整我的答案。