Retrieving the primary Key column
As some people already mentioned and the error itself describes, this is a variable interpolation/auto-quoting problem.

The most appropriate option here - following the D.O.'s documentation - would be to use where(), instead of condition(). 


  $query->where($snippet, $args = array())  
  
  The where() method allows for the addition of arbitrary SQL as a conditional fragment. $snippet may contain any legal SQL fragment, and
  if it has variable content it must be added using a named placeholder.
  The $args array is an array of placeholders and values that will be
  substituted into the snippet. It is up to the developer to ensure that
  the snippet is valid SQL. No database-specific modifications are made
  to the snippet.  
  
  (Copied from https://www.drupal.org/node/310086)


And here is a rewrite of your code:

$query=db_select('pg_index', 'i',array('target' =&gt; 'import'));  
$query-&gt;join('pg_attribute' , 'a' ,'a.attrelid = i.indrelid AND a.attnum = ANY(i.indkey)');                 
$result = $query
    -&gt;fields('a', array('attname','atttypid','atttypmod'))  
    -&gt;where("i.indrelid = 'semstudent'::regclass")
    -&gt;condition('i.indisprimary', true) 
    -&gt;execute();


I just tried this and it worked without any problems, hope it works for you too!