Returns a list of files from one of the following Snowflake storage features:
Stage
Named internal
Named external
For a specified table
For the current user
LIST can be abbreviated to LS.
- See also:
Syntax¶
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>' ]
Where:
internalStage ::= @[<namespace>.]<int_stage_name>[/<path>] | @[<namespace>.]%<table_name>[/<path>] | @~[/<path>]externalStage ::= @[<namespace>.]<ext_stage_name>[/<path>]
For a Git repository clone¶
LIST repositoryClone [ PATTERN = '<regex_pattern>' ]
Where:
repositoryClone ::= @[<namespace>.]<repository_clone>/<path>
Required parameters¶
For a stage¶
internalStage | externalStageSpecifies the location where the data files are staged:
Where:
namespaceis the database and/or schema in which the named stage or table resides. It is optional if a database and schema 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 a common string) that limits access to a set of files. Paths are alternatively called prefixes or folders by different cloud storage services.
Note
If the stage name or path includes spaces or special characters, it must be enclosed in single quotes (e.g.
'@"my stage"'for a stage named"my stage").Tip
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:Note
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").
Optional parameters¶
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.
Usage notes¶
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:
You can always list files in your user stage (i.e. no privileges are required).
To list files in a table stage, you must use a role that has the OWNERSHIP privilege on the table.
PATTERN supports the Java Pattern class syntax.
Output¶
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¶
For a Git repository clone¶
Examples¶
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 @%mytable PATTERN='.*data_0.*';
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):
LIST @my_csv_stage/analysis/ PATTERN='.*data_0.*';
Use the abbreviated form of the command to list all the files in the stage for the current user:
For a Git repository clone¶
For examples, see View a list of repository files.