So this appears to work:
defmacro exists_frag(table) do
arguments = ["EXISTS (
SELECT 1
FROM #{table} a
WHERE a.my_column = ?
)", (quote do: x.id)]
quote do: fragment(unquote_splicing(arguments))
end
def foo() do
from(x in My.Schema,
where: exists_frag("my_table_name")
)
end
I used this blog post as well: https://dreamconception.com/tech/ecto-how-to-build-dynamic-fragments-and-case-statements/






















