Python Forum

Full Version: Migrating data from oracle into postgres
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
.get_uri() returns str.
Probably you mean get_conn()
https://github.com/apache/airflow/blob/5...res.py#L83