title: Copy a whole table from MSSQL to PostgreSQL with Python code
body: <p>I am trying to get a selection from a table in a MSSQL database into another table in a PostgreSQL database. I read this post by "The_Fox" trying to do the same thing long ago: </p>
  
  <p><a href="https://stackoverflow.com/questions/6264696/copy-data-from-mssql-database-to-postgresql-database-with-python">copy data from MSSQL database to Postgresql database with Python</a></p>
  
  <p>I based my code on this and I managed to get one row at a time with "fetchone" from MSSQL to postgresql, however I do not manage to "fetchall" and insert a whole column of data into postgresql.</p>
  
  <p>With the following code I get the error:
  "ProgrammingError: syntax error at or near "["
  LINE 1: INSERT INTO test_tabell VALUES ([])"</p>
  
  <p>My code is below, any suggestions?</p>
  
  <p>Thanks!</p>
  
  <pre><code>import pymssql, psycopg2
  
  
  #Connect to the database
  class DatabaseRequest:
  
      def __init__(self):
          self.conn1 = pymssql.connect(
      host=r'*****',
      user=r'*****',
      password='*****',
      database='*****'
  )
          self.conn2 = psycopg2.connect(host='*****', dbname='*****', user= '*****', password='*****')
  
          self.cur1 = self.conn1.cursor()
          self.cur2 = self.conn2.cursor()
  
  # Fetch data from the MSSQL-database
      def request_proc(self):
          self.cur1.execute("SELECT table.column FROM table")
  
          global rows 
          rows = self.cur1.fetchall()
  
          # This prints all the information I want in my new table, so it seems to be able to fetch it, however in the form of "&lt;class 'tuple'&gt;"
          for row in rows:
              print(row)
              print (type(row))
          return rows   
  
  
  # Insert all data to an existing table in the postgresql database:
      def insert_proc(self):
  
  #This is the statement I think there is something wrong with:
          self.cur2.execute("INSERT INTO table VALUES (%s)" % self.cur1.fetchall())
          self.conn2.commit()
  
  
  
  a = DatabaseRequest()
  print(a.request_proc(), a.insert_proc())
  </code></pre>