How to concatenate string from {{ ... }}

I have postgres query

SELECT * FROM "Test" WHERE "UserId" = {{ urlparams.userid }} ORDER BY "id" DESC;

Now I would like to make the WHERE clause conditional so the query will contain WHERE only if urlparams.userid is defined. I've tried to put

{{ urlparams.userid ? 'WHERE "UserId" =' + urlparams.userid : null }} but getting weird errors.

I also tried to create JS query and trigger sql queries conditionally, but I am not sure how to return query data inside JS query.

@Pablo You are trying to do do this?
if (urlparams.userid != "") {
run query

If so, this can be done by using the advanced tab

So the query will only run if urlparams.userid is defined and not null.

Hi @ScottR ,

I am not trying to conditionally enable or disable query but rather slightly modify query if userid is null. So when it's null I need to run

When it's not null I need to run

SELECT * FROM "Test" WHERE "UserId" = {{ urlparams.userid }} ORDER BY "id" DESC;

OK and is this something you want to be done automatically on page load?
Or is it user event based?

I would like it to be done on page load only for now.

OK so I still believe that you can set the conditional in the advanced tab for each query
will run when urlparams.userid == ""
and the other query
SELECT * FROM "Test" WHERE "UserId" = {{ urlparams.userid }} ORDER BY "id" DESC;
should run urlparams.userid != ""
Both conditional set in Advanced Tab

and for each query you set it to run automatically when inputs change in the General Tab

But my table component can be bound to only one query. How can I use 2 queries on single table component?


In the Data field for that table, do the following
{{urlparams.userid == ""?}}
This checks to see if the userid is blank and if it is populate table with, but if it is not empty populate table with
You'll want to set up the separate queries to automatically run when inputs change.
Screen Shot 2021-12-22 at 12.29.17 PM