K
K
Karina2015-04-25 17:29:24
Ruby on Rails
Karina, 2015-04-25 17:29:24

How to display the result of SQL execution?

There is a very long request. I do not quite understand what it does - it is necessary to display its results in portions. It starts like this: Ends: Then, of course, this data is transmitted:
sql = <<-SQL
SQL

ActiveRecord::Base.connection.select_values(sql).map(&:to_i).uniq

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jeiwan, 2015-04-26
@Jeiwan

<<-SQL ... SQL is a multiline form of writing SQL queries.
Execute the query: ActiveRecord::Base.connection.execute(sql)
ActiveRecord::Base.connection.select_values(sql).map(&:to_i).uniq - this code also executes the query, but takes only the values ​​of the first column (id' shniks?), converts them into numbers and removes duplicates.
And in order to break the query into parts and display it in parts, you need to know SQL and manually parse it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question