无法在雪花中插入数组
Cannot insert Array in Snowflake
我有一个包含以下数据的 CSV 文件:
eno | phonelist | shots
"1" | "['1112223333','6195551234']" | "[[11,12]]"
我在snowflake中创建table的DDL语句如下:
CREATE TABLE ArrayTable (eno INTEGER, phonelist array,shots array);
我需要将 CSV 中的数据插入到 Snowflake table 中,我使用的方法是:
create or replace stage ArrayTable_stage file_format = (TYPE=CSV)
put file://ArrayTable @ArrayTable_stage auto_compress=true
copy into ArrayTable from @ArrayTable_stage/ArrayTable.gz
file_format = (TYPE=CSV FIELD_DELIMITER='|' FIELD_OPTIONALLY_ENCLOSED_BY='\"\')
但是当我尝试 运行 代码时,出现错误:
Copy to table failed: 100069 (22P02): Error parsing JSON:
('1112223333','6195551234')
如何解决?
FIELD_OPTIONALLY_ENCLOSED_BY='\"\'
基于你所拥有的那一行应该是 '\"'
select parse_json('[\'1112223333\',\'6195551234\']');
有效(反斜杠是为了绕过 sql 解析器)
但是你的输出有括号 (
,)
是不同的。
SELECT column2, TRY_PARSE_JSON(column2) as j
FROM @ArrayTable_stage/ArrayTable.gz
file_format = (TYPE=CSV FIELD_DELIMITER='|' FIELD_OPTIONALLY_ENCLOSED_BY='\"\')
WHERE j is null;
将显示哪些值无法解析..
如果您可能想要使用 to_array
来解析 column2 并因此将 table 插入到您的 SELECTED/transformed 数据中,那将无法自动转换
我有一个包含以下数据的 CSV 文件:
eno | phonelist | shots
"1" | "['1112223333','6195551234']" | "[[11,12]]"
我在snowflake中创建table的DDL语句如下:
CREATE TABLE ArrayTable (eno INTEGER, phonelist array,shots array);
我需要将 CSV 中的数据插入到 Snowflake table 中,我使用的方法是:
create or replace stage ArrayTable_stage file_format = (TYPE=CSV)
put file://ArrayTable @ArrayTable_stage auto_compress=true
copy into ArrayTable from @ArrayTable_stage/ArrayTable.gz
file_format = (TYPE=CSV FIELD_DELIMITER='|' FIELD_OPTIONALLY_ENCLOSED_BY='\"\')
但是当我尝试 运行 代码时,出现错误:
Copy to table failed: 100069 (22P02): Error parsing JSON: ('1112223333','6195551234')
如何解决?
FIELD_OPTIONALLY_ENCLOSED_BY='\"\'
基于你所拥有的那一行应该是 '\"'
select parse_json('[\'1112223333\',\'6195551234\']');
有效(反斜杠是为了绕过 sql 解析器)
但是你的输出有括号 (
,)
是不同的。
SELECT column2, TRY_PARSE_JSON(column2) as j
FROM @ArrayTable_stage/ArrayTable.gz
file_format = (TYPE=CSV FIELD_DELIMITER='|' FIELD_OPTIONALLY_ENCLOSED_BY='\"\')
WHERE j is null;
将显示哪些值无法解析..
如果您可能想要使用 to_array
来解析 column2 并因此将 table 插入到您的 SELECTED/transformed 数据中,那将无法自动转换