Я пытаюсь получить выборку из таблицы в базе данных MSSQL в другую таблицу в базе данных PostgreSQL.Я прочитал это сообщение от The_Fox, пытаясь сделать то же самое давно:
копировать данные из базы данных MSSQL в базу данных Postgresql с Python
Я основал свой код наэто и мне удалось получить по одной строке с "fetchone" из MSSQL в postgresql, однако мне не удается "fetchall" и вставить целый столбец данных в postgresql.
С помощью следующего кода яполучить ошибку: «ProgrammingError: синтаксическая ошибка в или около» [«LINE 1: INSERT INTO test_tabell VALUES ([])»
Мой код приведен ниже, любые предложения?
Спасибо!
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 "<class 'tuple'>"
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())