title: Can I automatically create a table in PostgreSQL from a csv file with headers?
body: <p>I'm running PostgreSQL 9.2.6 on OS X 10.6.8. I would like to import data from a CSV file with column headers into a database. I can do this with the <code>COPY</code> statement, but only if I first manually create a table with a column for each column in the CSV file. Is there any way to automatically create this table based on the headers in the CSV file?</p>
  
  <p>Per <a href="https://stackoverflow.com/questions/17662631/how-to-copy-from-csv-file-to-postgresql-table-with-headers-in-csv-file">this question</a> I have tried</p>
  
  <p><code>COPY test FROM '/path/to/test.csv' CSV HEADER;</code></p>
  
  <p>But I just get this error:</p>
  
  <p><code>ERROR:  relation "test" does not exist</code></p>
  
  <p>And if I first create a table with no columns:</p>
  
  <p><code>CREATE TABLE test ();</code></p>
  
  <p>I get:</p>
  
  <p><code>ERROR:  extra data after last expected column</code></p>
  
  <p>I can't find anything in the PostgreSQL <a href="http://www.postgresql.org/docs/9.2/static/sql-copy.html" rel="noreferrer">COPY documentation</a> about automatically creating a table. Is there some other way to automatically create a table from a CSV file with headers?</p>