So close… if I need to supply an ad-hoc argument (i.e. a variable) that specifies conversions for the join, fragment() raises an error:
# A user-supplied conversion
f1 = "CAST(? AS VARCHAR)"
from(a in query,
join: b in ^other_module,
on:
^dynamic(
[{^binding, tbl1}, {^assn, tbl2}],
fragment(^f1, field(tbl1, ^id1)) == field(tbl2, ^id2)
),
as: ^assn
)
|> add_join(rest, schema)
yields
** (Ecto.Query.CompileError) to prevent SQL injection attacks, fragment(...) does not allow strings to be interpolated as the first argument via the `^` operator, got: `f1`
That lead me to this post: Ecto not allowing string interpolation in fragments? - #22 by tfwright
I hadn’t known that there was once a fragment_unsafe macro, but I’m wishing that it were still around. I’ve been playing around with Code.eval_quoted but I can’t seem to figure out the syntax to make fragment accept a user-supplied variable to do the cast operation I need.






















