I'm trying to get a query like the following done with Dapper. Documentation around json is a bit slim though and I couldn't figure it out so far.
Basically I need to run a query similar to this one.
select * from table
WHERE jsonbfield @> ANY (ARRAY ['[{"property1": "value1", "property2":"value2"}]', '[{"property1": "value3", "property2": "value4"}]']::jsonb[]);
How can I pass this through a parameter?
Here some more details what I've tried so far. The field contains aggregated data like this as jsonb.
Similar to this
[{
"property1": "value1",
"property2": "value2,
},
{
"property1": "value3",
"property2": "value4,
}]
As mentioned in comments, the sql query is actually working and returning what I need. However, I'm not able so far to pass the data as a parameter. If I include it directly in the query it's working fine. But I would prefer to use parameters instead.
So this is working.
"select * from table where jsonbfield @> ANY (ARRAY['[{\"property1\": \"value1\"}]']::jsonb[])"
This ain't
var parameter = "'[{\"property1\": \"value1\"}]'";
"select * from table where jsonbfield @> ANY (ARRAY[@parameter]::jsonb[])"
'[{"property1": "value1", "property2":"value2"}]', '[{"property1": "value3", "property2": "value4"}]'
as string parameter – Lukasz Szozda Mar 2 '19 at 21:22