How can I find number of records processed by PostgreSQL after executing a SQL statement using ActiveRecord::Base Connection class?
temp_sql = "UPDATE table_a SET column_a ='abc' WHERE column_b = 1"
result = ActiveRecord::Base.establish_connection(@db).connection.execute(temp_sql)
Or can you suggest better way to do this. Please keep in mind that above update statement is a simple one to keep question brief. My real queries are "set based" and involves complex create temp tables, update, insert statements.
Found the answer in PG::Result class. It is cmd_tuples
method;
temp_sql = "UPDATE table_a SET column_a ='abc' WHERE column_b = 1"
result = ActiveRecord::Base.establish_connection(@db).connection.execute(temp_sql)
number_of_records = result.cmd_tuples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With