Postgresql – Create a quick report for a client

amazon-rdsawspostgresql

I have an Amazon RDS (postgres) database and an client asked me to have access to certain data stored in this database preferably in the form of a comma separated file. If the data changes, the client would like his report to represent the new state of the data.

What would be the text book way of providing this?

I was thinking about creating a view and granting them access to only this view.

Best Answer

Since you mentioned your client wanted a comma separated file as a report, you could always do something like:

psql -U myuser -h my.rds.external.address -c "\copy (SELECT * FROM mytable WHERE foo = 'bar') TO 'my_report.csv' WITH CSV HEADER NULL AS ''"

If you run that from a command line or a cron job from another machine (once you've allowed that IP address in your RDS instance configuration), you can just compress it and make it available to your client based on their needs.

A view would also work if you wanted to give them realtime access to the data instead of a comma separated report.