Unload into Microsoft Azure¶
如果您已经拥有 Microsoft Azure 账户并使用 Azure 容器存储和管理文件,则可以在从 Snowflake 表卸载数据时使用现有容器和文件夹路径。本主题介绍如何使用 COPY 命令来将数据从表卸载到 Azure 容器。然后,您可以将卸载的数据文件下载到本地文件系统。
Snowflake 支持以下类型的 Blob 存储账户:
- Blob 存储
- Data Lake Storage Gen2
- 常规用途 v1
- General-purpose v2
Snowflake does not support Data Lake Storage Gen1.
如下图所示,将数据卸载到 Azure 容器的操作分为两个步骤:
- Step 1:
Use the COPY INTO <location> command to copy the data from the Snowflake database table into one or more files in an Azure container bucket. In the command, you specify a named external stage object that references the Azure container (recommended) or you can choose to unload directly to the container by specifying the URI and security credentials (if required) for the container.
无论您使用哪种方法,如果您手动或在脚本中执行命令,此步骤都需要运行一个当前虚拟仓库的会话。仓库提供计算资源来从表中写入行。
- Step 2:
使用 Microsoft 提供的接口/工具从 Azure 容器下载文件。

Tip
The instructions in this set of topics assume you have read File formats to unload data and have created a named file format, if desired.
Before you begin, you may also want to read Data unloading considerations for best practices, tips, and other guidance.
Allow the Azure Virtual Network subnet IDs¶
If an Azure administrator in your organization has not explicitly granted Snowflake access to your Azure storage account, you can do so now. Follow the steps in Allow the VNet subnet IDs in the data loading configuration instructions.
Configure an Azure container for unloading data¶
For Snowflake to write to an Azure container, you must configure access to your storage account. For instructions, see Configure an Azure container for loading data. Note that we provide a single set of instructions, which call out the specific permissions required for data loading or unloading operations.
Unload data into an external stage¶
外部暂存区是指定的数据库对象,为数据卸载提供最大程度的灵活性。因为它们是数据库对象,所以可以将指定暂存区的权限授予任何角色。
You can create an external named stage using either Snowsight or SQL:
- Snowsight:
In the navigation menu, select Catalog » Database Explorer » <db_name> » Stages » Create
- SQL:
Create a named stage¶
The following example creates an external stage named my_ext_unload_stage with a container named mycontainer and a folder path named unload. The stage references the named file format object called my_csv_unload_format that was created in File formats to unload data:
Note
Use the blob.core.windows.net endpoint for all supported types of Azure blob storage accounts, including Data Lake Storage Gen2.
请注意,本示例中使用的 AZURE_SAS_TOKEN 和 MASTER_KEY 的值仅用于说明目的。
Unload data to the named stage¶
-
Use the COPY INTO <location> command to unload data from a table into an Azure container using the external stage.
The following example uses the
my_ext_unload_stagestage to unload all the rows in themytabletable into one or more files into the Azure container. Ad1filename prefix is applied to the files: -
使用 Azure 提供的工具从容器中检索对象(即命令生成的文件)。
Unload data directly into an Azure container¶
- Use the COPY INTO <location> command to unload data from a table directly into a specified Azure container. This option works well for ad hoc unloading, when you aren’t planning regular data unloading with the same table and container parameters.
必须为 Azure 容器指定 URI,并在 COPY 命令中指定用于访问容器的安全凭据。
The following example unloads all the rows in the mytable table into one or more files with the folder path prefix unload/ in an Azure container.
This example references a storage integration created using CREATE STORAGE INTEGRATION by an account administrator (i.e. a user with the ACCOUNTADMIN role) or a role with the global CREATE INTEGRATION privilege. A storage integration allows users to avoid supplying credentials to access a private storage location:
- 使用 Azure 控制台(或同等客户端应用程序)从容器中检索对象(即命令生成的文件)。