WITH UsersRez AS
(
SELECT "user".role_id as role_id, "user".id as user_id, ROW_NUMBER()
OVER (ORDER BY timestamp DESC) AS RowNumber
FROM "user" where role_id={0}
)
SELECT RowNumber,user_id
FROM UsersRez
WHERE user_id = {1}
.format(current_user.role.id, current_user.id)