MEHUL.JAIN
Insert into Select from Unnest
I have a use case where I want to insert large number of rows in PG Table at once from Ecto. But ecto has a param limit of 65_535, so the max rows I can insert is 65_535 / tot_number_of_fields_in_schema.
To overcome this, I am trying to see if I can to
Repo.insert_all(Schema, query)
query = from(c in Ecto.Query.fragment("SELECT * FROM unnest(? as field1, ? as field2"), ^field1_array, ^field2_array)
The idea here is, the total params will be 2 in this case
-- before
INSERT INTO users
(id, name)
VALUES ($1,$2),($3,$4);
-- after
INSERT INTO users
(id, name)
(select * from unnest($1::int[], $2::int[]));
Most Liked
LostKobrakai
Last Post!
MEHUL.JAIN
I have done this:
"d"
|> with_cte("d", as: fragment("SELECT * FROM unnest(ARRAY[1]::int[], ARRAY[2]::int[]) as x(a, b)"))
|> select([d], %{a: d.a})
But how do I remove prefix from cte query? I have a multi tenant/schema application, so I need prefix when I would try to do
DBWrapper.insert_all(SchemaModule, query)
0
Popular in Questions
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









