How do I use `Explain` with a `find_by_sql` query?

Terence Chow

User.find_by_sql("...my statement here...").explain

results in an error undefined method explain for array... which makes perfect sense to me...

I'm not using rails. I'm using sinatra although that should not matter since the commands come from the activerecord gem which I am using...

Any suggestions?

kiddorails

Error is pretty self-explanatory.

You can only run explain on ActiveRecord::Relation objects. But find_by_sql gives you an Array instead, on which explain cannot be called.

You have two ways to work around this:

  1. Convert your query with ActiveRecord methods (which return Relation)
  2. Use explain inside your find_by_sql string.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I use `Explain` with a `find_by_sql` query?

From Dev

My query is not using my indexes, how do i use explain plan and fix this slow query with MySQL

From Dev

How to secure query from sql injection in find_by_sql in Rails

From Dev

Activerecord: how to query using find_by_sql and include with a variable

From Dev

How do I explain 'main()'?

From Dev

How do I use values as a column headers in a SQL Server Query

From Dev

How do I use an SQL Query Result as the value of a variable in Java?

From Dev

How do I use session variables within a SQL query?

From Dev

How to use $query, $hint or $explain from Java

From Dev

How do I view the Explain Plan in Oracle Sql developer?

From Dev

How do I do this sql select query?

From Dev

Rails - how to protect against sql injection for a postgres find_by_sql query?

From Dev

How do I find the average of the result of a group by SQL query?

From Dev

How do I write an SQL query in c# to find DateTime?

From Dev

How do I explain Identifer Expected

From Dev

How do I explain the contents of the profile file

From Dev

scheme - How do i explain an output like this?

From Dev

How to use Spark Sql to do recursive query

From Dev

How do I use Slice operator and specify the fields to return by Find query?

From Dev

How do I use a wild card in the middle of an sql server like query

From Dev

(SQL) In a query, how do I use a CASE statement that would only conditionally require a JOIN?

From Dev

How do I use a Function to assign values to an Array from an SQL Query

From Dev

How do I use a form to change the SQL query to only display registered dates between a specific range?

From Dev

How do I export a SQL query into SPSS?

From Dev

How do I write this sql query

From Dev

How do I create a conditional SQL query

From Dev

How do I count this SQL query?

From Dev

How do I improve this SQL query?

From Dev

How do I solve this SQL Query?

Related Related

  1. 1

    How do I use `Explain` with a `find_by_sql` query?

  2. 2

    My query is not using my indexes, how do i use explain plan and fix this slow query with MySQL

  3. 3

    How to secure query from sql injection in find_by_sql in Rails

  4. 4

    Activerecord: how to query using find_by_sql and include with a variable

  5. 5

    How do I explain 'main()'?

  6. 6

    How do I use values as a column headers in a SQL Server Query

  7. 7

    How do I use an SQL Query Result as the value of a variable in Java?

  8. 8

    How do I use session variables within a SQL query?

  9. 9

    How to use $query, $hint or $explain from Java

  10. 10

    How do I view the Explain Plan in Oracle Sql developer?

  11. 11

    How do I do this sql select query?

  12. 12

    Rails - how to protect against sql injection for a postgres find_by_sql query?

  13. 13

    How do I find the average of the result of a group by SQL query?

  14. 14

    How do I write an SQL query in c# to find DateTime?

  15. 15

    How do I explain Identifer Expected

  16. 16

    How do I explain the contents of the profile file

  17. 17

    scheme - How do i explain an output like this?

  18. 18

    How to use Spark Sql to do recursive query

  19. 19

    How do I use Slice operator and specify the fields to return by Find query?

  20. 20

    How do I use a wild card in the middle of an sql server like query

  21. 21

    (SQL) In a query, how do I use a CASE statement that would only conditionally require a JOIN?

  22. 22

    How do I use a Function to assign values to an Array from an SQL Query

  23. 23

    How do I use a form to change the SQL query to only display registered dates between a specific range?

  24. 24

    How do I export a SQL query into SPSS?

  25. 25

    How do I write this sql query

  26. 26

    How do I create a conditional SQL query

  27. 27

    How do I count this SQL query?

  28. 28

    How do I improve this SQL query?

  29. 29

    How do I solve this SQL Query?

HotTag

Archive