From 2791a8cfb8fe95b2d9f393b8ed578b4aaaeda87a Mon Sep 17 00:00:00 2001 From: ruslan Date: Wed, 11 Sep 2024 17:24:44 +0200 Subject: [PATCH] Create psql-to-csv.md --- content/posts/psql-to-csv.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 content/posts/psql-to-csv.md diff --git a/content/posts/psql-to-csv.md b/content/posts/psql-to-csv.md new file mode 100644 index 0000000..cd0f34e --- /dev/null +++ b/content/posts/psql-to-csv.md @@ -0,0 +1,20 @@ +--- +title: Конвертация PostgreSQL в CSV +description: pSQL to CSV +date: 2024-09-11T17:24:00+02:00 +tags: [linux, postgres] +--- +## Конвертация +```bash +psql -d +``` +```psql +DO $$ +DECLARE + r RECORD; +BEGIN + FOR r IN (SELECT table_name FROM information_schema.tables WHERE table_schema = 'public') LOOP + EXECUTE format('COPY %I TO %L WITH (FORMAT CSV, HEADER)', r.table_name, '/path-to-csv/' r.table_name '.csv'); + END LOOP; +END $$; +```