I need to get all affected row count in PostgreSQL . If i run update query then got right row count but if i run again same query then i also get same row count but i think second time no row affected so in this case row count will be 0. Here is my simple code
import psycopg2
#db connection
conn = psycopg2.connect(
host="localhost",
database="test_db",
user="postgres",
password="123456"
)
#Setting auto commit false
conn.autocommit = True
#Creating a cursor object using the cursor() method
cursor = conn.cursor()
sql = "UPDATE test_table SET balance = 11 WHERE last_block = '14529343'"
cursor.execute(sql)
print("Rows returned = ",cursor.rowcount)
conn.commit()
conn.close()
#Closing the connection
After run this python script my current row affected is:
Rows returned = 70
second time also same output
Rows returned = 70 but it is not correct, result will be 0
but if i run same update query then same result but in this case output will be 0.
This is screenshot

updatethat does not change anything used in thewhereclause. Since yourwhereclause references only a specificlast blockbut does not change that value any subsequent run of the same query will process exactly the same rows, giving the same count every time. Perhaps you need to add the predicateand balance <> ....