REMOVE
statementsupportedData loading & unloadingRemoves files from either an external (external cloud storage) or internal (i.e. Snowflake) stage. For internal stages, the following stage types are supported: - Named internal stage - Stage for a specified table - Stage for the current user REMOVE can be abbreviated to RM.
Syntax
supportedpartialnot supportednot scored
REMOVE { internalStage | externalStage } [ PATTERN = '<regex_pattern>' ]
Where
internalStage ::=
@[<namespace>.]<int_stage_name>[/<path>]
| @[<namespace>.]%<table_name>[/<path>]
| @~[/<path>]
Where
externalStage ::=
@[<namespace>.]<ext_stage_name>[/<path>]
Parameters
| Name | Required | Description |
|---|---|---|
internalStage | externalStage | required | 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.ExpandShow lessSee more Where: <namespace> is the database and/or schema in which the named internal 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"). |
PATTERN = 'regex_pattern' | optional | Specifies a regular expression pattern for filtering files to remove. The command lists all files in the specified path and applies the regular expression pattern on each of the files found. |
Usage notes
- If you are loading data from a file on a stage, do not remove the staged files until the data has been loaded successfully. To check if the data has been loaded successfully, use the COPY_HISTORY command. Check the STATUS column to determine if the data from the file has been loaded. Note that if the status is Load in progress, removing the staged file can result in partial loads and data loss.
- To run this command with a named external stage that uses a storage integration, the role that owns the stage must have or inherit the USAGE privilege on the storage integration. The role that runs the command doesn’t need this privilege. If a COPY INTO statement specifies a storage integration directly with the STORAGE_INTEGRATION parameter instead of referencing a named stage, the role that runs the statement must have or inherit the USAGE privilege on the storage integration. For more information, see Stage privileges.
- Removing files from an external stage requires granting the following role or permission to Snowflake in your cloud storage account: Cloud Storage Service Role or Permission Instructions Amazon S3 s3:DeleteObject Configuring secure access to Amazon S3 Google Cloud Storage storage.objects.delete Configure an integration for Google Cloud Storage Microsoft Azure (Blob storage) Storage Blob Data Contributor Configure an Azure container for loading dataExpandShow lessSee more
- The command removes all directories and files that match a specified path. For example, the following statement would match any of the following objects in the mytable table stage: myobject.csv.gz (file)
- myobject (directory)
- myobject_new (directory)
- To remove all files for a specific directory, include a forward-slash (/) at the end of the path. For example: Copy code rm @%mytable/myobject/;
- If a REMOVE statement is interrupted before it has completed running, any files already removed by the statement are not restored.