title: Firebird: simulating create table as?
body: <p>I'm searching a way to simulate "create table as select" in Firebird from SP.</p>
  
  <p>We are using this statement frequently in another product, because it is very easy for make lesser, indexable sets, and provide very fast results in server side.</p>
  
  <pre><code>create temp table a select * from xxx where ...
  create indexes on a ...
  create temp table b select * from xxx where ...
  create indexes on b ...
  
  select * from a
  union
  select * from b
  </code></pre>
  
  <p>Or to avoid the three or more levels in subqueries.</p>
  
  <pre><code>select * 
  from a where id in (select id 
                      from b 
                      where ... and id in (select id from c where))
  </code></pre>
  
  <p>The "create table as select" is very good cos it's provide correct field types and names so I don't need to predefine them.</p>
  
  <p>I can simulate "create table as" in Firebird with Delphi as:</p>
  
  <p>Make select with no rows, get the table field types, convert them to create table SQL, run it, and make "insert into temp table " + selectsql with rows (without order by).
  It's ok.</p>
  
  <p>But can I create same thing in a common stored procedure which gets a select sql, and creates a new temp table with the result?</p>
  
  <p>So: can I get query result's field types to I can create field creator SQL from them?</p>
  
  <p>I'm just asking if is there a way or not (then I MUST specify the columns).</p>