// If join is required then the user must already have a record to update.
// There's also no need to increment the number of records tracked for this tournament.
varexistsint
err:=db.QueryRowContext(ctx,"SELECT 1 FROM leaderboard_record WHERE leaderboard_id = $1 AND owner_id = $2 AND expiry_time = $3",leaderboard.Id,ownerId,expiryTime).Scan(&exists)
iferr!=nil{
iferr==sql.ErrNoRows{
// Tournament required join but no row was found to update.
WHERE leaderboard_id = $1 AND owner_id = $2 AND expiry_time = $4 AND (max_num_score = 0 OR num_score < max_num_score)`
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")