SELECT data into file
suggest changeYou can copy a table to a file. COPY runs on the server and writes a path on the server. The role needs permission to write server files.
postgres=# select * from my_table;
c1 | c2 | c3
----+----+----
1 | 1 | 1
2 | 2 | 2
3 | 3 | 3
4 | 4 | 4
5 | 5 |
(5 rows)
postgres=# COPY my_table TO '/home/postgres/my_table.txt' WITH (FORMAT csv, DELIMITER '|', NULL 'null_string', HEADER);
COPY 5
postgres=# \! cat my_table.txt
c1|c2|c3
1|1|1
2|2|2
3|3|3
4|4|4
5|5|null_string
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents