During DB2 migration to PostgreSQL, I found some views using db2
locate_in_string() function, which returns the position of a specified instance of a given substring.
LOCATE_IN_STRING('aaabaabbaaaab','b',1,3); -- returns 8, for the 3d instance of 'b' LOCATE_IN_STRING('aaabaabbaaaab','b',1,1); -- returns 4, for the 1st instance of 'b'
Unfortunately, the PostgreSQLs function
position() it gives me only the post for the first instance.
I did not find something similar in PostgreSQL.
Is there an alternative or workaround (maybe regex?)?