title: plpgsql stored function that creates table with parameter column names
body: <p>I want to create a Postgres Stored function in plpgsql that creates a table with specified column names that vary according to input parameters.</p>
  
  <p>Basically something like this:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION document_insert_new_document(_name text, _table_name text)
    RETURNS bigint AS
  $BODY$
  declare
    _documentid bigint;
    _user_history_table_name text;
    _history_table_name_column text;
  
  begin
      _documentid = 0;
      _user_history_table_name = 'merge_user_history_' || _table_name;
      _history_table_name_column = _table_name || '_id';
      CREATE TABLE _user_history_table_name
      (
        user_history_id bigint NOT NULL,
        _history_table_name_column bigint NOT NULL,
        ...
      )
  
  
  
  end;
  $BODY$
    LANGUAGE plpgsql VOLATILE
    COST 100;
  </code></pre>
  
  <p>Is this possible? And if so, how?</p>