Dynamic string ecto query?

I am trying to find duplicatemobile_number that starts with “+” in the same table as:

Repo.all(from p in Parent, join: ps in PlusParent, where: ps.mobile_number == ^"+#{p.mobile_number}")

I am doing a join on the same table, but when I run the query I get error:

undefined function p/0
    (stdlib) lists.erl:1338: :lists.foreach/2
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1

the error is because of:

where: ps.mobile_number == ^"+#{p.mobile_number}"

how can I use p inside dynamic string within query as above?

Use a fragment. Since your p is a table and not a binding you need to do it on the SQL side, not the Elixir side, hence fragment. :slight_smile:

The ^ pin operator is only for binding with Elixir things, not operating on SQL things. :slight_smile: