tomekowal

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

josevalim

Creator of Elixir

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

katheleen

That is great solution! Awesome advice.

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
shijith.k
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement