Dynamic custom query


#1

I have a couple of visualizations using custom queries, and I need to change the query depending on user interaction if a given field exists in the database. For example: Let’s say the custom query is built using a field called pricepaid_city, and the user decides to select (a dropdown let’s say) to the state level, in that case, I need to change my custom query to use pricepaid_state and query again.

Is that something that I can do by modifying the query or do I need to create as many queries as I may need beforehand?


#2

You can define as many custom queries as you want and have them ready to be triggered, they won’t be sent to the server until you execute the visualization.

But in case you need to modify the same query over and over again, then you will have to access your provider, remove the previous one and add the modified:

const provider = cf.getProviderByConfig('My SQL provider')
const myCustomQuery = 'SELECT ....FROM.....';
provider.removeSource('the_name_of_your_query');
prov.addSourceMetaData('the_name_of_your_query', { query: myCustomQuery });