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?

On Apr 5, 2013, at 3:40 PM, Jason H., 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 R.
[email protected]
http://www.elevated-dev.com/
(303) 722-0567 voice

On Friday, 5 April 2013 17:40:35 UTC-4, Jason H., Android developer
wrote:

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. :slight_smile:

–Matt J.