Thanks Sijo,
I ended up using something very similar:
pg_conn = self.connection.instance_variable_get(:@connection)
pg_conn.exec("COPY (#{sql}) TO STDOUT WITH CSV HEADER")
csv = []
while (line = pg_conn.getline) != "\\."
csv << line
end
pg_conn.endcopy
csv.join("\n")
It's a hack but it works for now.
On Jul 11, 1:12 am, Sijo Kg <[email protected]> wrote:
> Hi Can you try like
>
> The following can be moved to lib
>
> moduleActiveRecord
> class Base
> def self.to_csv(sql_statement)
> self.connection.instance_variable_get(:@connection).exec("copy
> (#{sql_statement}) TO STDOUT WITH CSV")
> csv = []
> while (line = pg_conn.getline) != "\\."
> csv << line
> end
> return csv.join("\n")
> end
> end
> end
>
> And can access likeActiveRecord::Base.to_csv(sql_here)
>
> Sijo
> --
> 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 [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
-~----------~----~----~----~------~----~------~--~---