Properly handle // when resolving filepaths in UDF file access APIs (Pending)

Attention

This behavior change is in the 2026_04 bundle.

For the current status of the bundle, refer to Bundle history.

When a UDF or stored procedure reads a file using SnowflakeFile.open, Snowflake no longer collapses double slashes (//) between the stage location and the relative file path when resolving the file URL inside the UDF or stored procedure. This applies to file URLs built with BUILD_SCOPED_FILE_URL, BUILD_STAGE_FILE_URL, or a direct stage reference (@stage//path).

Before the change:

A leading / in the relative path is collapsed when the file URL is resolved inside the UDF or stored procedure, so the file resolves as if the extra slash were not present.

-- All three resolve to [stage-location]/file.txt inside the UDF
SELECT my_udf(BUILD_SCOPED_FILE_URL(@stage, '//file.txt'));
SELECT my_udf(BUILD_STAGE_FILE_URL(@stage, '//file.txt'));
SELECT my_udf('@stage//file.txt');
After the change:

The double slash is preserved when the file URL is resolved inside the UDF or stored procedure. If no file exists at the literal path //file.txt relative to the stage location, a “file not found” error is returned.

-- All three now resolve to [stage-location]//file.txt inside the UDF
SELECT my_udf(BUILD_SCOPED_FILE_URL(@stage, '//file.txt'));
SELECT my_udf(BUILD_STAGE_FILE_URL(@stage, '//file.txt'));
SELECT my_udf('@stage//file.txt');

The error message for a file not found due to this issue includes the following guidance:

File does not exist or not authorized. One possible reason may be that the relative path begins with a ‘/’, please verify the path is as expected.

Note

A single-slash relative path continues to resolve to [stage-location]/file.txt as before. Only paths with a redundant leading slash are affected.

How to update your code

Remove the extra leading slash from the relative file path:

-- Before (breaks after change)
SELECT my_udf(BUILD_SCOPED_FILE_URL(@stage, '//file.txt'));
SELECT my_udf(BUILD_STAGE_FILE_URL(@stage, '//file.txt'));
SELECT my_udf('@stage//file.txt');

-- After (correct)
SELECT my_udf(BUILD_SCOPED_FILE_URL(@stage, '/file.txt'));
SELECT my_udf(BUILD_STAGE_FILE_URL(@stage, '/file.txt'));
SELECT my_udf('@stage/file.txt');

If you use DIRECTORY on an external stage to generate file paths, verify that the generated relative paths do not begin with a /:

SELECT relative_path FROM DIRECTORY(@my_external_stage);

If any paths begin with a leading slash, amend your stage definition to append a trailing / to the URL so that the generated relative paths no longer include the extra slash.

Ref: 1810