Notes: Exporting data through pgcli/mycli

Antony Amirtha Raj
Francium Tech
Published in
1 min readFeb 26, 2018

--

We at Francium love to use lean database clients to connect to databases. We enjoy using pgcli. It is a python based, open source postgres client for those willing to use lean and simple but powerful tool.

Often we are required to export data as csv so that the other party may import the csv data onto their local database. So the following command could export the data to csv pretty quickly.

emp_db> \copy (select first_name, last_name, email from employees) TO '~/Downloads/hello.csv' WITH (FORMAT CSV, HEADER)

And for, mycli

\T csv
\o ~/Downloads/hello.csv
select first_name, last_name, email from employees;

So simple, isn’t it?

Francium Tech is a technology company laser focussed on delivering top quality software of scale at extreme speeds. Numbers don’t scare us. If you have any requirement or want a free health check of your systems architecture, feel free to shoot an email at contact@francium.tech, we will get in touch!

--

--