Postgresql Find Substring Python Function