I have a query that uses a jsonb
function (jsonb_path_query_array
), which allows me to navigate through the JSON data and select specific things. The problem I am having is that as part of my function parameter, I make use of the symbol "?" to navigate the JSON. Metabase is wrongly interpreting this as a var and replacing it with my actual variables, and then leaving my variables in the query as "?".
Example:
SELECT
count(*),
(jsonb_path_query_array (b. "responseData",
'$.sections[*] ? (@.name == "SOME_NAME").radioButtons[*] ? (@.checked == true).label') ->> 0) AS "Category"
FROM
"Template" t
WHERE
AND t. "createdAt" <= {{ dateFrom }}::timestamp
AND t. "createdAt" >= {{ dateTo }}::timestamp
GROUP BY
"Category"
When I preview this query, I get:
SELECT
count(*),
(jsonb_path_query_array (b. "responseData",
'$.sections[*] date '2024-03-01' (@.name == "SOME_NAME").radioButtons[*] date '2024-03-31' (@.checked == true).label') ->> 0) AS "Category"
FROM
"Template" t
WHERE
AND t. "createdAt" <= ?::timestamp
AND t. "createdAt" >= ?::timestamp
GROUP BY
"Category"
Any ideas on how to prevent this from happening?