spapas
Hello,
the where macro (among others) gets an array of query positions as an argument ie query |> where([c0, c1, c2], c2.name = 32). How could I create the array of named bindings [c0, c1, c2] and the actual binding (c2) dynamically ? For example I lets say I have something like {name: 2} and I’d like to get both [c0, c1, c2] and c2.name=32 (or field(c2, ^“name”) in order to create a dynamic filter. Is this even possible? Do I need to use macros? Can somebody point me to the correct direction.
Thank you
Trending in Questions
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #security
- #elixirconf-eu
- #processes
- #api
- #forms
- #hex











Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
wolfiton
i don’t know if you found this thread yet Dynamic Queries in Ecto
If not dynamic ecto queries may be your answer.
spapas
Hello @wolfiton yes I’m aware of
dynamican I’ve used it in other situations, however this is not what I want for this. I’d just like some pointers on how I could implement my requirement.One other way to describe what I want are two functions (or macros) like
and
which I could call in the bindings in the
wherefunction i.e something likeand this would be transformed to
Is this maybe better explained ?
wolfiton
Hello,
Yes it is more clear now.
peerreynders
While you’ve explained how you want to do it - it’s not clear why you would want to do it in this particular fashion.
I’m just mentioning this because in many use cases it makes sense to switch away from positional bindings and use named bindings instead - that is, any binding that may need to be referenced later in a composition is named so that it can be referenced by name rather than position later.
spapas
@peerreynders yes I guess I fell into the trap of asking of a way to implement the solution I had in my mind than describing the actual problem
I more or less want to create a dynamic query filtering mechanism. For example, I’ve got the following query:
and I want to filter on various fields from all relations
(w, b, a, ak).Now in non-dynamic case, I’ll create a schemaless changeset using something like
and finally retrieve the changes from the changeset and filter on the initial query:
This works fine however it is a lot of work to do all this again and again for all my filters.
So instead I thought of modeling the filters I’d need for each query using a simple structure like:
– please notice that the
posdefines the position in the named query i.estatusis forWithholding(pos 0) whileafmis forBeneficiary(pos 1) –and then do something like:
So now the problem is that I have the initial query which is passed to
QueryFilterEx.filterand I want to dynamically filter it using thefiltersstruct I defined before to add where clauses to it. This leads me to the problem I described in my 1st and 2nd postAlso, concerning named bindings i really don’t think that it would solve my problem because I still wouldn’t be able to dynamically construct the aliases of the bindings in the where clauses.
BR,
Serafeim
spapas
After some clarifications on the elixir-lang IRC channel from @josevalim it seems that @peerreynders suggestion was correct. Using named bindings can solve this problem!
So, if you have a query with proper named bindings you can pass them to your filter specification in order to be used when querying. Here’s a small snippet on how you can such dynamic filters:
Thank you very much for helping with this !