For a data-only export use COPY
.
You get a file with one table row per line as plain text (not INSERT
commands), it's smaller and faster:
COPY (SELECT * FROM nyummy.cimory WHERE city = 'tokio') TO '/path/to/file.csv';
Import the same to another table of the same structure anywhere with:
COPY other_tbl FROM '/path/to/file.csv';
COPY
writes and read files local to the server, unlike client programs like pg_dump
or psql
which read and write files local to the client. If both run on the same machine, it doesn't matter much, but it does for remote connections.
There is also the \copy
command of psql that:
Performs a frontend (client) copy. This is an operation that runs an SQL
COPY
command, but instead of the server reading or writing the specified file, psql reads or writes the file and routes the data between the server and the local file system. This means that file accessibility and privileges are those of the local user, not the server, and no SQL superuser privileges are required.