BUILD_STAGE_FILE_URL
functionsupportedData loading & unloadingGenerates a Snowflake file URL to a staged file using the stage name and relative file path as inputs. A file URL permits prolonged access to a specified file. That is, the file URL does not expire. Call this SQL function in a query, user-defined function (UDF), or stored procedure. Access files in a stage by sending the file URL in a request to the REST API for file support. When users send a file URL to the REST API to access files, Snowflake performs the following actions: - Authenticate the user. - Verify that the role has sufficient privileges on the stage that contains the file. - Redirect the user to the staged file in the cloud storage service.
Syntax
BUILD_STAGE_FILE_URL( @<stage_name> , '<relative_file_path>' )
Parameters
| Name | Required | Description |
|---|---|---|
stage_name | required | Name of the internal or external stage where the file is stored. Note If the stage name includes spaces or special characters, it must be enclosed in single quotes (e.g. '@"my stage"' for a stage named "my stage"). |
relative_file_path | required | Path and filename of the file relative to its location in the stage. |
Returns
The function returns a file URL in the following format: Where:
Usage notes
- The permissions required to call this SQL function differ depending on how it is called: SQL Operation Permissions Required Query USAGE (external stage) or READ (internal stage) Stored procedure The stored procedure owner (i.e. role that has the OWNERSHIP privilege on the stored procedure) must have the stage privilege: USAGE (external stage) or READ (internal stage). A role that queries the stored procedure only requires the USAGE privilege on the stored procedure. UDF The UDF owner (i.e. role that has the OWNERSHIP privilege on the UDF) must have the stage privilege: USAGE (external stage) or READ (internal stage). A role that queries the UDF only requires the USAGE privilege on the UDF.ExpandShow lessSee more
- An HTTP client that sends a file URL to the REST API must be configured to allow redirects.
- When a file URL is accessed, the query history shows that the internal GET_STAGE_FILE function was called.
- If files downloaded from an internal stage are corrupted, verify with the stage creator that ENCRYPTION = (TYPE = 'SNOWFLAKE_SSE') is set for the stage.