Jason Hsu, Android developer
2013-Apr-05 21:40 UTC
Exporting a Postgres database to CSV without superuser privileges
How do you export a Postgres database to CSV when you do NOT have superuser privileges? The line of code in question (for my Bargain Stock Funds project at https://github.com/jhsu802701/bsf-scrape/blob/master/scrape.rb) is: @conn.exec("COPY funds TO ''" + csv_path + "'' With CSV HEADER;") I need superuser access in order to run this code. This is OK in the development environment, because I used my root privileges (through sudo) to give my username superuser status for Postgres. However, this does not work in the production environment. where so my username doesn''t have superuser status. Is there another way to create a CSV file from a Postgres database? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/eT-wyynLbSgJ. For more options, visit https://groups.google.com/groups/opt_out.
Scott Ribe
2013-Apr-06 02:49 UTC
Re: Exporting a Postgres database to CSV without superuser privileges
On Apr 5, 2013, at 3:40 PM, Jason Hsu, Android developer wrote:> I need superuser access in order to run this code.No you don''t. You need select privileges on the table, and write permissions in the output directory. -- Scott Ribe scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org http://www.elevated-dev.com/ (303) 722-0567 voice -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Matt Jones
2013-Apr-08 21:22 UTC
Re: Exporting a Postgres database to CSV without superuser privileges
On Friday, 5 April 2013 17:40:35 UTC-4, Jason Hsu, Android developer wrote:> > How do you export a Postgres database to CSV when you do NOT have > superuser privileges? > > The line of code in question (for my Bargain Stock Funds project at > https://github.com/jhsu802701/bsf-scrape/blob/master/scrape.rb) is: > > @conn.exec("COPY funds TO ''" + csv_path + "'' With CSV HEADER;") > > I need superuser access in order to run this code. This is OK in the > development environment, because I used my root privileges (through sudo) > to give my username superuser status for Postgres. > > However, this does not work in the production environment. where so my > username doesn''t have superuser status. > > Is there another way to create a CSV file from a Postgres database? >It would far more portable to output a CSV directly using the CSV library (iterating over the results yourself) - also allows for formatting, etc. On a related note, you may want to look into something like Ruby''s Struct or attr_accessors rather than writing a giant ball of Java-flavored Ruby like your Firm class. :) --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/HJHDAix3U3AJ. For more options, visit https://groups.google.com/groups/opt_out.