On Jul 10, 2009, at 1:27 PM, gsterndale wrote:

>
> Thanks Philip,
>
> The Postgres gem rdoc hasn't been much help.  All of the PGresult
> instance methods that retrieve values require a tuple number. My
> PGresult has a number of fields, but not tuples (rows).
>
> This query (when run in psql) returns a large block of text. For
> example:
> email,fname,lname,created_at
> [email protected],Foo,Fooster,2009-07-07 17:00:41.929865
> [email protected],Bar,Barbie,2009-07-01 20:31:08.659965
> [email protected],User,User,2009-07-07 20:33:53.293606
> [email protected],Admin,Admin,2009-07-07 20:33:53.760538
>
> I agree 100% that using FasterCSV and ActiveRecord to pull the data is
> much more portable (and elegant). In fact, that's how I'm doing it
> now. However, this is a huge dataset that is causing server timeouts
> and hogs memory. I'm investigating csv generation in Postgres as it
> takes a fraction of the time and resources because each object isn't
> getting instantiated.
>
> Any thoughts?
>

Skip AR and use the select_values() call perhaps. That will skip any  
object instantiation at least.





> On Jul 10, 4:07 pm, Philip Hallstrom <[email protected]> wrote:
>>> I'm using ActiveRecord's connection to execute a custom query (which
>>> runs fine in psql) like this:
>>
>>>>> result = ActiveRecord::Base.connection.execute("COPY (select *
>>>>> from users) TO STDOUT WITH CSV;")
>>>  SQL (0.8ms)   COPY (select * from users) TO STDOUT WITH CSV;
>>> => #<PGresult:0x2589ad8>
>>>>> result.nfields
>>> => 39
>>>>> result.ntuples
>>> => 0
>>
>>> An instance of PGresult is returned. How can I get data out of it?
>>
>> Load up the rdocs for the postgres gem... it will tell you.... but  
>> why
>> do it this way?  Why not use AR to get your records and fastercsv to
>> convert it to CSV?  Much more portable...
> >


--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to