mysql – Replace in update, change extension in filenames


I have a table with images, images , in which one of these columns ( file_name ) has image names, some jpg others png , what I need is to change, UPDATE all to the png extension, that is, change any extension that has and put png .

PS: there are filenames that have dots in addition to the extension, eg "41sUhh.mGDDL. SY355 .jpg"


Use replace()

update tabela set file_name = replace(file_name, '.jpg', '.png');

Just be careful not to have more than one occurrence of .jpg in your caminho_foto column.

Scroll to Top