Dino
Posted on November 17, 2019
Ever wanted to export data from the PostgreSQL table into a JSON file?
👇
pg_cmd="\\copy (select row_to_json(r) from (select * FROM table_name) r ) to
table.json"
psql -w -h host -U username -d database_name -c $pg_cmd
sed -i -e 's/\\\\/\\/g' table.json # clean up extra '\' characters
After executing these commands you will have two JSON files
- table.json - initial JSON exported data file
-
table.json-e - file which contains cleaned up JSON, without extra
\
characters
✌️
💖 💪 🙅 🚩
Dino
Posted on November 17, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
docker DOCKER and DOCKER COMPOSE: Run Dependencies Without Installing Them in Your Environment
November 30, 2024
undefined SQL: Identify associated member groups without common points of association #eg82
November 29, 2024
undefined Two-Factor Authentication Using Better_Auth, Next.js, Prisma, ShadCN, and Resend
November 29, 2024