Hello!
I have a jsonb field in my db which looks like
[%{id: 1, name: “test1”}, %{id: 2, name: “test2”}]
I need get all the records which contains id: 1
my working query:
where: fragment("? @@ ?", a.details, ^"$[*].id == 1")
however i need to pass a variable as id so i changed it to:
where: fragment("? @@ ?", a.details, ^"$[*].id == #{variable.id}")
I have read is not possible to pass a variable (Interpolating) to a fragment due to sql injection attacks
my variable comes from a safe source (it’s an id from incrementation)
so i changed my query to, but it wont work (it returns empty array)
where: fragment("? @@ ? = ?", a.details, ^"$[*].id", ^variable.id)
any ideas what is wrong?