在Redshift中删除数字中的逗号

时间:2019-02-14 15:55:14

标签: sql amazon-redshift

我的数据包含100,000.89之类的数字,依此类推。我应该在Redshift中使用什么功能删除逗号并将其保持为100000.89?我们是在表的创建阶段还是在创建表后编写函数,然后对表进行后处理?

2 个答案:

答案 0 :(得分:2)

要从 text 列中删除逗号,请使用replace()

select replace(col, ',', '')
from t

编辑::对于null数据,请使用coalesce()

select coalesce(replace(col,',', ''), '')
from t

答案 1 :(得分:0)

我刚刚通过合并将所有列添加到了插入查询中,因为它们在某个地方都具有空值,并且就像一个魅力一样工作。如前所述,在非null字段中丢失数据的redshift错误令人误解:https://forums.aws.amazon.com/thread.jspa?threadID=119640 我也更改了复制命令,并添加了BLANKSASNULL。这工作了!感谢你的帮助。下面是我的命令:     insert into test.t_final (select coalesce(project_number) as project_number, coalesce(contract_po) as contract_po, coalesce(tracking_date) as tracking_date, (coalesce(replace(amount,',',''))) as amount, (coalesce(replace(tax,',',''))) as tax, (coalesce(replace(contract_value,',',''))) as contract_value, coalesce(comments) from test.t)