How do you create a parameter query where the user will enter a value?
With parameters you can substitute values into your query at runtime without having to Edit Source. Any string between double curly braces Show In editing mode, you can click the gear icon for each parameter widget to adjust its settings. The gear icons disappear when you click Show Data Only so that users who don’t own the query can’t change the parameter behavior. Add A Parameter From The UIYou can insert a parameter into your query and immediately activate its settings pane by using the You can discover the key shortcut on your operating system by hovering your cursor above the Parameter SettingsClick the gear icon beside each parameter widget to edit its settings:
Prior to Redash version 7, the parameter settings pane in the Query Editor included a For security reasons, a Redash user must have Full Access permission to the data source to use Text-type Query Parameters. Other types such as Date, Date Range, Number or Dropdown list are available to all users. Date and Date-Range ParametersDate Parameters use a familiar calendar picking interface and can default to the current date and time. You can chose from three levels of precision: Date, Date and Time, and Date and Time with seconds. Date Range Parameters insert two markers called SELECT user_uuid as ‘value’, username as ‘name’ FROM users1 and SELECT user_uuid as ‘value’, username as ‘name’ FROM users2 which signify the beginning and end of your chosen date range.
Date parameters are passed as strings to your database. So you should wrap them in single quotes ( SELECT user_uuid as ‘value’, username as ‘name’ FROM users3) or whatever your database uses to declare strings. Although they behave like Text parameters Dates are still safe for use in embeds and share dashboards. Date Range parameters use a combined widget to simplify range selection. Quick Date and Date-Range OptionsWhen you add a Date or Date Range parameter to your query, the selection widget shows a blue lightning bolt glyph. Click the glyph to see dynamic values like “Today” or “Yesterday”. There are dynamic date range options too. The complete list of dynamic date-ranges is:
Because dynamic dates and date ranges are calculated in the front-end, they aren’t compatible with Scheduled Queries. Dropdown ListsIf you want to restrict the scope of possible parameter values when running a query, you can use Redash’s SELECT user_uuid as ‘value’, username as ‘name’ FROM users4 parameter type. When selected from the parameter settings panel, a text box appears where you can enter your allowed values, each one separated by a new line. Dropdown lists are SELECT user_uuid as ‘value’, username as ‘name’ FROM users5 parameters under the hood, so if you want to use dates/datetimes in your dropdown, you should enter them in the format your data source requires. Query Based Dropdown ListDropdown lists can also be tied to the results of an existing query. Just click SELECT user_uuid as ‘value’, username as ‘name’ FROM users6 under Type in the settings panel. Search for your target query in the Query to load dropdown values from bar. Performance will degrade if your target query returns a large number of records. If your target query returns more than one column, Redash uses the first one. If your target query returns SELECT user_uuid as ‘value’, username as ‘name’ FROM users7 and SELECT user_uuid as ‘value’, username as ‘name’ FROM users8 columns, Redash populates the parameter selection widget with the SELECT user_uuid as ‘value’, username as ‘name’ FROM users7 column but executes the query with the associated SELECT user_uuid as ‘value’, username as ‘name’ FROM users8. For example, suppose this query: SELECT user_uuid as ‘value’, username as ‘name’ FROM users returned this data: valuename1001John Smith1002Jane Doe1003Bobby TablesRedash’s dropdown list widget would look like this: But when Redash executes the query, the value passed to the database would be 1001, 1002 or 1003. Serialized Multi-SelectDropdown lists can also be serialized to allow for multi-select. Just toggle the Allow multiple values option and choose whether or not to wrap the parameters with single quotes or double-quotes. In your query, change your 1 clause to use the 2 keyword.
The parameter multi-selection widget let you pass extra values to the database. FAQCan I reuse the same parameter multiple times in a single query? Sure! Just use the same identifier in the curly brackets. In this example:
We use the 3 parameter twice.Can I use multiple parameters in a single query? Of course, just use a unique name for each one. In this example:
We use two parameters: 3 and 5.Can I use parameters in embedded visualizations and shared dashboards? Yes, with one exception. If a query uses a Text type parameter it cannot be embedded because Text parameters are not safe from SQL injection. All other types of query parameters can be used safely in embedded visualizations and dashboards. Parameter TypeSafe for Embedding?TextNoNumberYesDropdown ListYesQuery Based Dropdown ListYesDateYesDate and TimeYesDate and Time w/SecondsYesDate RangeYesDate and Time RangeYesDate and Time Range w/SecondsYesPrior to Version 8 of Redash, parameters were not allowed in embedded visualizations. In a future version, all types of parameters will be allowed on publicly shared dashboards and visualizations. Our hosted platform always runs the latest available version of the app. Can I change parameter values via the URL? Yes. Each parameter appears in the URL query string preceded by 6. A query with id 7 and the following query text:
Would have link a like so: 8This is useful for linking between queries and dashboards. Parameter Mapping on DashboardsQuery Parameters can also be powerfully controlled within dashboards. You can link together parameters on different widgets, set static parameter values, or choose values individually for each widget. You select your desired parameter mapping when adding dashboard widgets that depend on a parameter value. Each parameter in the underlying query will appear in the Parameters list. You can also access the parameter mapping interface by clicking the vertical ellipsis ( 9) on the top right of a dashboard widget then clicking Edit Parameters.
Value Source Options
|