title: Loop through like tables in a schema
body: <p>Postgres 9.1 - I have a schema that has tables "partitioned" by month (a new table is created each month, all columns the same). It is not set up as normal partitioning with a "master" table. I am currently writing a fairly large query, that I will have to run a few times each month. </p>
  
  <p>Schema: <code>augmented_events</code><br>
  tables:<br>
  <code>p201301</code> (January 2013)<br>
  <code>p201302</code> (Feb 2013)<br>
  <code>p201303</code> (March 2013)<br>
   ...<br>
  <code>p201312</code> (December 2013)<br>
  <code>p201401</code> (January 2014)</p>
  
  <p>Right now I have to write my (simplified) query as:  </p>
  
  <pre><code>select *    
  from augmented_events.p201301  
  union   
  select *      
  from augmented_events.p201302  
  union  
  select *      
  from augmented_events.p201303  
  union  
  select *      
  from augmented_events.p201312  
  union  
  select *      
  from augmented_events.p201401 
  </code></pre>
  
  <p>And every month I need to add in the new month. I would like to make this a little more scalable without me having to revisit it every month. Is there a function I can create (or one that exists) that loops through each table in the <code>augmented_events</code> schema, and treats it as if I was to union these tables?</p>