Consider the following UPDATE. I think the naming is clear enough to not require any further explanation. The identification of which row to update happens in a sub query. Is there a concurrency risk here? Could another process "sneak in" between the execution of the sub query and the outer query, and book the row? If so, I think the risk could be eliminated by doing a FOR UPDATE in the sub query (see my comment in the query)
UPDATE
bookableresource_slots
SET
booked = $1,
status = $2,
data = $3
WHERE id = (
SELECT
id
FROM
bookableresource_slots
WHERE
starttime = $4
AND booked IS NULL
LIMIT 1
-- SHOULD I USE "FOR UPDATE" HERE TO LOCK THE ROW?
)
RETURNING
id;