Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dump subset of table

Tags:

postgresql

I want to dump a subset of a table of my postgres database. Is there a way to dump a SELECT statement without creating a view?

I need to copy a part of the table to an other postgres database.

like image 698
guettli Avatar asked Aug 08 '12 08:08

guettli


People also ask

How do I dump a table in PostgreSQL?

Right-click on a table and select backup option. In Dump Option window, you can find an option like backup Only schema, backup Only Data. Enter your file name path, select backup mode as plain text and take the backup of your table. You can restore this table in any database.

What is pg_dump in PostgreSQL?

pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently. pg_dump does not block other users accessing the database (readers or writers). pg_dump only dumps a single database.

Where is pg_dump file stored?

sql , which uses the plain or SQL format, the pg_dump command does not store any file anywhere. It just sends the output to STDOUT , which is usually your screen, and it's done. But in your command, you also told your shell (Terminal, Command prompt, whatever) to redirect STDOUT to a file.


1 Answers

Use COPY to dump it directly to disk.

Example (from the fine manual) using a SELECT:

COPY 
(SELECT * FROM country WHERE country_name LIKE 'A%') 
TO '/usr1/proj/bray/sql/a_list_countries.copy';
like image 73
Frank Heikens Avatar answered Sep 29 '22 15:09

Frank Heikens