diff --git a/includes/entity.inc b/includes/entity.inc
index dc43e73..af63c2b 100644
--- a/includes/entity.inc
+++ b/includes/entity.inc
@@ -154,6 +154,9 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {
    */
   public function load($ids = array(), $conditions = array()) {
     $entities = array();
+    if (!empty($ids)) {
+      $ids = $this->cleanIds($ids);
+    }
 
     // Revisions are not statically cached, and require a different query to
     // other conditions, so separate the revision id into its own variable.
@@ -222,6 +225,37 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {
   }
 
   /**
+   * Sanitizes the entity IDs to the correct data type.
+   *
+   * The identifier sanitization provided by this method has been introduced
+   * as Drupal used to rely on the database to facilitate this, which worked
+   * correctly with MySQL but led to errors with other DBMS such as PostgeSQL.
+   *
+   * @param array $ids
+   *   The entity IDs to verify.
+   * @return array
+   *   The sanitized list of entity IDs.
+   */
+  protected function cleanIds($ids) {
+    $base_table_schema = drupal_get_schema($this->entityInfo['base table']);
+    if (isset($base_table_schema['fields'][$this->idKey]['type'])) {
+      switch ($base_table_schema['fields'][$this->idKey]['type']) {
+        case 'serial':
+        case 'int':
+          $ids = array_filter($ids, 'is_numeric');
+          $ids = array_map('intval', $ids);
+          break;
+        case 'char':
+        case 'varchar':
+          $ids = array_filter($ids, 'is_string');
+          $ids = array_map('strval', $ids);
+          break;
+      }
+    }
+    return $ids;
+  }
+
+  /**
    * Builds the query to load the entity.
    *
    * This has full revision support. For entities requiring special queries,
diff --git a/modules/system/system.test b/modules/system/system.test
index cae5cc7..669e936 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -1040,6 +1040,11 @@ class PageNotFoundTestCase extends DrupalWebTestCase {
     );
     $node = $this->drupalCreateNode($edit);
 
+    // As node IDs must be integers, make sure requests for non-integer IDs
+    // return a page not found error.
+    $this->drupalGet('node/invalid');
+    $this->assertResponse(404);
+
     // Use a custom 404 page.
     $this->drupalPost('admin/config/system/site-information', array('site_404' => 'node/' . $node->nid), t('Save configuration'));
 
