DEV Community

Cover image for Exporting a large PostgreSQL table using Python

Exporting a large PostgreSQL table using Python

Varun Gujarathi on October 16, 2023

When working with large datasets, it's common to extract PostgreSQL tables to CSV files for further analysis and sharing. However, naively exportin...
Collapse
 
amankrokx profile image
Aman Kumar • Edited

\COPY my_table TO 'filename' CSV HEADER

Collapse
 
hawkaj profile image
Aarya Jha

hey could you also elaborate on how can we control the chunk size being processed here?

Collapse
 
varungujarathi9 profile image
Varun Gujarathi

There is no built-in method to control the chunk size. The COPY protocol itself focuses on efficient bulk data transfer. If you DO want to control you can change the config on the PostgreSQL server OR iterate through your data in loops.