Categories:

DML Commands - File Staging

REMOVE

Removes 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.

See also:

LIST

Syntax

REMOVE internalStage [ PATTERN = '<regex_pattern>' ]

Where:

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

Required Parameters

internalStage

Specifies the location in Snowflake where files are staged:

@[namespace.]int_stage_name[/path]

Files are removed from the specified named internal stage.

@[namespace.]%table_name[/path]

Files are removed from the stage for the specified table.

@~[/path]

Files are removed from the stage for the current user.

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").

Optional Parameters

PATTERN = 'regex_pattern'

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

  • 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

    Configuring an Integration for Google Cloud Storage

    Microsoft Azure (Blob storage)

    Storage Blob Data Contributor

    Configuring an Azure Container for Loading Data

  • 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)

    rm @%mytable/myobject;
    
  • To remove all files for a specific directory, include a forward-slash (/) at the end of the path. For example:

    rm @%mytable/myobject/;
    
  • Do not remove the worksheet_data directory in the Snowflake user stage. The classic web interface stores metadata for worksheets in the Worksheets Worksheet tab tab in this directory. Removing the directory removes access to the worksheets, which cannot be restored.

    Note that this precaution does not apply to Snowsight worksheets in the new web interface, which are stored elsewhere and are not prone to accidental deletion.

  • If a REMOVE statement is interrupted before it has completed running, any files already removed by the statement are not restored.

Examples

Remove all files from the path1/subpath2 path in a named internal stage named mystage:

REMOVE @mystage/path1/subpath2;

Remove all files from the stage for the orders table:

REMOVE @%orders;

Use the abbreviated form of the command to remove files whose names match the pattern *jun* from the stage for the current user:

RM @~ pattern='.*jun.*';