我在 athena 有一张具有这种结构的表
CREATE EXTERNAL TABLE `json_test`(
`col0` string ,
`col1` string ,
`col2` string ,
`col3` string ,
`col4` string ,
)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES (
'quoteChar'='\"',
'separatorChar'='\;')
像这样的 Json 字符串存储在“col4”中:
{'email': 'test_email@test_email.com', 'name': 'Andrew', 'surname': 'Test Test'}
我正在尝试进行 json_extract 查询:
SELECT json_extract(col4 , '$.email') as email FROM "default"."json_test"
但查询返回空值。
任何帮助,将不胜感激。
JSON 需要使用双引号 ("
) 用于包含值。
Compare:
presto> SELECT json_extract('{"email": "test_email@test_email.com", "name": "Andrew"}' , '$.email');
_col0
-----------------------------
"test_email@test_email.com"
and
presto> SELECT json_extract('{''email'': ''test_email@test_email.com'', ''name'': ''Andrew''}', '$.email');
_col0
-------
NULL
(Note: ''
SQL 里面的 varchar 字面意思是单个'
在构造的值中,因此这里的文字与问题中的格式相同。)
如果您的字符串值是“带单引号的 JSON”,您可以尝试使用以下命令修复它replace(string, search, replace) → varchar https://prestosql.io/docs/current/functions/string.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)