SQL - 在字段末尾删除双分号

时间:2017-09-22 15:12:53

标签: sql regex string amazon-redshift character-trimming

我们正在使用Amazon-Redshift(符合PostgreSQL的语法),我们在表格中有以下字符串

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

我想' rtrim'双分号。所以我想

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

怎么做?

2 个答案:

答案 0 :(得分:2)

public extension UIColor { convenience init?(hex: String) { var red: CGFloat = 0.0 var green: CGFloat = 0.0 var blue: CGFloat = 0.0 var alpha: CGFloat = 1.0 let hex = hex.replacingOccurrences(of: "^#", with: "", options: .regularExpression) guard let hexValue = UInt64(hex, radix: 16) else { print("invalid hex string") return nil } switch (hex.count) { case 3: red = CGFloat((hexValue & 0xF00) >> 8) / 15.0 green = CGFloat((hexValue & 0x0F0) >> 4) / 15.0 blue = CGFloat(hexValue & 0x00F) / 15.0 case 4: red = CGFloat((hexValue & 0xF000) >> 12) / 15.0 green = CGFloat((hexValue & 0x0F00) >> 8) / 15.0 blue = CGFloat((hexValue & 0x00F0) >> 4) / 15.0 alpha = CGFloat(hexValue & 0x000F) / 15.0 case 6: red = CGFloat((hexValue & 0xFF0000) >> 16) / 255.0 green = CGFloat((hexValue & 0x00FF00) >> 8) / 255.0 blue = CGFloat(hexValue & 0x0000FF) / 255.0 case 8: red = CGFloat((hexValue & 0xFF000000) >> 24) / 255.0 green = CGFloat((hexValue & 0x00FF0000) >> 16) / 255.0 blue = CGFloat((hexValue & 0x0000FF00) >> 8) / 255.0 alpha = CGFloat(hexValue & 0x000000FF) / 255.0 default: print("Invalid RGB string, number of characters after '#' should be either 3, 4, 6 or 8", terminator: "") return nil } self.init(red: red, green: green, blue: blue, alpha: alpha) } } 函数与regexp_replace正则表达式(任意数量的(;;)*$后跟行尾):

;;

答案 1 :(得分:0)

select replace('TODO;;;',';;','')

如果我做了一个错误的假设请发表评论,我会重新调整我的答案。