diff --git a/includes/entity.inc b/includes/entity.inc
index 203ed87..5e23bd6 100644
--- a/includes/entity.inc
+++ b/includes/entity.inc
@@ -181,6 +181,15 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {
       }
     }
 
+    // Ensure integer entity IDs are valid.
+    if (!empty($ids)) {
+      $ids = $this->cleanIds($ids);
+      // If all passed IDs have been filtered out, do not return any entities.
+      if (empty($ids)) {
+        return $entities;
+      }
+    }
+
     // Load any remaining entities from the database. This is the case if $ids
     // is set to FALSE (so we load all entities), if there are any ids left to
     // load, if loading a revision, or if $conditions was passed without $ids.
@@ -222,6 +231,32 @@ class DrupalDefaultEntityController implements DrupalEntityControllerInterface {
   }
 
   /**
+   * Ensures integer entity IDs are valid.
+   *
+   * 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 PostgreSQL.
+   *
+   * @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'])) {
+      $id_type = $base_table_schema['fields'][$this->idKey]['type'];
+      if ($id_type == 'serial' || $id_type == 'int') {
+        $ids = array_filter($ids, function ($id) {
+          return is_numeric($id) && $id == (int) $id;
+        });
+        $ids = array_map('intval', $ids);
+      }
+    }
+    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'));
 
