I have a few tables in the database in a Hasura cluster. I want to export one them as a CSV file (with the data). How can I do this?
You can follow one of the following methods:
Connect to the database and use psql
to export data as CSV:
a) Directly access the underlying Postgres db instance:
hasura microservice port-forward postgres -n hasura --local-port 6432
b) follow this SO question to actually export data as a CSV file (assumes you have psql
installed).
Use the data APIs to write a simple service that can convert JSON to CSV and save it to a file.
Hasura exposes and API endpoint for accessing pg_dump of the underlying database.
https://hasura.io/docs/1.0/graphql/core/api-reference/pgdump.html#pg-dump-api-reference
curl --location --request POST 'https://<hasura-hostname>/v1alpha1/pg_dump' --header 'x-hasura-admin-secret: <password>' --header 'Content-Type: application/json' --data-raw '{ "opts": ["-O", "-x", "--schema", "public", "--schema", "auth"], "clean_output": true}' -o backup.sql
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.