Search code examples
sqlpostgresqlcsvherokuheroku-postgres

SQL syntax error when using Heroku dataclips to export PostgreSQL database into csv


I have a Rails app on Heroku that i'm currently testing to ensure that I can download the information it gathers. I've managed to get PostgreSQL 9.3.5 working and can even get it to spit out a public url to an unreadable dump file, but I want to export a particular table into a CSV that is easier to understand so that I can gather the data.

I've been looking into Heroku Dataclips. The documentation says that this is possible, but doesn't explain how. This site seemed to give some tips on SQL inputs: http://www.gistutor.com/postgresqlpostgis/10-intermediate-postgresqlpostgis-tutorials/39-how-to-import-or-export-a-csv-file-using-postgresql-copy-to-and-copy-from-queries.html

So I entered this into Dataclips:

COPY participations(user_full_name, user_email, event_name, event_date_time)
TO '/usr/local/pgsql/data/csv/event_registrations.csv'
WITH DELIMITER ‘,’
CSV HEADER

However, I get this error:

Your query couldn't be created.
ERROR:  syntax error at or near "COPY"
LINE 2: COPY participation(user_full_name, user_email, event_name, e...
    ^

How can I fix this? Maybe the reference i'm using is wrong, because I don't see the difference between what i'm doing and what's there.

FWIW, i'm using Cloud9 IDE as my terminal.


Solution

  • According to Heroku support, this is what you need to put in a Dataclip if you want to get all the records from a particular table:

    SELECT * from table_name;
    

    Once you create your Dataclip, you will have the option through the Dataclips interface to download the results as a CSV.