question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional Parameters Support

See original GitHub issue

Today 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:

  1. Any false-y value will make this section not render. Including 0 (zero), which might be acceptable in some cases.
  2. 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:open
  • Created 5 years ago
  • Reactions:77
  • Comments:44 (6 by maintainers)

github_iconTop GitHub Comments

15reactions
smickcommented, Apr 29, 2019

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.

10reactions
renekyewskicommented, Dec 2, 2019

Any news? This is pretty critical for us.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found