Fork me on GitHub
#sql
<
2023-09-19
>
Bingen Galartza Iparragirre13:09:29

Hi. I'm working on a query that can potentially return thousands of rows. The goal is to write the result into a CSV file. I guess that next.jdbc/plan is the way to go, but I'm not sure what to do with the Reducible that it returns. All the examples that I find (using reduce, transduce, etc) are transforming or aggregating the data. But in my case I just want to write the data to a file and immediately discard it. So I wonder if I'm in the right path. Any hints?

seancorfield15:09:33

Use reduce. The "transform" will write a row to the csv file (and can return nil). You could probably use run! That uses reduce under the hood.

Bingen Galartza Iparragirre15:09:47

That sounds good! Thanks

igrishaev16:09:37

If it’s Postgres, you can use CopyManager and redirect any query into a csv tream

Bingen Galartza Iparragirre07:09:05

Thanks for the suggestion igrishaev. Already implemented it using next.jdbc/plan, and works like a charm for our use case. But it's good to know there are more options.