简体   繁体   English

将 json 上传到雪花表中

[英]upload json into a snowflake table

I created an empty table in Snowflake.我在 Snowflake 中创建了一个空表。

在此处输入图像描述

I want to upload a json file into this table now.我现在想将 json 文件上传到此表中。 One possibility would be to add the entire json's value into the first row of the first column.一种可能性是将整个 json 的值添加到第一列的第一行。 However, when I upload the file from my computer, and select JSON as the type, I get this error但是,当我从我的计算机上传文件,并且 select JSON 作为类型时,我收到此错误

Unable to copy files into table.
SQL compilation error: JSON file format can produce one and only one column of type variant or object or array. Use CSV file format if you want to load more than one column.

What am I doing wrong?我究竟做错了什么? Am I supposed to use another file type instead?我应该改用其他文件类型吗?

Your column type is VARCHAR, as the error suggests, it needs to be of type variant or object or array if you want to load everything into one column from the JSON file.您的列类型是 VARCHAR,如错误所示,如果要将所有内容从 JSON 文件中加载到一列中,则它需要是变体或 object 或数组类型。

When you try to load data from a JSON file, it's expected to have only one variant column.当您尝试从 JSON 文件加载数据时,它应该只有一个变量列。 If you want to parse JSON and load the relevant fields to specific column, you need to use transformation feature of COPY command:如果要解析 JSON 并将相关字段加载到特定列,则需要使用 COPY 命令的转换功能:

copy into home_sales(city, state, zip, sale_date, price)
   from (select substr(parse_json($1):location.state_city,4), substr(parse_json($1):location.state_city,1,2),
                parse_json($1):location.zip, to_timestamp_ntz(parse_json($1):sale_date), parse_json($1):price
         from @sf_tut_stage/sales.json.gz t)

https://docs.snowflake.com/en/user-guide/script-data-load-transform-json.html https://docs.snowflake.com/en/user-guide/script-data-load-transform-json.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM