I have a int4range
, which I want to query. In this example, the column is named from_postal_code
I’d like to do something like this:
from r in Route, where: fragment("? @> ?", r.from_postal_code, type(^value, :integer)
But this doesn’t actually work, because ecto does not cast value
to ::integer
, but rather to ::bigint
, resulting in the following error:
(Postgrex.Error) ERROR 42883 (undefined_function) operator does not exist: int4range @> bigint
I could switch to using a int8range
, which is queryable by a bigint, but this seems… silly. Surely there must be some way to actually cast to a normal integer? As best as I can tell, this switcheroo of types is implemented at the adapter level, I think it might be this. And this seems tricky to bypass, but I’m not very familiar with ecto internals. Is there some way to bypass this to cast to a normal integer which is not a bigint?