[ Home ]

A PostgreSQL function to return the extension of a filename

create or replace function extract_file_extension(filename text) returns text as $$
declare
    extension text;
begin
    select regexp_replace(filename, E'^.*\\.', '') into extension;
    if extension = filename then
        return '';
    else
        return extension;
    end if;
end;
$$ language plpgsql;