LIST

Returns a list of files from one of the following Snowflake storage features:

LIST 可以缩写为 LS。

另请参阅:

REMOVE, PUT, COPY INTO <table>, COPY INTO <location>, GET

语法

The syntax differs depending on whether you're listing files in a stage or a Git repository clone.

For a stage

LIST { internalStage | externalStage } [ PATTERN = '<regex_pattern>' ]
Copy

其中:

internalStage ::=
    @[<namespace>.]<int_stage_name>[/<path>]
  | @[<namespace>.]%<table_name>[/<path>]
  | @~[/<path>]
Copy
externalStage ::=
  @[<namespace>.]<ext_stage_name>[/<path>]
Copy

For a Git repository clone

LIST repositoryClone [ PATTERN = '<regex_pattern>' ]
Copy

其中:

repositoryClone ::=
  @[<namespace>.]<repository_clone>/<path>
Copy

必填参数

For a stage

internalStage | externalStage

指定暂存数据文件的位置:

@[namespace.]int_stage_name[/path]

文件位于指定的已命名内部暂存区。

@[namespace.]ext_stage_name[/path]

文件位于指定的命名外部暂存区。

@[namespace.]%table_name[/path]

文件位于指定表的暂存区中。

@~[/path]

文件位于当前用户的暂存区。

其中:

  • namespace 是已命名暂存区或表所在的数据库和/或架构。如果数据库和架构当前正在用户会话中使用,则此参数为 选填;否则,为必填。

  • path 是云存储位置中文件的可选路径(即文件的名称以公共字符串开头),且区分大小写,用于限制对一组文件的访问。不同的云存储服务也可以将路径称为 前缀文件夹

备注

如果暂存区名称包含空格或特殊字符,则必须将其放在单引号内(例如,对于命名为 "my stage" 的暂存区,格式为 '@"my stage"')。

小技巧

指定路径可为 LIST 命令提供范围,从而减少运行命令所需的潜在时间。

For a Git repository clone

repositoryClone

Specifies the name of the repository clone and the branch, tag, or commit for which to list files.

@[namespace.]repository_clone/path

When listing files from a Git repository clone, the path is required and must begin with one of the following:

branches/branch_name

List files from the specified branch.

tags/tag_name

List files from the specified tag.

commits/commit_hash

List files from the commit specified by the commit hash.

备注

If the repository clone name or path includes spaces or special characters, it must be enclosed in single quotes (for example, '@"my repository"' for a repository named "my repository").

可选参数

PATTERN = 'regex_pattern'

指定用于筛选输出文件的正则表达式模式。该命令列出指定 path 中的所有文件,并对找到的每个文件应用正则表达式模式。

使用说明

  • 要使用依赖存储集成的外部暂存区运行此命令,您必须使用具有或继承存储集成 USAGE 权限的角色。

    有关更多信息,请参阅 暂存区权限

  • 与已命名暂存区相比,表暂存区和用户暂存区不是第一类数据库对象;相反,它们是与表/用户关联的隐式暂存区。因此,它们本身没有可授予的权限:

输出

The command returns columns in the following tables. Column values differ depending on whether you're using LIST with a stage or Git repository clone.

For a stage

数据类型

描述

name

VARCHAR

Name of the staged file

大小

NUMBER

Size of the file compressed (in bytes)

md5

VARCHAR

MD5 列存储暂存数据文件内容的 MD5 哈希值。

对于具有默认加密的内部暂存区 (SNOWFLAKE_FULL),在上传过程中,源文件使用随机密钥进行加密,其生成的 MD5 摘要始终与原始本地文件不同。

Amazon S3 暂存区通过 S3 eTag 字段报告该值,而该字段可能不是文件内容的 MD5 哈希值。

对于使用客户管理的加密密钥 (CMEK) 的 Google Cloud 暂存区,md5 预计为 NULL。

有关更多信息,请参阅 客户管理的加密密钥 (https://cloud.google.com/storage/docs/encryption/customer-managed-keys)。

sha1

VARCHAR

Not used

last_modified

VARCHAR

Timestamp when the file was last updated in the stage

For a Git repository clone

数据类型

描述

name

VARCHAR

Full file path with extension

大小

NUMBER

Size of the file compressed (in bytes)

md5

VARCHAR

Not used

sha1

VARCHAR

A unique identifier generated by applying the SHA-1 hashing algorithm to the file's contents. It is used by Git to track and reference the exact version of a file in the repository, and can be used to detect changes in the file's content.

last_modified

VARCHAR

Timestamp of the commit associated with the listed files. This does not necessarily indicate when the file content was last changed.

示例

For a stage

列出 mytable 表暂存区中的所有文件:

LIST @%mytable;
Copy

列出已命名暂存区 mystage 路径 path1 中的所有文件:

LIST @mystage/path1;
Copy

列出在 mytable 表的暂存区中与正则表达式匹配的文件(即包含字符串 data_0 的所有文件名):

LIST @%mytable PATTERN='.*data_0.*';
Copy

列出已命名暂存区 my_csv_stage 路径 /analysis/ 中与正则表达式匹配的文件(即包含字符串 data_0 的所有文件名):

LIST @my_csv_stage/analysis/ PATTERN='.*data_0.*';
Copy

使用命令的缩写形式列出当前用户在暂存区中的所有文件:

LS @~;
Copy

For a Git repository clone

For examples, see 查看存储库文件列表.

语言: 中文