Result from ActiveRecord :: Base.connection.execute (sql) - PostgreSQL

How to find the number of records processed by PostgreSQL after executing an SQL statement using the 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 you can suggest a better way to do this. Please keep in mind that the above update statement is simple to keep the question short. My real queries are "installed based" and include complex temp creation tables, updates, insert instructions.

+7
source share
1 answer

Found answer in class PG :: Result. This is the 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 
+4
source

All Articles