Conditional upsert

The cond operation supports len() only. You should check the val last with %d at the query level and use len() in the cond level.