SQL从varchar获取值。我在redshift中有一个列元素作为varchar,如下所示
Id elements
1 [{"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"}]
如何在上面的该数组中选择值。 abc @ 123
答案 0 :(得分:0)
如果数据库为 MYSQL ,则应使用
json_extract
https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html
SELECT
ID,
json_extract(JSON_DATA, '$[0].value') AS MAIL
FROM JSON_TABLE;
结果:
ID MAIL
1 "abc@gmail.com"
演示:http://rextester.com/live/SQG30833
Redshift 应该使用 json_extract_path_text 函数 https://docs.aws.amazon.com/redshift/latest/dg/JSON_EXTRACT_PATH_TEXT.html