本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
若要將JSON資料轉換為 Athena 資料類型,請使用CAST
.
注意
在此範例中,若要將字串表示為 JSON-coded,請以JSON
關鍵字開頭並使用單引號,例如 JSON
'12345'
WITH dataset AS (
SELECT
CAST(JSON '"HELLO ATHENA"' AS VARCHAR) AS hello_msg,
CAST(JSON '12345' AS INTEGER) AS some_int,
CAST(JSON '{"a":1,"b":2}' AS MAP(VARCHAR, INTEGER)) AS some_map
)
SELECT * FROM dataset
此查詢會傳回:
+-------------------------------------+
| hello_msg | some_int | some_map |
+-------------------------------------+
| HELLO ATHENA | 12345 | {a:1,b:2} |
+-------------------------------------+