title: Can I truncate tables dynamically?
body: <p>I have a table with 3 different partitions that is split on the <code>point_of_sale</code> column. I have constructed a view (<code>massive_table</code>) to aggregate data from these partitions like so: </p>
  
  <pre><code>CREATE VIEW massive_table as
  SELECT * FROM massive_table_UK
  UNION ALL
  SELECT * FROM massive_table_US
  UNION ALL
  SELECT * FROM massive_table_DE;
  </code></pre>
  
  <p>The <code>massive_table_UK/US/DE</code> tables each have a check constraint imposed on them so that the <code>point_of_sale</code> column can only contain a string value of either <code>UK</code>, <code>US</code> or <code>DE</code> as appropriate.</p>
  
  <p>Before partitioning it, I'd prepare the table for new data by doing the following:</p>
  
  <pre><code>DELETE FROM massive_table WHERE point_of_sale = 'UK';
  </code></pre>
  
  <p>What I'd prefer to, however, is to truncate the appropriate partition.  Is it possible to do this dynamically?  I've looked at the <a href="http://www.postgresql.org/docs/9.1/static/plpgsql-statements.html" rel="nofollow">PostgreSQL PL/pgSQL documentation</a> and it says that </p>
  
  <blockquote>
    <p>Another restriction on parameter symbols is that they only work in SELECT, INSERT, UPDATE, and DELETE commands. In other statement types (generically called utility statements), you must insert values textually even if they are just data values.</p>
  </blockquote>
  
  <p>I'm rather new to PostgreSQL programming and I'm struggling to comprehend that sentence; What I'd like to be able to do is have a function that would truncate the appropriate partition based on a given <code>point_of_sale</code> value.  Is that possible?</p>