尝试使用varchar
使用json从列中提取文本值,但在模式上运行时在雪花上获得无效参数错误。这个json有一些不同的结构,这是我以前看到的。
试过这些来取出文字:
changes:comment:new_value::varchar
changes:new_value::varchar
changes:comment::varchar
JSON看起来像这样:
{
"comment":
{
"new_value": "Hello there. Welcome to our facility.",
"old_value": ""
}
}
希望提取此列中的数据,以便输出显示:
Hello there. Welcome to our facility.
你无法从VARCHAR
中提取字段。如果您的字符串是JSON,则必须将其转换为VARIANT
类型,例如通过PARSE_JSON
功能。
示例如下:
create or replace table x(v varchar) as select * from values('{
"comment":
{
"new_value": "Hello there. Welcome to our facility.",
"old_value": ""
}
}');
select v, parse_json(v):comment.new_value::varchar from x;
--------------------------------------------------------------+------------------------------------------+
V | PARSE_JSON(V):COMMENT.NEW_VALUE::VARCHAR |
--------------------------------------------------------------+------------------------------------------+
{ | Hello there. Welcome to our facility. |
"comment": | |
{ | |
"new_value": "Hello there. Welcome to our facility.", | |
"old_value": "" | |
} | |
} | |
--------------------------------------------------------------+------------------------------------------+