title: converting columns to postgresql database
body: <p>suppose I have a list of columns in python of equal lengths (in the example below, each column has 4 elements, but in my actual work each column has around 500+ elements):</p>
  
  <pre><code>col0 = [1, 12, 23, 41]   # also used as a primary key
  col1 = ['asdas','asd', '1323', 'adge']
  col2 = [true, false, true, true]
  col4 = [312.12, 423.1, 243.56, 634.5]
  </code></pre>
  
  <p>and I have a postgresql table already defined, with columns: Col0 (integer, also primary key), Col1 (character varying), Col2 (boolean), Col3 (numeric)</p>
  
  <p>I wrote the following code to connect to the postgresql database (which seemed to have worked fine):</p>
  
  <pre><code>import psycopg2
  ...
  conn = psycopg2.connect("dbname='mydb' user='myuser' host='localhost' password = 'mypwd')
  cur = conn.cursor()
  </code></pre>
  
  <p>Now suppose I want to push the columns to postgresql table <code>myt</code> where I want the rows to populated as :</p>
  
  <pre><code> Col1  Col2     Col3   Col4
   1     'asdas'  true   312.12
   12    'asd'    false  423.1
   ...
  </code></pre>
  
  <p>I saw examples on SO <a href="https://stackoverflow.com/questions/28924118/converting-pandas-columns-to-postgresql-list">such as this one</a> where the example is for reading from a csv file:</p>
  
  <pre><code>for row in reader:
      cur.execute("INSERT INTO test (num, data) VALUES (%s, %s)", (variable1, variable2))
  </code></pre>
  
  <p>(a) Can I adopt something similar for my case? Would this work:</p>
  
  <pre><code>for i in range(0, len(col0)):
      cur.execute("INSERT INTO myt (Col1, Col2, Col3, Col4) VALUES (%??, %s, %??, %f)", (col0[i], col1[i], col2[i], col3[i]))
  </code></pre>
  
  <p>(b) If yes, what is the type specifier for python integer, boolean, float types , when the corresponding postgresql types are integer, boolean and numeric?</p>
  
  <p>(c) Also, what if I have 40 tables, instead of 4 tables. Do I have to write a long line like this:</p>
  
  <pre><code>   "INSERT INTO myt (Col1, Col2, ..., Col40) VALUES (%d, %s, ..., %f)", (col0[i], ...))
  </code></pre>