DEV Community

Shaikh Al Amin
Shaikh Al Amin

Posted on

postgres create csv from select command

BEGIN; -- Start a transaction


\COPY (SELECT * FROM addresses) TO '/var/www/html/backups/addresses.csv' WITH CSV HEADER;

\COPY (SELECT * FROM carts) TO '/var/www/html/backups/carts.csv' WITH CSV HEADER;

\COPY (SELECT * FROM categories) TO '/var/www/html/backups/categories.csv' WITH CSV HEADER;

\COPY (SELECT * FROM failed_jobs) TO '/var/www/html/backups/failed_jobs.csv' WITH CSV HEADER;

\COPY (SELECT * FROM orders) TO '/var/www/html/backups/orders.csv' WITH CSV HEADER;

\COPY (SELECT * FROM products) TO '/var/www/html/backups/products.csv' WITH CSV HEADER;

\COPY (SELECT * FROM profiles) TO '/var/www/html/backups/profiles.csv' WITH CSV HEADER;

\COPY (SELECT * FROM storage_files) TO '/var/www/html/backups/storage_files.csv' WITH CSV HEADER;

\COPY (SELECT * FROM users) TO '/var/www/html/backups/users.csv' WITH CSV HEADER;

\COPY (SELECT * FROM wishlists) TO '/var/www/html/backups/wishlists.csv' WITH CSV HEADER;


COMMIT; -- End the transaction
Enter fullscreen mode Exit fullscreen mode

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay