Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 868
mevdiven Avatar asked Dec 27 '12 05:12

mevdiven


1 Answers

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
like image 113
mevdiven Avatar answered Oct 15 '22 20:10

mevdiven