You can specify a parameter instead of any expression, value, or name in a query.
First, you must define a parameter, which can then be used in several places in the query. For example:
SELECT COUNT(*) number
FROM (
TABLE_DATE_RANGE([githubarchive:day.events_],
TIMESTAMP("{dateFrom default="2015-01-01" type="datetime"}"),
TIMESTAMP("{dateTo default="2015-01-02" type="datetime"}")
))
WHERE type ="{event default='PushEvent' values='PushEvent,WatchEvent,ForkEvent' type='select'}"
LIMIT {limit_12 default="10" pattern="^[0-9]+$" type="input"}
The types of parameters:
1. input field (default type): {parameterName default="100" type="input" pattern="[0-9]*"}
- default * — the default value
- type —
input
- pattern — a regular expression to check the value
2. date and time: {parameterName default="2015-01-02" type="datetime"}
- default * — the default value
- type * —
datetime
3. select from the list: {parameterName default="PushEvent" type="select" values="PushEvent,WatchEvent,ForkEvent"}
- default * — the default value
- type * —
select
- values * — list of values separated by commas
On subsequent calls to the parameter, you only need to specify its name, for example, {date}.
* Required properties.
Example of using the dynamic parameter as a regular expression value:
...
WHERE
REGEXP_CONTAINS(user_country,
r"{UserCountry default=".*" type="select" values=".*,US,UK,Canada,Australia"}")
...
In the dropdown list of values that the regular expression can take you'll see:
- .* (any value)
- US
- UK
- Canada
- Australia
6 Comments