function Truncate::__toString

Same name in this branch
  1. main core/modules/sqlite/src/Driver/Database/sqlite/Truncate.php \Drupal\sqlite\Driver\Database\sqlite\Truncate::__toString()
  2. main core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::__toString()
Same name and namespace in other branches
  1. 11.x core/modules/sqlite/src/Driver/Database/sqlite/Truncate.php \Drupal\sqlite\Driver\Database\sqlite\Truncate::__toString()
  2. 11.x core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::__toString()
  3. 10 core/modules/sqlite/src/Driver/Database/sqlite/Truncate.php \Drupal\sqlite\Driver\Database\sqlite\Truncate::__toString()
  4. 10 core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::__toString()
  5. 9 core/modules/sqlite/src/Driver/Database/sqlite/Truncate.php \Drupal\sqlite\Driver\Database\sqlite\Truncate::__toString()
  6. 9 core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::__toString()
  7. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Truncate.php \Drupal\Core\Database\Driver\sqlite\Truncate::__toString()
  8. 8.9.x core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::__toString()
  9. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Truncate.php \Drupal\pgsql\Driver\Database\pgsql\Truncate::__toString()

On PostgreSQL, TRUNCATE is fully transactional: it can be rolled back and does not cause an implicit commit, so there is no need to fall back to the slower DELETE query when inside a transaction. TRUNCATE is much faster on large tables and, unlike DELETE, does not leave dead rows behind for VACUUM to clean up.

Note that TRUNCATE takes an ACCESS EXCLUSIVE lock on the table that is held until the transaction ends, and it is not MVCC-safe with respect to concurrent transactions using a snapshot taken before the truncation.

Return value

string The prepared statement.

Overrides Truncate::__toString

See also

https://www.postgresql.org/docs/current/sql-truncate.html

File

core/modules/pgsql/src/Driver/Database/pgsql/Truncate.php, line 50

Class

Truncate
PostgreSQL implementation of \Drupal\Core\Database\Query\Truncate.

Namespace

Drupal\pgsql\Driver\Database\pgsql

Code

public function __toString() {
  // Create a sanitized comment string to prepend to the query.
  $comments = $this->connection
    ->makeComment($this->comments);
  return $comments . 'TRUNCATE {' . $this->connection
    ->escapeTable($this->table) . '} ';
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.