Another way to calculate the last position is to cut the string into an array by delimon equal to the desired character, and then subtract the length of characters for the last item from the length of the whole string
CREATE FUNCTION last_pos(char, text) RETURNS INTEGER AS
$$
select length($2) - length(a.arr[array_length(a.arr,1)])
from (select string_to_array($2, $1) as arr) as a
$$ LANGUAGE SQL;
For the first position it’s easier to use
select position('#' in '2010-####-3434');
source
share