# Inserting CSV into postgres

**URL:** <https://forum.elixirforum.com/t/inserting-csv-into-postgres/3606>\
**Category:** Questions\
**Tags:** ecto, streams\
**Created:** [February 8, 2017, 4:58pm UTC](https://forum.elixirforum.com/t/inserting-csv-into-postgres/3606 "2017-02-08T16:58:42Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![sabri](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sabri/32/9683_2.png) [@sabri](https://forum.elixirforum.com/u/sabri)\
**Post date:** [February 8, 2017, 7:23pm UTC](https://forum.elixirforum.com/t/inserting-csv-into-postgres/3606/5 "2017-02-08T19:23:37Z")

</div>

Yea, if I need one second for each individual row to insert, it would take hours to complete..  
So, as for the link provided, how would I refactor their example below, so that it will be feeded by the CSV.decode in my code above?

> Postgrex.transaction(pid, fn(conn) →   
> query = Postgrex.prepare!(conn, “”, “COPY users TO STDOUT;”)  
> Postgrex.stream(conn, query, )  
> |\> Enum.into(File.stream!(“users”), fn(%Postgrex.Result{rows: rows}) → rows end)  
> end)

But, then, I will lose validation as you mentioned? any work arround for possible errors to handle?

Thanks for valuable help!

---

_[View the full topic](https://forum.elixirforum.com/t/inserting-csv-into-postgres/3606)._
