Including avatar url into Postgres sql query

Trying to insert buddypress avatar url into postgres table when user upload new avatar.
Function bp_loggedin_user_avatar( ‘html=false’ ) gives proper URL but it just echoes it to screen.Not able to assigned value to variable $user_avatar_url and include it into query.
Is there way to have url properly inserted into sql query?