drop function if exists sp_get_last_poster_user_on_topic( p_forum_topic_id integer );
create function sp_get_last_poster_user_on_topic( p_forum_topic_id integer ) returns integer as $$
declare
	retval integer;
begin
	select owner_user_id into retval from forum_posts where forum_topic_id=p_forum_topic_id and not is_admin_moderated order by forum_post_id desc limit 1;
	return retval;
end;
$$language plpgsql
