Answer the question
In order to leave comments, you need to log in
Working with paths in SQL. Is there an easy way?
Example - sqlfiddle.com/#!9/a2612
There is a column with paths to files, for example '/a/b/c/110/h4eheh.jpg' You
need to get only the last folder, extension from it and insert a static string between them . Those. the new name should be '110_somestring.jpg'
Is it possible to write a query without a bunch of nested functions?
PS Please do not offer to implement this in python/php/node.js, etc.
Answer the question
In order to leave comments, you need to log in
SELECT CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX('/a/b/c/110/h4eheh.jpg','/',-2),'/',1),'_somestring.',SUBSTRING_INDEX('/a/b/c/110/h4eheh.jpg','.',-1)) as image
SET @q = '/a/b/c/110/h4eheh.jpg';
SET @a1 = SUBSTRING_INDEX(SUBSTRING_INDEX(@q,'/',-2),'/',1);
SET @a2 = SUBSTRING_INDEX(@q,'.',-1);
SELECT @q, CONCAT(@a1,'_somestring.',@a2),@a2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question