Get string after character
You need use substring function
SQL FIDDLE
SELECT substring('1245487/filename.mov' from '%/#"%#"%' for '#');
Explanation:
%/
This mean %
some text and then a /
#"%#"
each #
is the place holder defined in the last part for '#'
and need and aditional "
So you have <placeholder> % <placeholder>
and function will return what is found inside both placeholder. In this case is %
or the rest of the string after /
FINAL QUERY:
SELECT substring(source_path from '%/#"%#"%' for '#');
FROM movies_history
If your case is that simple (exactly one /
in the string) use split_part()
:
SELECT split_part(source_path, '/', 2) ...
If there can be multiple /
, and you want the string after the last one, a simple and fast solution would be to process the string backwards with reverse()
, take the first part, and reverse()
again:
SELECT reverse(split_part(reverse(source_path), '/', 1)) ...
Or you could use the more versatile (and more expensive) substring()
with a regular expression:
SELECT substring(source_path, '[^/]*$') ...
Explanation:
[...]
.. encloses a list of characters to form a character class.[^...]
.. if the list starts with ^
it's the inversion (all characters not in the list).*
.. quantifier for 0-n times.$
.. anchor to end of string.
db<>fiddle here
Old sqlfiddle