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?
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.
Table to JSON: https://dba.stackexchange.com/questions/90482/export-postgres-table-as-json
JSON to yaml: dump json into yaml
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.