Search code examples
kdb

Function does not return value in kdb/q


I have a function declaration in kdb/q:

q)func_demo:{[time1;time2] select from t where time within(time1 time2)}

where the datatype for time is v. And the query works perfectly.

I pass two time into the function:

q)func_demo[13:00:00 13:00:02]

But there is no table showing in the console, and it gives me something like:

{[time1;time2] select from tt where tp_time within(time1 time2)}[13:00:00 13:00:02]

Could someone gives me some hints how to deal with this issue? is that because I don't convert 13:00:00 to type 'v' when I pass in the parameters?

Thanks so much!


Solution

  • You need to pass the parameters as @emc211 has suggested; however there is a problem with the function you are using (time1 time2)

    {[time1;time2] select from tt where tp_time within(time1 time2)}[13:00:00;13:00:02]
    

    It should be (time1;time2) - semicolon (;) after time1

    {[time1;time2] select from tt where tp_time within(time1; time2)}[13:00:00;13:00:02]
    

    Explanation :

    time1:13:00:00
    time2:13:00:02
    

    this is similar to time1@time2

    q)(time1 time2)
    'type
    [0]  (time1 time2)
    

    To use the time1 and time2 as list :

    q)(time1;time2)
    13:00:00 13:00:02
    

    If you are using the actual values then no need to specify the ; for the similar type of elements.

    (time1;time2)~(13:00:00 13:00:02)
    1b