Dynamic column in query

I request your help to know how Can I do a dynamic query in retool? I have a requirement where the user can select if the search is for email or by name so I am trying with this query select * from USERS where {{!textInput1.value}} or {{radioGroup1.value}} ILIKE {{'%' +textInput1.value + '%'}} where {{radioGroup1.value}} has the name of the column. I did not get a message error when I saved the query but it does not work. What Can it be the solution?

Note: I am using the database that the tool has for showing what I want to do

I hope that you can help me, please.

Hi @Yesi, welcome to the community!

With your query, you are lacking a variable to compare the values. Example: which variable/column in the USERS table are you aligning {{textInput1.value}}? is it email, first_name, or last_name, etc. Dynamically setting the columnName is difficult and have not worked around that since the way this {{}} outputs strings are as string literal for any SQL resource (any retool team, please correct me if wrong). You can do something like this so it'll be semi-dynamic to what you want:

SELECT *
FROM users
WHERE ({{!textInput1.value}} or email ILIKE CONCAT('%', CAST({{textInput1.value}} AS VARCHAR), '%'))

This worked on my end though. Try looking into adding filter to your table by adding events when you enter an email address. You can check this docu for setting up filters to your table via events on other component.

Regards,