title: Zend\Db\Sql\Select using function as table
body: <p>I'm trying to use <code>Zend\Db\Sql\Select</code> to select the results of a sql function, then join other tables, sort, paginate etc. I realize there are solutions that involve building a statement from hand-written SQL, but I have helpers for sorting and pagination that work with Select and I'd like to utilize the select API.</p>
  
  <p>Anyway, if I try to do something like this...</p>
  
  <p><code>$select-&gt;from(new TableIdentifier("ufn_user_client($userId, $clientId)", 'my_schema')</code></p>
  
  <p>... it quotes the entire function, including the parens, and I get <code>ERROR:  relation \"my_schema.ufn_user_client(3, 2)\" does not exist</code> since it quoted the entire thing. I've tried using just a string instead of TableIdentifier, Zend\Db\Expression, etc with similar results. How can I get this literal string in the FROM clause without it quoting the whole expression?</p>
  
  <p>Here's a minimal example:</p>
  
  <pre><code>&lt;?php
  
  require_once 'vendor/autoload.php';
  
  $config = [
      'driver'   =&gt; 'pdo_pgsql',
      'host'     =&gt; 'postgresvm.dev',
      'username' =&gt; 'user',
      'password' =&gt; 'pass',
      'dbname'   =&gt; 'mydb',
      'port'     =&gt; 5432
  ];
  
  $dbAdapter  = new \Zend\Db\Adapter\Adapter($config);
  $sqlAdapter = new \Zend\Db\Sql\Sql($dbAdapter);
  
  $select = new \Zend\Db\Sql\Select();
  $select-&gt;from("my_schema.ufn_user_client(2, 3)");
  
  $results =  $dbAdapter-&gt;query(
      $sqlAdapter-&gt;buildSqlString($select),
      \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
  )-&gt;toArray();
  
  var_dump($results);
  </code></pre>
  
  <p>which results in an error:</p>
  
  <pre><code>PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "my_schema.ufn_user_client(2, 3)" does not exist
  </code></pre>
  
  <p>Maybe this is specific to the postgres pdo driver and how it quotes identifiers?</p>