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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay