Hi All. I have a mysql statement that I would really really like to call from my Ruby program which goes like this: SELECT a, b, DAYOFWEEK(date_time) as DOW, HOUR(date_time) at hr, AVG(x/y) FROM records; This is possible by creating a 3-dimentional array of a, b, date_time containing x/y, and then finding averages and putting it into a 4-dimensional array of a, b, dow, and hr. _3-dim_array_ a b date_time _4-dim_array_ a b dow hr My reasons for not wanting to do it this way is that there could be 100,000+ records. Also, look at how pretty and compact that the MySql statement is! I would much rather let MySql handle all that because arrays will get very big, and I''m not sure if or how Ruby can handle that. Can someone tell me if I can use the above MySql statement to generate the 4-dimentional array? If not, can someone please help me find a possible solution? Danke in advance! -- Posted via http://www.ruby-forum.com/.
You can always use the raw connection. ActiveRecord::Base.connection.execute See here for more related methods: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#M000625 -Jonathan. On 6/15/06, lisa-u <maneneko@yahoo.com> wrote:> Hi All. > > I have a mysql statement that I would really really like to call from my > Ruby program which goes like this: > > SELECT a, b, DAYOFWEEK(date_time) as DOW, > HOUR(date_time) at hr, > AVG(x/y) > FROM records; > > This is possible by creating a 3-dimentional array of a, b, date_time > containing x/y, and then finding averages and putting it into a > 4-dimensional array of a, b, dow, and hr. > > _3-dim_array_ > a > b > date_time > > _4-dim_array_ > a > b > dow > hr > > My reasons for not wanting to do it this way is that there could be > 100,000+ records. Also, look at how pretty and compact that the MySql > statement is! I would much rather let MySql handle all that because > arrays will get very big, and I''m not sure if or how Ruby can handle > that. > > Can someone tell me if I can use the above MySql statement to generate > the 4-dimentional array? If not, can someone please help me find a > possible solution? > > Danke in advance! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Search the API for find_by_sql It''ll let you generate arbitrary SQL statements and get the results back via ActiveRecord Regards Dave M. On 15/06/06, lisa-u <maneneko@yahoo.com> wrote:> Hi All. > > I have a mysql statement that I would really really like to call from my > Ruby program which goes like this: > > SELECT a, b, DAYOFWEEK(date_time) as DOW, > HOUR(date_time) at hr, > AVG(x/y) > FROM records; > > This is possible by creating a 3-dimentional array of a, b, date_time > containing x/y, and then finding averages and putting it into a > 4-dimensional array of a, b, dow, and hr. > > _3-dim_array_ > a > b > date_time > > _4-dim_array_ > a > b > dow > hr > > My reasons for not wanting to do it this way is that there could be > 100,000+ records. Also, look at how pretty and compact that the MySql > statement is! I would much rather let MySql handle all that because > arrays will get very big, and I''m not sure if or how Ruby can handle > that. > > Can someone tell me if I can use the above MySql statement to generate > the 4-dimentional array? If not, can someone please help me find a > possible solution? > > Danke in advance! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >