update query with cursor.executemany() gives 0 rows updated, DPY-4009 or DPY-2010 #126
-
Hi, I have a list of lists to use for update query -> Note the elements are the same type (str). query = '''update table set colx = :2 where coly = :1''' If i put brackets around chunk variable like shown below: the following error is displayed: On the other hand, in case i use mixed types of data in the list of lists where first element in int64 and the second is string as shown below: query = '''update table set colx = :2 where coly = :1''' The code is executed without errors and 0 rows are updated. In the end when i wrap chunk variable with brackets and use mixed types of data inside list (int64, str) I get Can someone help with this one? is it possible that list of list causing this issue? Here is suggested to use list of tuples -> https://cx-oracle.readthedocs.io/en/latest/user_guide/batch_statement.html BR, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
There may be an issue in how you perceive bind by position works. In your case the value of ":2" will be the first element of your array and ":1" will be the second element of your array. Bind by position works from left to right and pays no attention to the name of the bind variable. If I create a table and populate it with this code: create table disc_126 (
colx varchar2(50) not null,
coly varchar2(50) not null
);
insert into disc_126 values ('UNSET', '228024357162572');
insert into disc_126 values ('UNSET', '228023553168747');
insert into disc_126 values ('UNSET', '228024356695672');
commit; Then this code: chunk = [
['202211231855235525', '228024357162572'],
['202209131156285076', '228023553168747'],
['202101211532410542', '228024356695672']
]
query = "update disc_126 set colx = :2 where coly = :1"
cursor.executemany(query, chunk, arraydmlrowcounts=True)
print("row count:", cursor.rowcount)
print("dml row counts:", cursor.getarraydmlrowcounts()) displays the following output:
Note the use of the array DML row counts feature. This will return an array of the number of rows updated for each element of the input array. This is optional, but can be useful in some situations, so I thought I would include it. |
Beta Was this translation helpful? Give feedback.
-
Hi @anthony-tuininga , Yes! That was the root cause. I guess i have never used "mixed" positional bindings in my scripts before. :) Thanks for a prompt feedback! :) BR, |
Beta Was this translation helpful? Give feedback.
There may be an issue in how you perceive bind by position works. In your case the value of ":2" will be the first element of your array and ":1" will be the second element of your array. Bind by position works from left to right and pays no attention to the name of the bind variable.
If I create a table and populate it with this code:
Then this code: