簡體   English   中英

有沒有辦法在 Redshift SQL 的多個列上分隔值,如“csv”字符串?

[英]Is there a way to separate values like "csv" strings on multiple columns on Redshift SQL?

例如:如果我select preferences from stores我會得到以下結果:

|preferences                                                           |
|----------------------------------------------------------------------|
|"debit_rate"=>"0.00", "credit_rate_1"=>"0.01", "credit_rate_2"=>"0.02"|
|"debit_rate"=>"0.03", "credit_rate_1"=>"0.04", "credit_rate_2"=>"0.05"|
|"debit_rate"=>"0.06", "credit_rate_1"=>"0.07", "credit_rate_2"=>"0.08"|
|"debit_rate"=>"0.09", "credit_rate_1"=>"0.10", "credit_rate_2"=>"0.11"|

我有辦法得到這個結果嗎?

debit_rate credit_rate_1 credit_rate_2
0.00 0.01 0.02
0.03 0.04 0.05
0.06 0.07 0.08
0.09 0.10 0.11

看起來你將這些字符串變成有效的 json 的變化很小。redshift 有 json 函數,可以更智能地解析這些字符串。 請參閱https://docs.aws.amazon.com/redshift/latest/dg/json-functions.html

如果您只是將“=>”更改為“:”並將整個內容括在花括號“{}”中,您應該在那里。

然后您可以將這些字符串轉換為 SUPER 類型並通過鍵值訪問數據。 請參閱:https://docs.aws.amazon.com/redshift/latest/dg/query-super.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM