I''d like to get single values from the DB. For example... SELECT COUNT(*) freaks WHERE status=''freaky''; I''m not sure how to approach that in Rails. Seems like ActiveRecord is all about getting an object or array of objects. Of course I could just... Freak.find(:all ...conditions...) and then get the length of the array. But that seems wasteful. Maybe not. Is that what people normally do? Any help would be appreciated. Thanks, Eeby -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Is count_by_sql what you want? Freak.count_by_sql("SELECT COUNT(*) FROM freaks WHERE status=''freaky'') Jarrod Menoube wrote:> I''d like to get single values from the DB. For example... > > SELECT COUNT(*) freaks WHERE status=''freaky''; > > I''m not sure how to approach that in Rails. Seems like ActiveRecord is > all about getting an object or array of objects. > > Of course I could just... > > Freak.find(:all ...conditions...) > > and then get the length of the array. But that seems wasteful. Maybe > not. Is that what people normally do? > > Any help would be appreciated. > > Thanks, > > Eeby-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wes Rogers wrote:> Is count_by_sql what you want? > > Freak.count_by_sql("SELECT COUNT(*) FROM freaks WHERE status=''freaky'')Thanks, it look as though it might be. I''ll try it. Eeby -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
U can do freak.findbystatus and pass in freaky as status Sent from my iPhone On Oct 5, 2007, at 9:43 PM, Jarrod Menoube <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > wrote:> > I''d like to get single values from the DB. For example... > > SELECT COUNT(*) freaks WHERE status=''freaky''; > > I''m not sure how to approach that in Rails. Seems like ActiveRecord is > all about getting an object or array of objects. > > Of course I could just... > > Freak.find(:all ...conditions...) > > and then get the length of the array. But that seems wasteful. Maybe > not. Is that what people normally do? > > Any help would be appreciated. > > Thanks, > > Eeby > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
atpunkt-TM7Dk29TcfyELgA04lAiVw@public.gmane.org
2007-Oct-06 16:40 UTC
Re: How to get atoms of data from the DB
Freak.count(:conditions=>[:status=>''freaky'']) should do it more generic - but more sql-dialect-specific Freak.connection.select_one("SELECT count(*) FROM freaks WHERE status=''freaky'' ") should give you atomic precision. P On 6 Okt., 08:28, Bcp <bcpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> U can do freak.findbystatus and pass in freaky as status > > Sent from my iPhone > > On Oct 5, 2007, at 9:43 PM, Jarrod Menoube <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > > > wrote: > > > I''d like to get single values from the DB. For example... > > > SELECT COUNT(*) freaks WHERE status=''freaky''; > > > I''m not sure how to approach that in Rails. Seems like ActiveRecord is > > all about getting an object or array of objects. > > > Of course I could just... > > > Freak.find(:all ...conditions...) > > > and then get the length of the array. But that seems wasteful. Maybe > > not. Is that what people normally do? > > > Any help would be appreciated. > > > Thanks, > > > Eeby > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
atpunkt-TM7Dk29TcfyELgA04lAiVw@public.gmane.org
2007-Oct-06 16:43 UTC
Re: How to get atoms of data from the DB
Why has google groups no ''Ruby-syntax-check ? Freak.count(:conditions => { :status=>''freaky'' } ) was what I wanted to write On 6 Okt., 18:40, "atpu...-TM7Dk29TcfyELgA04lAiVw@public.gmane.org" <atpu...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Freak.count(:conditions=>[:status=>''freaky'']) should do it > > more generic - but more sql-dialect-specific > > Freak.connection.select_one("SELECT count(*) FROM freaks WHERE > status=''freaky'' ") > > should give you atomic precision. > > P > > On 6 Okt., 08:28, Bcp <bcpar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > U can do freak.findbystatus and pass in freaky as status > > > Sent from my iPhone > > > On Oct 5, 2007, at 9:43 PM, Jarrod Menoube <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > > > > wrote: > > > > I''d like to get single values from the DB. For example... > > > > SELECT COUNT(*) freaks WHERE status=''freaky''; > > > > I''m not sure how to approach that in Rails. Seems like ActiveRecord is > > > all about getting an object or array of objects. > > > > Of course I could just... > > > > Freak.find(:all ...conditions...) > > > > and then get the length of the array. But that seems wasteful. Maybe > > > not. Is that what people normally do? > > > > Any help would be appreciated. > > > > Thanks, > > > > Eeby > > > -- > > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---