Dynamic SQL query #31722
-
Hello,
In dashboard there should be an input box, if it's empty the query should be wo
but it turns to:
Sorry if smth similar has been already discussed - didn't find Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @orazs, I'm here to help you with any bugs, questions, or contributions. Let's tackle this together! To achieve dynamic SQL query modification based on user input in Superset, you can use Jinja templating effectively. It seems like you're on the right track, but there might be a misunderstanding in how the
SELECT smth
FROM table
WHERE 1=1
{% if filter_values('search') %}
AND search_vector @@ websearch('english', {{ "'" + "','".join(filter_values('search')) + "'" }})
{% endif %}
This setup should dynamically include the If you continue to experience issues, double-check the filter configuration in your dashboard to ensure it aligns with the query logic. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
For those who interested, the answer was found in https://preset.io/blog/intro-jinja-templating-apache-superset/ |
Beta Was this translation helpful? Give feedback.
Hey @orazs, I'm here to help you with any bugs, questions, or contributions. Let's tackle this together!
To achieve dynamic SQL query modification based on user input in Superset, you can use Jinja templating effectively. It seems like you're on the right track, but there might be a misunderstanding in how the
filter_values
function is used. Here's a refined approach:Ensure Jinja Templating is Enabled: Make sure that Jinja templating is enabled in your
superset_config.py
by setting theENABLE_TEMPLATE_PROCESSING
feature flag.Use
filter_values
Correctly: Thefilter_values
function should be used to dynamically insert filter values into your query. Here's how you can modify your query: