我正在尝试编写一个SQL查询以将JSON数据上传到Snowflake DB Table。
我编写的查询如下所示:
insert into xyz_table(id, json_column) values (1, '{
"first_name": "John",
"last_name": "Corner",
"createddate": "2019-07-02T10:01:30+00:00",
"type": "Owner",
"country": {
"code": "US",
"name": "United States"
}
}');
我得到以下错误
SQL compilation error: Expression type does not match column data type, expecting VARIANT but got VARCHAR(182) for column CANONICAL_JSON
请让我知道,我们如何在雪花数据库表中使用 SQL 查询插入JSON 数据
我得到了它的解决方案:
查询可以写成:
insert into xyz_table(id, json_column) select 1, parse_json($${
"first_name": "John",
"last_name": "Corner",
"createddate": "2019-07-02T10:01:30+00:00",
"type": "Owner",
"country": {
"code": "US",
"name": "United States"
}
}$$);