You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@asterixdb.apache.org by Taewoo Kim <wa...@gmail.com> on 2016/09/24 03:28:44 UTC

Do we allow optional parameter in a function?

Hi all,

Here is my question. Can a function have an optional parameter? For
example, if a function F requires three parameters  - a, b, c, can we omit
the last one? F(a,b,c) VS F(a,b). I tried and Asterix says that F(a,b) is
not defined. If someone knows the workaround, it would be really nice.

Actual scenario: Full-text search function name is ftcontains() and it has
three parameters - expresssion1, expression2, options as a record. An
example is ftcontains($o.title, "database", {"mode":"and"}). I would like
to give user the option to not put the third parameter. In that case, each
option can be set using default values.

Best,
Taewoo

Re: Do we allow optional parameter in a function?

Posted by Taewoo Kim <wa...@gmail.com>.
@Steven: Thanks for the information. I think two separate function
signatures would be better instead let use say F(a,b,null).

Best,
Taewoo

On Fri, Sep 23, 2016 at 8:38 PM, Steven Jacobs <sj...@ucr.edu> wrote:

> The only way we handle this currently is to have two separate function
> signatures. They can share code underneath, but we are strict about
> parameter count. The other option would be for the user to pass some null
> representation for the third value.
> Steven
>
> On Friday, September 23, 2016, Taewoo Kim <wa...@gmail.com> wrote:
>
> > Hi all,
> >
> > Here is my question. Can a function have an optional parameter? For
> > example, if a function F requires three parameters  - a, b, c, can we
> omit
> > the last one? F(a,b,c) VS F(a,b). I tried and Asterix says that F(a,b) is
> > not defined. If someone knows the workaround, it would be really nice.
> >
> > Actual scenario: Full-text search function name is ftcontains() and it
> has
> > three parameters - expresssion1, expression2, options as a record. An
> > example is ftcontains($o.title, "database", {"mode":"and"}). I would like
> > to give user the option to not put the third parameter. In that case,
> each
> > option can be set using default values.
> >
> > Best,
> > Taewoo
> >
>

Re: Do we allow optional parameter in a function?

Posted by Steven Jacobs <sj...@ucr.edu>.
The only way we handle this currently is to have two separate function
signatures. They can share code underneath, but we are strict about
parameter count. The other option would be for the user to pass some null
representation for the third value.
Steven

On Friday, September 23, 2016, Taewoo Kim <wa...@gmail.com> wrote:

> Hi all,
>
> Here is my question. Can a function have an optional parameter? For
> example, if a function F requires three parameters  - a, b, c, can we omit
> the last one? F(a,b,c) VS F(a,b). I tried and Asterix says that F(a,b) is
> not defined. If someone knows the workaround, it would be really nice.
>
> Actual scenario: Full-text search function name is ftcontains() and it has
> three parameters - expresssion1, expression2, options as a record. An
> example is ftcontains($o.title, "database", {"mode":"and"}). I would like
> to give user the option to not put the third parameter. In that case, each
> option can be set using default values.
>
> Best,
> Taewoo
>