1

I am working in django and trying to figure out how to export a table i have in my database to a yaml file, but cant find the solution to it..probably some simple change.. Right now i have a written a bash to export my customer table to a CSV file that works fine:

export_customer.sh

echo "Enter the directory path to save the file"
read path_to_save
file_name="myFile.csv"

psql --dbname=mydb --host=localhost --username=mydb -c "COPY
(
select name, id from customers
) to stdout DELIMITER ',' CSV HEADER" > "${path_to_save}/${file_name}"

My customer table look something like this:

id             name
-------------------
 1             xxxxx
 2             yyyyy

Does anyone now how to export this into a yaml file instead?

Michael
  • 35
  • 6

1 Answers1

1

This might be a bit roundabout but if you don't care about performance, you can export your table to a JSON and then convert the JSON to a yaml.

  1. Table to JSON: https://dba.stackexchange.com/questions/90482/export-postgres-table-as-json

  2. JSON to yaml: dump json into yaml

Aziz Sonawalla
  • 2,482
  • 1
  • 5
  • 6
  • 1
    Yes to go that way seems easy, how thought about it before, but were hoping to find a more direct way to solve it. Thx anyway Aziz – Michael Sep 02 '20 at 06:17