WHERE leaderboard_id = $1 AND owner_id = $2 AND expiry_time = $4 AND (max_num_score = 0 OR num_score < max_num_score)`+strings.ReplaceAll(filterSQL,"WHERE","AND")
WHERE leaderboard_id = $1 AND owner_id = $2 AND expiry_time = $4 AND (max_num_score = 0 OR num_score < max_num_score)`
err:=tx.QueryRowContext(ctx,"SELECT num_score, max_num_score FROM leaderboard_record WHERE leaderboard_id = $1 AND owner_id = $2 AND expiry_time = $3",leaderboard.Id,ownerId,expiryTime).Scan(&dbNumScore,&dbMaxNumScore)
// This query could probably be avoided by adding the num_scores to the result of the insert and adding one to it,
// and if there is an error at this point it will be a sql.ErrNoRows meaning this is an insert so we can set it to one.
err=tx.QueryRowContext(ctx,"SELECT num_score, max_num_score FROM leaderboard_record WHERE leaderboard_id = $1 AND owner_id = $2 AND expiry_time = $3",leaderboard.Id,ownerId,expiryTime).Scan(&dbNumScore,&dbMaxNumScore)