How to get input file name as column in AWS Athena external tables

If you need just the filename, you can extract it with regeexp_extract().

To use it in Athena on the "$path" you can do something like this:

SELECT regexp_extract("$path", '[^/]+$') AS filename from table;

If you need the filename without the extension, you can do:

SELECT regexp_extract("$path", '[ \w-]+?(?=\.)') AS filename_without_extension from table;

Here is the documentation on Presto Regular Expression Functions


You can do this with the $path pseudo column.

select "$path" from table