Add support for parameter lists


#1

Hi!
I would love a feature where you can provide a list of parameters in redash e.g

WHERE city IN “{{paramter}}”

As of right now it doesn’t seem to work


#2

I have been using a fun workaround :slight_smile: with Postgres arrays:

select
*
from paths
where id::varchar = any(string_to_array(replace(trim(’{{paths (enter comma separated path ids like 5,4,9)}}’), ’ ', ‘’), ‘,’))

The replace part is optional, in case you’re worried that people will enter comma space delimited values instead of comma delimited values.

Enjoy!
Ben


#3

Redash supports query based parameters.


#4

It does.

https://redash.io/help/queries/writing_queries.html#query_params
https://redash.io/help/queries/writing_queries.html#query_filters

#RTFM :slight_smile:


#5

I am already using the filters and parameters.
My questions specifically targeted the IN SQL-Keyword, which didn’t work
with the standard parameters.


#6

@rohithmenon
The option does not show for me in the parameters drop down list.
I used the newest Amazon image about 2 weeks ago. How can I
enable this maybe manually?


#7

Building from source should work. Not sure of the sha from which image is built.


#8

@rohithmenon Thanks for the quick reply. That is unfortunately not an option, since it is a production server and I’d actually prefer it to upgrade via the built in function. Is there an ETA for a new build?


#9

Not sure. You should ping the maintainer. You can cherrypick the change on top of the current deploy if you want. But its all up to you.


#10

@rohithmenon Never heard of that option before. Can you elaborate?


#11

Cherry picking will require rebuilding the frontend code…

The next release should be this month.


#12

Perfect! Thanks @arikfr

We have our private fork of redash for unreleased features. If you are not comfortable with building from source, what I told is not an option.


#13

+1 for parameter lists. One way I could see it being implemented is as follows:
New parameter type: text list
Text box appears for entry of the list - one value per line
Redash wraps each line in single quotes and adds a comma
Parameter can be used in SQL like so: WHERE id in( {{ id_list }} )

Similar implementation for number list except no quotes around the values when being inserted into the query. You could also implement as a single new parameter type “list” and add a checkbox for text vs number.


#14

One workaround for this issue is using Jinja2’s loop.last syntax. The Jinja code would look something like this:

(
  {% for item in this_list %}
  {{ item }} {% if not loop.last %} , {% endif %}
  {% endfor %}
)

This avoids the syntax error of a trailing comma without hacking through Python’s tuple representations.


#15

#16

Just to make sure I understand, are you saying this is a workaround to make it work under the current version of Redash? I wasn’t aware that you could write inline Jinja in a query. I just Googled “redash jinja” and didn’t come up with any results, so if that’s what you’re saying, it must be an undocumented feature?