Feb-10-2022, 08:52 PM
I am trying to migrate data from oracle into postgres using python. My code follow bellow.
def insert_postgres(): con = OracleHook(oracle_conn_id=kwargs['oracle_conn']).get_conn() cursor = con.cursor() cursor.execute(query) result = cursor.fetchall() df = pd.read_sql(query, con) try: connection = PostgresHook(postgres_conn_id=kwargs['postgres_connection']).get_uri() connection.autocommit = True cursor = connection.cursor() query = df cur.execute(query) cur.insert_rows(kwargs['table'], rows=df ) connection.commit() print(" Transaction completed successfully ") except (Exception) as error: print('Error in transction', error) connection.rollback() finally: if connection is not None: cursor.close() connection.close() print('PostgreSQL connection is closed')I am getting error this three error.
AttributeError: 'str' object has no attribute 'close' AttributeError: 'str' object has no attribute 'autocommit' AttributeError: 'str' object has no attribute 'rollback'Does anyone knows what is happen here?