lundi 21 décembre 2015

SQLite: isolating the file extension from a path

I need to isolate the file extension from a path in SQLite. I've read the post here (SQLite: How to select part of string?), which gets 99% there.

However, the solution:

select distinct replace(column_name, rtrim(column_name, replace(column_name, '.', '' ) ), '') from table_name;

fails if a file has no extension (i.e. no '.' in the filename), for which it should return an empty string. Is there any way to trap this please?

Note the filename in this context is the bit after the final '\' - it shouldn't be searching for '.'s in the full path, as it does at moment too.

I think it should be possible to do it using further nested rtrims and replaces.

Aucun commentaire:

Enregistrer un commentaire