Optional Parameters Support
See original GitHub issueToday to make a parameter optional, the user needs to have a workaround in the query logic itself. For example:
select count(0)
from queries
where 'All' = '{{org_id}}' or org_id::varchar = '{{org_id}}'
In this case when the value of org_id
is All
, then we don’t filter by it. It will be great if the user could mark a whole section as optional if no parameter is provided. The templating language we use (Mustache) actually supports this:
select count(0)
from queries
{{#org_id}}
where 'All' = '{{org_id}}' or org_id::varchar = '{{org_id}}'
{{/org_id}}
If no value for {{org_id}}
is provided, then the section between {{#org_id}}
and {{/org_id}}
won’t be rendered. So in theory, we can just allow for passing empty values for parameters and it works.
This has two issues though:
- Any false-y value will make this section not render. Including
0
(zero), which might be acceptable in some cases. - This might make the implementation of #2904 more complicated.
We should probably take this into account when implementing #2904, and revisit once it’s indeed implemented.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:77
- Comments:44 (6 by maintainers)
Top Results From Across the Web
Named and Optional Arguments - C# Programming Guide
Optional arguments enable you to omit arguments for some parameters. Both techniques can be used with methods, indexers, constructors, ...
Read more >TypeScript Optional Parameters
In this tutorial, you will learn how to use the TypeScript optional parameters for functions.
Read more >Optional Parameters in Java: Common Strategies and ...
Unlike some languages such as Kotlin and Python, Java doesn't provide built-in support for optional parameter values.
Read more >Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >Dealing with Optional Parameters in Go | by Peter Malina
Legend says Go does not support optional parameters or method overloading, as it may be confusing or fragile in practice. However, there are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Metabase solved this using bracket syntax:
[[AND created >= {{start_date}} ]]
.If the variable referenced within the double brackets (
start_date
) exists then the contents of the brackets is parsed into the query, otherwise the line is ignored.This is quite elegant in my opinion and it doesn’t invite users to abuse default values.
Any news? This is pretty critical for us.