LIST¶
Returns a list of files from one of the following Snowflake storage features:
-
暂存区
- 已命名的内部暂存区。
- 已命名的外部暂存区。
- 指定表的暂存区。
- 当前用户的暂存区。
LIST 可以缩写为 LS。
- See also:
语法
The syntax differs depending on whether you’re listing files in a stage or a Git repository clone.
For a stage¶
其中:
For a Git repository clone¶
其中:
必填参数
For a stage¶
internalStage | externalStage指定暂存数据文件的位置:
@[namespace.]int_stage_name[/path]Files are in the specified named internal stage. @[namespace.]ext_stage_name[/path]Files are in the specified named external stage. @[namespace.]%table_name[/path]Files are in the stage for the specified table. @~[/path]Files are in the stage for the current user. Where: - namespaceis the database and/or schema in which the named stage or table resides. It is optional if a database andschema are currently in use within the session; otherwise, it is required. - pathis an optional case-sensitive path for files in the cloud storage location (i.e. files have names that begin with acommon string) that limits access to a set of files. Paths are alternatively called prefixes or folders by different cloud storage services. If the stage name or path includes spaces or special characters, it must be enclosed in single quotes (e.g. '@"my stage"'for astage named "my stage").Specifying a path provides a scope for the LIST command, potentially reducing the amount of time required to run the command.
For a Git repository clone¶
repositoryCloneSpecifies the name of the repository clone and the branch, tag, or commit for which to list files.
@[namespace.]repository_clone/pathWhen listing files from a Git repository clone, the
pathis required and must begin with one of the following:branches/branch_nameList files from the specified branch. tags/tag_nameList files from the specified tag. commits/commit_hashList 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'Specifies a regular expression pattern for filtering files from the output. The command lists all files in the specified
pathand applies the regular expression pattern on each of the files found.
使用说明
-
To run this command with an external stage that uses a storage integration, you must use a role that has or inherits the USAGE privilege on the storage integration.
For more information, see Stage privileges.
- In contrast to named stages, table and user stages are not first-class database objects; rather, they are implicit stages associated with
the table/user. As such, they have no grantable privileges of their own:
- 您始终可以在用户暂存区列出文件(即不需要任何权限)。
- 要列出表暂存区中的文件,必须使用对表具有 OWNERSHIP 权限的角色。
- PATTERN supports the Java Pattern class (https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html) syntax.
输出
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¶
| Column | Data type | Description |
|---|---|---|
| name | VARCHAR | Name of the staged file |
| size | 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。 For more information, see Customer-managed encryption keys (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¶
| Column | Data type | Description |
|---|---|---|
| name | VARCHAR | Full file path with extension |
| size | 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¶
List all the files in the stage for the mytable table:
List all the files in the path1 path of the mystage named stage:
List the files that match a regular expression (i.e. all file names containing the string data_0) in the stage for the mytable
table:
List the files in the /analysis/ path of the my_csv_stage named stage that match a regular expression (i.e. all file names containing
the string data_0):
使用命令的缩写形式列出当前用户在暂存区中的所有文件:
For a Git repository clone¶
For examples, see View a list of repository files.