如何将JSON数据插入Snowflake Datawarehouse表的列中?

时间:2019-09-17 10:42:41

标签: snowflake-data-warehouse

我正在尝试编写SQL查询以将JSON数据上传到Snowflake数据库表中。

我编写的查询如下:

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查询在Snowflake数据库表中插入 JSON数据

1 个答案:

答案 0 :(得分:1)

我已经解决了:

查询可以写为:

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"
  }
}$$);