在 Redshift 中将 json 格式的列拆分为多列
Split json-format column into multiple columns in Redshift
select feature_column from table
{"reporting": true, "newsletters": false, "merchant_payment": false, "customer_feedback": true, "reserve_with_google": true, "new_closingtime_background": true, "merchant_logo_on_customer_email": true}
{"messaging": false, "yext_sync": false, "marketplace": false, "newsletters": false, "ranking_coach": false, "sms_reminders": false, "sms_newsletters": false, "merchant_payment": true, "customer_feedback": true, "birthday_reminders": false, "merchant_dashboard": true, "merchant_shiftplan": false, "reserve_with_google": false, "sms_customer_confirmation": false, "individual_email_from_name": true, "appointment_location_customer": false}
{"messaging": false, "newsletters": false, "merchant_payment": false, "birthday_reminders": false, "merchant_shiftplan": false, "double_opt_in_required": false, "new_closingtime_background": true, "facebook_instagram_integration": true, "show_all_branch_option_on_insights": true, "show_newsletter_non_subscriber_selection": false}
我不想将所有这些值存储在一列中,而是想将其转换为表格形式:
No. reporting newsletters merchant_payment customer_feedback
1 true false false true
2 false false true true
3 false false false false
据我所知,json ->> 功能在 Redshift 过时的 Postgres 版本中不可用。
我假设这些是 Redshift 中包含 json 的字符串(不是新的 Super 数据类型)。 Redshift 有几个 json 解析函数 - https://docs.aws.amazon.com/redshift/latest/dg/json-functions.html
我想你想使用 json_extract_path_text() 函数 - https://docs.aws.amazon.com/redshift/latest/dg/JSON_EXTRACT_PATH_TEXT.html
select json_extract_path_text(feature_column, '{reporting}') as reporting from ...
select feature_column from table
{"reporting": true, "newsletters": false, "merchant_payment": false, "customer_feedback": true, "reserve_with_google": true, "new_closingtime_background": true, "merchant_logo_on_customer_email": true}
{"messaging": false, "yext_sync": false, "marketplace": false, "newsletters": false, "ranking_coach": false, "sms_reminders": false, "sms_newsletters": false, "merchant_payment": true, "customer_feedback": true, "birthday_reminders": false, "merchant_dashboard": true, "merchant_shiftplan": false, "reserve_with_google": false, "sms_customer_confirmation": false, "individual_email_from_name": true, "appointment_location_customer": false}
{"messaging": false, "newsletters": false, "merchant_payment": false, "birthday_reminders": false, "merchant_shiftplan": false, "double_opt_in_required": false, "new_closingtime_background": true, "facebook_instagram_integration": true, "show_all_branch_option_on_insights": true, "show_newsletter_non_subscriber_selection": false}
我不想将所有这些值存储在一列中,而是想将其转换为表格形式:
No. reporting newsletters merchant_payment customer_feedback
1 true false false true
2 false false true true
3 false false false false
据我所知,json ->> 功能在 Redshift 过时的 Postgres 版本中不可用。
我假设这些是 Redshift 中包含 json 的字符串(不是新的 Super 数据类型)。 Redshift 有几个 json 解析函数 - https://docs.aws.amazon.com/redshift/latest/dg/json-functions.html
我想你想使用 json_extract_path_text() 函数 - https://docs.aws.amazon.com/redshift/latest/dg/JSON_EXTRACT_PATH_TEXT.html
select json_extract_path_text(feature_column, '{reporting}') as reporting from ...