DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 963,503 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Hugo Martins
Hugo Martins

Posted on • Originally published at on

Extracting Data from PostgreSQL

PostgreSQL has an excellent module built specifically for the purpose of extracting data between a file and a table.

This can be used to extract several data in three formats:- Text- CSV- Binary

Sometimes you’d want to extract data to a folder different than the one the database is in. You’d want to extract the data to the machine your logged on instead. This can be done using \copy instead of COPY.

An example of basic usage for extracting data would be, in CSV:

\copy (SELECT * FROM foo WHERE bar IS NOT NULL) TO '/path/to/folder' HEADER CSV

Enter fullscreen mode Exit fullscreen mode

This simple snippet is incredibly useful to generate reports or extract data for analysis, simply and quickly.

Source: -

Originally published at on October 10, 2016.

Latest comments (0)

Update Your DEV Experience Level:


Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠