如果你的情况就是这么简单(exactly one /
在字符串中)使用split_part() https://www.postgresql.org/docs/current/functions-string.html#FUNCTIONS-STRING-OTHER:
SELECT split_part(source_path, '/', 2) ...
If可以有multiple /
,并且您想要后面的字符串last一,一个简单快速的解决方案是向后处理字符串reverse() https://www.postgresql.org/docs/current/functions-string.html#FUNCTIONS-STRING-OTHER,取第一部分,并且reverse()
again:
SELECT reverse(split_part(reverse(source_path), '/', 1)) ...
Or你可以使用更通用的(也更昂贵的)substring() https://www.postgresql.org/docs/current/functions-string.html#FUNCTIONS-STRING-OTHER用正则表达式:
SELECT substring(source_path, '[^/]*$') ...
解释:
[...]
.. 包含一个字符列表以形成字符类。
[^...]
..如果列表开头为^
这是反转(列表中没有的所有字符)。
*
.. 0-n 次量词。
$
.. 锚定到字符串末尾。
db<>fiddle
Old sqlfiddle http://sqlfiddle.com/#!17/9eecb/4675