PostgreSQL issue inserting data
Question: i want to insert the data into a `PostgreSQL` database but when i try to
insert data is not stored in the database and error is not generated so I am
unable to find out what the error is, please help

    
    
    #!/usr/bin/python
    
    import psycopg2
    import psycopg2.extras
    import sys
    
    
    con = None
    
    try:
    
        con = psycopg2.connect("dbname='mydb' user='merlin' host='192.168.0.104'  password='merlin123'") 
        cursor = con.cursor(cursor_factory=psycopg2.extras.DictCursor)
    
        cursor.execute("SELECT * FROM table1")
    
        rows = cursor.fetchall()
    
    
    except psycopg2.DatabaseError, e:
        print 'Error %s' % e    
    
    
    finally:
    
        if con:
            con.close()
    
    try:
       con = psycopg2.connect("dbname='mydb2' user='merlin' host='192.168.0.104'") 
       cursor = con.cursor(cursor_factory=psycopg2.extras.DictCursor)
       query = "INSERT INTO table3 VALUES ('%s', '%s', '%d' , %s)" % (raw[0][0], raw[0][1],raw[0][2],0) 
        #while raw!=None:
    
       cursor.execute(query)
       con.commit()
    
    except psycopg2.DatabaseError, e:
        print 'Error %s' % e    
    
    finally:
    
        if con:
            con.close()
        sys.exit(1)
    

Can anyone help solving the error?


Answer: Your problem not seeing the exception stack trace is because you are doing
`sys.exit(1)` in the `finally` clause -- so you are exiting before python has
a chance to display the error.

I would simplify your script a lot (comment out the unnecessary portions) and
then gradually add in the complexity you need if/when you need it.

BTW I think The error will be that `raw` is not defined

