Delete query is called while updating the cck field value of node.

After debugging i find following code in


in field_sql_storage_field_storage_write($entity_type, $entity, $op, $fields)

we have following code

// Delete and insert, rather than update, in case a value was added.
  // Delete languages present in the incoming $entity->$field_name.
  // Delete all languages if $entity->$field_name is empty.
  $languages = !empty($entity->$field_name) ? $field_languages : $all_languages;
  if ($languages) {
      ->condition('entity_type', $entity_type)
      ->condition('entity_id', $id)
      ->condition('language', $languages, 'IN')
      ->condition('entity_type', $entity_type)
      ->condition('entity_id', $id)
      ->condition('revision_id', $vid)
      ->condition('language', $languages, 'IN')

May be someone explain why ? And also can i use update Query instead of delete, insert ?

  • calling? you mean called?
    – GwenM
    Feb 8, 2016 at 13:17
  • Yes while i am editing any node and trying to save, delete query is called for cck fields ex: "field_data_body" Feb 8, 2016 at 13:37

1 Answer 1


As the comment at the top states: Delete and insert, rather than update, in case a value was added.

So to make sure all old data is cleared, the records are deleted and re-added with new data (as you can see on line 481: $query = db_insert($table_name)->fields($columns);.

Of course you could use the update query, but this query would need to contain all fields because it is impossible to know which fields are added, modified or deleted. A simple delete and add solves that problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.