2

I am trying to run INSERT INTO SELECT statement in cur.execute. The code executes without any error, but there are no records inserted in the table.

Here is the table data:

enter image description here

I execute the following query,

cursor = conn.cursor()
query = 'INSERT INTO destination_test_hist SELECT * FROM destination_test'
cursor.execute(query)
conn.commit()

Where am I going wrong? I need some assistance

user1584253
  • 975
  • 2
  • 18
  • 55
  • This actually works for me except when I add parameterized criteria. e.g. - curose.execute("select ... where col1 = ?",arg1). – OTM Jun 24 '21 at 20:52

2 Answers2

0

Syntax-wise, I don't see any errors.

Just a few simple things to check to be sure:

Check that your connection is correct and you are checking that server/db, your source table(in this case destination_test) and target table (in this case destination_test_hist) are correct.

I_Tried
  • 41
  • 6
0

Check your database environment and relevant tables in the same. You might have checked the QA test environment maybe or post the query with output of no records with database name and tables.

Also, at programming level it may appear that it might not have got executed in the database do debug the query output what it returns at programming level too.

Himanshu
  • 3,830
  • 2
  • 10
  • 29
  • I have double checked the query, it is running perfectly in hue, inserting records. Regarding programming level, if there is an error in query it does give syntax error (which is fixed) and it returns as successfully executed. No other errors encountered – user1584253 Mar 02 '20 at 05:50