Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies to:
Databricks SQL
Databricks Runtime 18 LTS and above
Important
This feature is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage Azure Databricks previews.
Returns a FILE value that references the file at path, or NULL if the file doesn't exist or is inaccessible.
Syntax
try_to_file(path)
Arguments
path: ASTRINGexpression specifying the path to a file, for example a path in a Unity Catalog volume.
Returns
A FILE value that references the file at path, or NULL if the file doesn't exist or is inaccessible.
This function is the error-tolerant version of to_file function. To gather file metadata, Azure Databricks makes a remote call to the file's storage location. If the file doesn't exist or is inaccessible, this function returns NULL instead of raising an error.
Common error conditions
TO_FILE_ILLEGAL_USAGE.NO_PATH_PROVIDED
For more information, see Error conditions in Azure Databricks.
Examples
To create a FILE reference from a path in a volume:
SELECT try_to_file('/Volumes/my_catalog/my_schema/my_volume/report.pdf');
If the path doesn't exist or is inaccessible, try_to_file returns NULL:
SELECT try_to_file('/Volumes/my_catalog/my_schema/my_volume/ghost.csv');
NULL