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