diff --git a/entitycache.info b/entitycache.info
index f4155fb..085d090 100644
--- a/entitycache.info
+++ b/entitycache.info
@@ -8,3 +8,5 @@ files[] = entitycache.module
 files[] = entitycache.comment.inc
 files[] = entitycache.taxonomy.inc
 files[] = entitycache.test
+
+dependencies[] = drupal (>=7.36)
diff --git a/entitycache.module b/entitycache.module
index dce177f..75cead3 100644
--- a/entitycache.module
+++ b/entitycache.module
@@ -90,6 +90,11 @@ class EntityCacheControllerHelper extends DrupalDefaultEntityController {
       }
     }
 
+    // Ensure integer entity IDs are valid.
+    if (!empty($ids)) {
+      static::entityCacheCleanIds($controller, $ids);
+    }
+
     // 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.
@@ -145,6 +150,37 @@ class EntityCacheControllerHelper extends DrupalDefaultEntityController {
     return $entities;
   }
 
+  /**
+   * 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 static function entityCacheCleanIds($controller, &$ids) {
+    $entity_info = entity_get_info($controller->entityType);
+    if (isset($entity_info['base table field types'])) {
+      $id_type = $entity_info['base table field types'][$controller->idKey];
+      if ($id_type == 'serial' || $id_type == 'int') {
+        $ids = array_filter($ids, array(__CLASS__, 'entityCacheFilterId'));
+        $ids = array_map('intval', $ids);
+      }
+    }
+  }
+
+  /**
+   * Callback for array_filter that removes non-integer IDs.
+   */
+  public static function entityCacheFilterId($id) {
+    return is_numeric($id) && $id == (int) $id;
+  }
+
   public static function entityCacheGet($controller, $ids, $conditions = array()) {
     $cached_entities = array();
     if ($ids && !$conditions) {
