雪花,如何按特定顺序将数据卸载到雪花中的阶段(internal/external)?

Snowflake, How to unload the data in a specific order to the stage (internal/external) in snowflake?

我能够在 snowflake 中创建内部阶段并使用“COPY INTO”命令将 table 数据卸载到阶段。 table 中的记录数很大 (150K)。所以当我卸载到舞台上时,有 3 个文件以随机顺序创建。我想在阶段中按升序或降序保存数据,就像我们在 order by SQL 子句中使用的那样。我怎样才能做到这一点?

Example:
stage_0_0_0.csv -> 1 to 50000
stage_0_1_0.csv -> 50001 to 100000
stage_0_2_0.csv -> 100001 to 150001

不需要和上面完全一样,但应该是有顺序的。另外,如何将所有三个文件合并为一个文件。

非常感谢任何帮助。

谢谢大家

如果您只是使用 COPY INTO @stage from Table; 将数据卸载到 Stage 中,我们不保证数据的顺序。

但是,如果您在内部 select 中使用排序依据,如下所示,这将根据指定的列名称对数据进行排序

COPY INTO @stage FROM (select * from source_table order by column_name) FILE_FORMAT = (TYPE = CSVCOMPRESSION = GZIP FIELD_OPTIONALLY_ENCLOSED_BY = '"') INCLUDE_QUERY_ID = TRUE