i'm facing the below error and unable to move forward,if anyone have any leads or solution on how to handle this,Kindly let me know.
I'm trying to port the data from one database to another using the below logic and is stumbled with this error,Please help me with this.
I have been trying to resolve it for many days and till now haven't got any idea on how to do this,Can you please help me with this and show me where i'm getting these?
I'm trying to port the data from one database to another using the below logic and is stumbled with this error,Please help me with this.
I have been trying to resolve it for many days and till now haven't got any idea on how to do this,Can you please help me with this and show me where i'm getting these?
Quote:Error while fetching data from PostgreSQL tuple indices must be integers or slices, not str
import psycopg2 import os import time import sys from pprint import pprint from datetime import datetime from psycopg2 import sql import traceback def psql_fetchandInsert(cnx_msql,cnx_psql,msql, psql, msql_command, psql_command): msql.execute(msql_command) for row in msql: try: print(row) print(psql_command) psql.execute(psql_command, row) exc_info = sys.exc_info() cnx_psql.commit() except psycopg2.Error as e: traceback.print_exception(exc_info) traceback.print_exc() print ("Cannot execute the query!!", e.pgerror) sys.exit("Some problem occured with the query!!!") def Fetch(): try: cnx_msql = psycopg2.connect(user="postgres", password="postgres", host="127.0.0.1", port="5432", database="postgres") except psycopg2.Error as e: print ("DB: Unable to connect!", e.msg) sys.exit(1) # Postgresql connection try: cnx_psql = psycopg2.connect(user="postgres", password="postgres", host="127.0.0.1", port="5432", database="Sendy") #cnx_psql = psycopg2.connect(conn_string_psql) except psycopg2.Error as e: print('PSQL: Unable to connect!\n{0}').format(e) sys.exit(1) try: # Cursors initializations cur_msql = cnx_msql.cursor() cur_psql = cnx_psql.cursor() print(" cursor initialised") print("creating table using cursor") SQL_schema="""CREATE SCHEMA IF NOT EXISTS st AUTHORIZATION postgres;""" SQL_products="""CREATE TABLE IF NOT EXISTS st.products ( Id INTEGER , Name CHARACTER VARYING , Product CHARACTER VARYING , email CHARACTER VARYING , sku CHARACTER VARYING , html_code CHARACTER VARYING , quote_id INTEGER , itemcount NUMERIC );""" cur_psql.execute(SQL_schema) cur_psql.execute(SQL_products) cnx_psql.commit(); commands = [("""SELECT "Id","Name","Product","email","htmlcode","itemcount" from dl."Products";""", """INSERT INTO st."products" (Id,Name,Product,email,htmlcode,itemcount) \ VALUES (%(Id)s, %(Name)s, %(Product)s, %(email)s, %(html_code)s, %(itemcount)s);""") ] print ("check") for msql_command, psql_command in commands: psql_fetchandInsert(cnx_msql,cnx_psql,cur_msql, cur_psql, msql_command, psql_command) except (Exception, psycopg2.Error) as error: print ("Error while fetching data from PostgreSQL", error) finally: ## Closing cursors cur_msql.close() cur_psql.close() ## Committing cnx_psql.commit() ## Closing database connections cnx_msql.close() cnx_psql.close() if __name__ == '__main__': Fetch()