 <p>If there's no duplicate, then this query will do an insert, and the <code>Time</code> value will be null, as no value was ever set. <code>Null + anything</code> is null, hence the error.</p> <p>Try <code>... Time = COALESCE(Time, 0) + INTERVAL $time SECOND</code> or similar to get aroun dit.</p>