Check out example codes for "copying query result to excel". It will help you in understanding the concepts better.

Code Example 1

COPY (SELECT * FROM tracks WHERE genre_id = 6) TO '/Users/dave/Downloads/blues_tracks.csv' DELIMITER ',' CSV HEADER;

Learn ReactJs, React Native from akashmittal.com