fruworg.github.io/content/posts/psql-to-csv.md

21 lines
487 B
Markdown
Raw Normal View History

2024-09-11 18:24:44 +03:00
---
title: Конвертация PostgreSQL в CSV
description: pSQL to CSV
date: 2024-09-11T17:24:00+02:00
tags: [linux, postgres]
---
## Конвертация
```bash
psql -d <database>
```
```psql
DO $$
DECLARE
r RECORD;
BEGIN
FOR r IN (SELECT table_name FROM information_schema.tables WHERE table_schema = 'public') LOOP
2024-09-13 13:34:35 +03:00
EXECUTE format('COPY %I TO %L WITH (FORMAT CSV, HEADER)', r.table_name, '/<path-to-csv>/' || r.table_name || '.csv');
2024-09-11 18:24:44 +03:00
END LOOP;
END $$;
```