LIST¶
Returns a list of files that have been staged (i.e. uploaded from a local file system or unloaded from a table) in one of the following Snowflake stages:
Named internal stage.
Named external stage.
Stage for a specified table.
Stage for the current user.
LIST can be abbreviated to LS.
- See also:
Syntax¶
LIST { internalStage | externalStage } [ PATTERN = '<regex_pattern>' ]
Where:
internalStage ::= @[<namespace>.]<int_stage_name>[/<path>] | @[<namespace>.]%<table_name>[/<path>] | @~[/<path>]externalStage ::= @[<namespace>.]<ext_stage_name>[/<path>]
Required parameters¶
internalStage | externalStage
Specifies the location where the data files are staged:
@[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:
namespace
is 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.path
is 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.
Optional parameters¶
PATTERN = 'regex_pattern'
Specifies a regular expression pattern for filtering files from the output. The command lists all files in the specified
path
and applies the regular expression pattern on each of the files found.
Usage notes¶
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.
Output¶
The command returns the following columns:
Column |
Data Type |
Description |
---|---|---|
name |
VARCHAR |
Name of the staged file. |
size |
NUMBER |
Size of the file compressed (in bytes). |
md5 |
VARCHAR |
The MD5 column stores an MD5 hash of the contents of the staged data file. For internal stages with default encryption ( |
last_modified |
VARCHAR |
Timestamp when the file was last updated in the stage. |
Examples¶
List all the files in the stage for the mytable
table:
LIST @%mytable;
List all the files in the path1
path of the mystage
named stage:
LIST @mystage/path1;
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:
LS @~;