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

Top comments (0)