title: postgresql copy csv to table
body: <p>trying to copy data from a CSV file and save it in a table with postgresql. </p>
  
  <p>script based on <a href="https://stackoverflow.com/questions/2987433/how-to-import-csv-file-data-into-a-postgresql-table">this post</a></p>
  
  <p>running script in psql with postgresql version 11.6</p>
  
  <p>command used to run:</p>
  
  <pre><code>\i script.sql
  </code></pre>
  
  <p>script:</p>
  
  <pre><code>create table data
  (
      col_1 varchar(64)
      , col_2 varchar(64)
      , col_3 varchar(64)
      , col_4 varchar(64)
      , col_5 varchar(64)
      , col_6 varchar(64)
      , col_7 varchar(128)
      , col_8 varchar(64)
      , col_9 varchar(64)
      , col_10 varchar(64)
      , col_11 bigint
  )
  
  copy data from 'data.csv' with (format csv);
  </code></pre>
  
  <p>error message:</p>
  
  <pre><code>ERROR:  syntax error at or near "copy"
  LINE 15: copy data from 'data.csv' with (format csv...
           ^
  </code></pre>
  
  <p>also tried another way based on <a href="http://www.postgresqltutorial.com/import-csv-file-into-posgresql-table/" rel="nofollow noreferrer">this tutorial</a></p>
  
  <pre><code>create table data
  (
      col_1 varchar(64)
      , col_2 varchar(64)
      , col_3 varchar(64)
      , col_4 varchar(64)
      , col_5 varchar(64)
      , col_6 varchar(64)
      , col_7 varchar(128)
      , col_8 varchar(64)
      , col_9 varchar(64)
      , col_10 varchar(64)
      , col_11 bigint
  )
  
  copy data(col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10, col_11)
  from 'data.csv' delimiter ',' csv header;
  </code></pre>
  
  <p>error message:</p>
  
  <pre><code>ERROR:  syntax error at or near "copy"
  LINE 15: copy data(col_1, col_2, col_3, col_4...
  </code></pre>