Check db_merge status whether inserted or updated
MergeQuery::execute() returns MergeQuery::STATUS_INSERT when the data was inserted in the database table, and MergeQuery::STATUS_UPDATE when a row was updated.

MergeQuery is the class of the object returned from db_merge().

public function execute() {
  if (!count($this-&gt;condition)) {
    throw new InvalidMergeQueryException(t('Invalid merge query: no conditions'));
  }
  $select = $this-&gt;connection-&gt;select($this-&gt;conditionTable)
    -&gt;condition($this-&gt;condition);
  $select-&gt;addExpression('1');
  if (!$select-&gt;execute()-&gt;fetchField()) {
    try {
      $insert = $this-&gt;connection-&gt;insert($this-&gt;table)-&gt;fields($this-&gt;insertFields);
      if ($this-&gt;defaultFields) {
        $insert-&gt;useDefaults($this-&gt;defaultFields);
      }
      $insert-&gt;execute();
      return self::STATUS_INSERT;
    }
    catch (Exception $e) {
      // The insert query failed, maybe it's because a racing insert query
      // beat us in inserting the same row. Retry the select query, if it
      // returns a row, ignore the error and continue with the update
      // query below.
      if (!$select-&gt;execute()-&gt;fetchField()) {
        throw $e;
      }
    }
  }
  if ($this-&gt;needsUpdate) {
    $update = $this-&gt;connection-&gt;update($this-&gt;table)
      -&gt;fields($this-&gt;updateFields)
      -&gt;condition($this-&gt;condition);
    if ($this-&gt;expressionFields) {
      foreach ($this-&gt;expressionFields as $field =&gt; $data) {
        $update-&gt;expression($field, $data['expression'], $data['arguments']);
      }
    }
    $update-&gt;execute();
    return self::STATUS_UPDATE;
  }
}