Quantcast
Channel: User Dmytro Biletskyi - Stack Overflow
Viewing all articles
Browse latest Browse all 39

Answer by Dmytro Biletskyi for Trying to insert 1_000_000 records in db using Ecto Elixir

$
0
0

To insert same row into DB you can use raw SQL. We can generate data to insert from select creating data we need and multiply it with generate_series() function.

This way we will be generating just one query to DB and don't need to transfer 3kk values.

query = """INSERT INTO users (points, inserted_at, updated_at)SELECT   0, now(), now()FROM   generate_series(1, 1000000);"""Ecto.Adapters.SQL.query!(Remote.Repo, query, [])

Viewing all articles
Browse latest Browse all 39

Latest Images

Trending Articles





Latest Images