![]() |
Migrating data from oracle into postgres - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Migrating data from oracle into postgres (/thread-36359.html) |
Migrating data from oracle into postgres - python_student - Feb-10-2022 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? RE: Migrating data from oracle into postgres - buran - Feb-10-2022 .get_uri() returns str.Probably you mean get_conn() https://github.com/apache/airflow/blob/5a6a2d604979cb70c5c9d3797738f0876dd38c3b/airflow/providers/postgres/hooks/postgres.py#L83 |