Passing values to Queries

HI all

New to Retool. I have a very simple issue with passing a value resulting from a a select tool pick.

The select tool correctly displays the desired list from my database and saves the selection as {{select1.value}}. I am able to confirm by displaying {{select1.value}} in a text box.

However, when I query my data (organized in a Retool database) with the following, I get the correct label back but the value is just blank.

SELECT make FROM "Cardata" WHERE equipment = {{select1.value}};

The query editor tells me that {{Select1.value}} is undefined. The data in the database is correct and should return a value.

This has got to be a simple problem to fix, so any advice would be appreciated.

@Doug_Milner Welcome to Retool!

Your setup is an extremely common use case so I've got some follow-up questions:

Is your query being run within the app or previewed in the code editor?

When you substitute {{select1.value}} with a hardcoded value (what the select should be providing) does the query still return no rows?

Can you provide a screenshot of the query/app space just to see if there's something directly in the query/setup that could be causing the issue?


I ran it in the code editor. When I hard code in a value, it functions properly. When I reference {{select1.value}} it returns a blank. Screen shot below

The screenshot shows that Retool doesn't recognize the select1 reference. How is it created in your app? Can you share a screenshot of the component tree?


It is created by selecting an item from a pull down list using the select tool.


Here's an example of the select component driving my Retool DB query:

When I change the dropdown values (pulled from a query of the same table in the DB) the query10 you see here updates with the new dropdown value.

Do you have a similar setup to this? Can you share it so we can see if it is a bug vs a setup issue?


It appears to be the exact same set up

Same result with {{select1.selectedValue}}

is your selectbox set up with values or labels? Might need select1.selectedLabel

It is set up with values. I tried the label option but same result.

Yeah that's weird, would need to see how you are populating the data into that select box.


Here's the example select component I have setup:


Is your setup the same? My listQuery is separate than the query I used for the example results I was able to pull using the value.

When you hover over the .value in the SQL, does it show the value of the component? If so, have you enabled using dynamic references within the SQL editor. For me, this option was not enabled by default.

Hi @Doug_Milner,

It seems like your screenshots might be using the query library. If that is the case, component values won't be in scope within the query library. You'll need to create a dynamic variable on the query library query. Then, once you import the query into your app, you can pass the select value into your query.

In the query library, you'll create a variable using {{}}. You can put any variable name inside the {{}} and you can put any test values in the variable field on the right (replace {{select1.value}} in your query with {{some_string_here}}):

In the app, import your query & pass in the select value:

1 Like