Python Forum
Migrating data from oracle into postgres
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Migrating data from oracle into postgres
#1
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?
Reply
#2
.get_uri() returns str.
Probably you mean get_conn()
https://github.com/apache/airflow/blob/5...res.py#L83
python_student likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Load data in Oracle muzokh 0 251 Mar-08-2024, 11:19 PM
Last Post: muzokh
Sad Migrating of python2 script to python3 zuri 7 978 Oct-05-2023, 02:40 PM
Last Post: snippsat
  install apache-airflow[postgres,google] on Python 3.8.12 virtual env ShahajaK 1 7,633 Oct-07-2021, 03:05 PM
Last Post: Larz60+
  Load data from One oracle Table to Multiple tables amy83 1 1,778 Dec-02-2020, 01:57 AM
Last Post: Larz60+
  Migrating to Mysql from SQlite atari400 10 4,612 Nov-23-2019, 09:56 PM
Last Post: atari400
  python and postgres DB SQL execution bluefrog 3 3,704 Jun-21-2018, 01:58 PM
Last Post: wavic
  inserting data into oracle db using python sahilsiddharth 9 19,457 May-22-2017, 08:08 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020