armen-g
February 20, 2020, 2:51pm
#1
Hello Heroes,
I have a query like this in Metabase.
SELECT account_type IN {{ account_type }}
FROM accounts;
{{ account_type }} is set as a field filter and referred to metabase_data1 table’s account_type field
It generates this query completely wrong which cannot be executed in Postgres.
SELECT account_type IN “public”.“metabase_data1”.“account_type” IN (‘user’)
FROM accounts;
But expected to generate
SELECT account_type IN (‘user’)
FROM accounts;
Could you pls help me to find out what should I do.?
flamber
February 20, 2020, 3:05pm
#2
Hi @armen-g
You can currently only use Field Filters in the WHERE
clause.
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#the-field-filter-variable-type
You might be interested in several of the issues linked in this (upvote by clicking on the first post of each issue):
https://github.com/metabase/metabase/issues/11531
armen-g
February 20, 2020, 3:09pm
#3
Hi @flamber ,
Thank you for the response. Even in where clause it works same way. it generates totally wrong query.
The github issue you have linked is not the same BTW.
flamber
February 20, 2020, 3:11pm
#4
@armen-g If you check the documentation, then notice that Field Filters should not include the column, since it will automatically add that, so your query will look like this:
SELECT *
FROM accounts
WHERE {{ account_type }}