tomekowal
Problem with a query when upgrading from Ecto 3.5.0
I have this query that worked in Ecto 3.4.6 but does not work in Ecto 3.5.0 or later
EDIT: I wrongly assumed that setting ecto_sql at 3.5.0 also sets ecto at 3.5.0 but it was higher.
from cm in q,
where:
not exists(
fragment(
"""
SELECT *
FROM member_tag_assignments
WHERE tag_id = ANY(?) AND club_member_id = ?
""",
type(^secondary_lookup.tag_ids, {:array, :binary_id}),
cm.id
)
)
After upgrade it says:
== Compilation error in file lib/clubbase/club_member_search/club_member_search.ex ==
** (CompileError) lib/clubbase/club_member_search/club_member_search.ex:339: cannot use ^secondary_lookup.tag_ids outside of match clauses
I understand that Elixir thinks it is outside of query but I don’t know why. I have import Ecto.Query at the top. Other queries work OK - only that particular combination of exists and fragment is problematic.
The exists is custom
defmacro exists(arg) do
quote do: fragment("EXISTS(?)", unquote(arg))
end
because it was not yet available back in 3.5
I also tried assigning extracting tag_ids to a variable so that I am not using . inside type but it doesn’t make a difference.
I can’t pinpoint what happened in 3.5 that breaks the query.
Most Liked
josevalim
The error message seems to indicate that Elixir is not expanding the from correctly. So Elixir then proceeds to expand the arguments and find an invalid ^.
Last Post!
katheleen
Popular in Questions
Other popular topics
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









