Snowflake cloud data platform 将CSV数据加载到雪花表
在尝试将以下数据加载到SnowFlake表中时,列会拆分为多个列,因为它是CSV文件 列数据:Snowflake cloud data platform 将CSV数据加载到雪花表,snowflake-cloud-data-platform,Snowflake Cloud Data Platform,在尝试将以下数据加载到SnowFlake表中时,列会拆分为多个列,因为它是CSV文件 列数据: {"Department":"Mens Wear","Departmentid":"10.1;20.1","customername":"john4","class":"tops wear","subclass":&quo
{"Department":"Mens
Wear","Departmentid":"10.1;20.1","customername":"john4","class":"tops wear","subclass":"sweat shirts","product":"North & Face 2 Bangle","style":"Sweat shirt hoodie - Large - Black"}
是否有其他方法将数据加载到单个列中。最好的解决方案是在CSV文件中使用不同的分隔符而不是逗号。如果不可能,则可以使用不存在的分隔符接收数据,将整行作为一列,然后对其进行解析。当然,它不会像本机加载那样有效:
cat test.csv
1,2020-10-12,Gokhan,{"Department":"Mens Wear","Departmentid":"10.1;20.1","customername":"john4","class":"tops wear","subclass":"sweat shirts","product":"North & Face 2 Bangle","style":"Sweat shirt hoodie - Large - Black"}
create file format csvfile type=csv FIELD_DELIMITER='NONEXISTENT';
select $1 from @my_stage (file_format => csvfile );
create table testtable( id number, d1 date, name varchar, v variant );
copy into testtable from (
select
split( split($1,',{')[0], ',' )[0],
split( split($1,',{')[0], ',' )[1],
split( split($1,',{')[0], ',' )[2],
parse_json( '{' || split($1,',{')[1] )
from @my_stage (file_format => csvfile )
);
select * from testtable;
+----+------------+--------+-----------------------------------------------------------------+
| ID | D1 | NAME | V |
+----+------------+--------+-----------------------------------------------------------------+
| 1 | 2020-10-12 | Gokhan | { "Department": "Mens Wear", "Departmentid": "10.1;20.1", ... } |
+----+------------+--------+-----------------------------------------------------------------+
您的文件格式/复制到语句是什么?您可以创建一个带有变量列的表,并插入解析为JSON的数据。正如@Marcel所说,请分享整行数据,而不仅仅是一列数据——以及你是如何加载的