elements
[{"name":"email",
"value":"abc@gmail.com",
"nodeName":"INPUT",
"type":"text"},
{"name":"password",
"value":"*****",
"nodeName":"INPUT",
"type":"password"},
{"name":"checkbox",
"value":null,
"nodeName":"INPUT",
"type":"checkbox"}]
我在redshift中有这样的数据。如何从中提取值abc@gmail.com。此查询用于redshift。请帮助我的SQL。 Elements是列名,其值以[]开头。
我尝试过的查询: 选择 ID, json_extract_path_text(ELEMENTS,'name')作为name1 从表中
错误:[XX000] [500310] Amazon无效操作:JSON解析错误详细信息:------------------------------ -----------------错误:JSON解析错误代码:8 ...
答案 0 :(得分:0)
您可以在python中创建UDF,对于您创建的情况,请以适合的情况进行测试和编辑:
create or replace function f_py_json (jsonVar varchar(512),
jsonElemvarchar(10), occ integer)
returns varchar(512)
stable
as $$
import json
asJson = json.loads(jsonVar)
name_list = []
ret=str(asJson['elements'][occ][jsonElem])
return ret
$$ language plpythonu;
select f_py_json (id, 'value', 1) from test;
-- Input is {"elements":[{"name":"email","value":"abc@gmail.com"},{"name":"password","value":"*****"}]}