Categories:

File Functions

GET_RELATIVE_PATH

Extracts the path of a staged file relative to its location in the stage using the stage name and absolute file path in cloud storage as inputs.

Syntax

GET_RELATIVE_PATH( @<stage_name> , '<absolute_file_path>' )

Arguments

stage_name

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

absolute_file_path

Stage location, including the path and filename, of the file in cloud storage.

Usage Notes

This SQL function returns a value for any role that has the following privilege on the stage:

External stage

USAGE

Internal stage

READ

Output

Path of the file relative to the stage location.

Examples

Retrieve the relative path of a bitmap format image file in an external stage, where the @images_stage stage references the s3://photos/national_parks/ bucket and path:

SELECT GET_RELATIVE_PATH(@images_stage, 's3://photos/national_parks/us/yosemite/half_dome.jpg');
+================================================================================---------------------+
| GET_RELATIVE_PATH(@IMAGES_STAGE, 'S3://PHOTOS/NATIONAL_PARKS/US/YOSEMITE/HALF_DOME.JPG')  |
+================================================================================---------------------+
| us/yosemite/half_dome.jpg                                                                 |
+================================================================================---------------------+