Undefined function fragment/2

This may be a newbie question, sorry about that, but i can’t figure it out.

Im trying to make a simple thing

import Ecto.Query
...

filter = %{key: "tags", value: "aaa"}
value = filter[:value]
fragment(" '?' =ANY (tags)", value)

But I get every time undefined function fragment/2

I tried importing or using API Builder etc but without result.

Anyone has a full example? (I’m using ":ecto, "3.0.6"

thanks in advance

1 Like

:wave:

This may be a newbie question, sorry about that, but i can’t figure it out.

No need for apologies. I assume it is because you need to use the fragment inside a Query. Can you show the entire function?

Here is an example

from p in Post,
 where: is_nil(p.published_at) and
        fragment("lower(?)", p.title) == ^title

from Ecto.Query — Ecto v3.11.1

2 Likes

You can also use dynamic if you need to use fragment outside Query

2 Likes

Full code
https://gist.github.com/mberrueta/1a18c9bdf4a96839ee69a6a3092b3483

I use dynamic, but i need a query like

SELECT * from services where 'xxxx' =ANY(tags)

If you want to use fragment outside Query you need to wrap it inside dynamic, I don’t see you doing that in your gist. What I mean is something like this dynamic([d], fragment("?=ANY (tags)", d.some_field))

4 Likes

perfect! that was the solution! thank you so much!