在 Amazon Redshift 中对单个列使用多个替换条件

Pra*_*ude 1 amazon-web-services amazon-redshift

我有一个表,其中金额列有 , 和 $ 符号,例如: $8,122.14 作为值。我想编写一个替换函数来一次性替换该列上的 $ 和 。有什么方法可以在 Redshift 的一次替换中写入多个条件吗?此外,这是数据后处理的一部分,我在替换这些值后将数据从阶段表插入最终表。

我尝试了代码中给出的采取1和2中列出的方法,但都失败了。

采取1:insert into db.stage_table select (coalesce(replace(logging_amount,'$',','),''))) aslogging_amount from db.table;

采取2:insert into db.stage_table select (coalesce(replace(logging_amount,'$',',')) aslogging_amount from db.table;

两人都失败了。

预期结果应该是单个语句中的替换函数。

Jon*_*ott 5

是的,你可以像这样嵌套替换语句

replace(replace(logging_amount,'$',''),',','')
Run Code Online (Sandbox Code Playgroud)

或者,如果您愿意,您可以使用正则表达式(就我个人而言,对于类似的事情,我认为嵌套替换更容易阅读。)