Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bulk insert Array in snowflake?

I am ingesting data in snowflake using the following command:

 copy into ArrayTable from (select $1, array_construct($2),array_construct($3) 

 from @ArrayTable_stage/ArrayTable-1-1.csv.gz) 
    
 file_format = (TYPE=CSV FIELD_DELIMITER='|' FIELD_OPTIONALLY_ENCLOSED_BY='\"')

But the array_construct() is not feasible for insertion of multiple tables since I have to manually specify columns which are of ARRAY datatype.

What is the alternative method for bulk insertion of Arrays in snowflake?

like image 477
linux Avatar asked Jun 19 '26 21:06

linux


2 Answers

I am not sure if this article would help or you have already seen it: https://community.snowflake.com/s/article/How-to-use-an-INSERT-statement-to-add-an-ARRAY-column-to-the-table

I am also following your question. Just to see what you are trying is achievable in snowflake dynamically or we always have to do it manually.

like image 120
kuldeep ghosh Avatar answered Jun 25 '26 00:06

kuldeep ghosh


Could you share some sample data of what your source/stage looks like.

But, creating the table with the columns as Variant datatype should work for what you are looking to do. You then should not need to do the array_construct()

https://docs.snowflake.com/en/sql-reference/data-types-semistructured.html

like image 29
Brandon Coleman Avatar answered Jun 25 '26 00:06

Brandon Coleman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!