Pager extention not working in dynamic database query I am trying to create a page which shows all the nodes created by the currently logged in user.  To do this I am using a dynamic query to fetch the relevant nodes.  However, for some reason the pager is not working.  Instead it lists all of the nodes.  I have not been able to work out why this is occurring as I have successfully used pagination previously with other less complex queries.  The following is from the page callback function:

function playground_page() {
  $build = array();

  $build['intro'] = array(
    '#markup' =&gt; 'This is a testing ground for Drupal concepts.',
  );

  // Example of table join. Display content created by current user.

  // Construct base query.
  global $user;
  $query = db_select('users', 'u');
  $node_table_alias = $query-&gt;join('node', 'n', 'n.uid = u.uid');
  $query
    -&gt;fields($node_table_alias, array('nid'))
    -&gt;condition('u.uid', $user-&gt;uid);

  // Add pager and node_access options.
  $query
    -&gt;addTag('node_access')
    -&gt;extend('PagerDefault')
    -&gt;limit(5);

  $nids = $query-&gt;execute()-&gt;fetchCol();
  $nodes = node_load_multiple($nids);

  foreach ($nodes as $node) {
    $key = 'node_' . $node-&gt;nid;
    $build[$key] = node_view($node, 'teaser');
  }

  $pager_args = array('tags' =&gt; array('&lt;&lt;', '&lt;', NULL, '&gt;', '&gt;&gt;'));
  $build['pager'] = array(
    '#markup' =&gt; theme('pager', $pager_args),
  );

  return $build;
}
This issue is related to the use of extenders.  When using an extender it is important to note that $query is not altered in place. A new query object is returned from extend(), and if it is not saved to a variable it will be lost.  See Extenders documentation for more info. 

To achieve this with the OP code, one would need to modify the following section:

  // Add pager and node_access options.
  $query = $query
    -&gt;addTag('node_access')
    -&gt;extend('PagerDefault')
    -&gt;limit(5);


Full working code is as follows:

function playground_page() {
  $build = array();

  $build['intro'] = array(
    '#markup' =&gt; 'This is a testing ground for Drupal concepts.',
  );

  // Example of table join. Display content created by current user.

  // Construct base query.
  global $user;
  $query = db_select('users', 'u');
  $node_table_alias = $query-&gt;join('node', 'n', 'n.uid = u.uid');
  $query
    -&gt;fields($node_table_alias, array('nid'))
    -&gt;condition('u.uid', $user-&gt;uid);

  // Add pager and node_access options.
  $query = $query
    -&gt;addTag('node_access')
    -&gt;extend('PagerDefault')
    -&gt;limit(5);

  $nids = $query-&gt;execute()-&gt;fetchCol();
  $nodes = node_load_multiple($nids);

  foreach ($nodes as $node) {
    $key = 'node_' . $node-&gt;nid;
    $build[$key] = node_view($node, 'teaser');
  }

  $pager_args = array('tags' =&gt; array('&lt;&lt;', '&lt;', NULL, '&gt;', '&gt;&gt;'));
  $build['pager'] = array(
    '#markup' =&gt; theme('pager', $pager_args),
  );

  return $build;
}