Concatnate the keyed KDB+ tables

By streamstar

Once in a while, we may write a function to do some computation for a particular day, then we would like to re-use the same function to do the same computation for each day in the history, and save the results into a single database. How to do that?

Suppose your function is

q> f:{[d] …}

where d is the date, and f returns a keyed table

q> sum f each exec date from t where date within (startDate;endDate)

will do it for keyed table.

Tags: , , , ,

3 Responses to “Concatnate the keyed KDB+ tables”

  1. brainyoga Says:

    could also write it as follows

    sum f each date where date within (startDate;endDate)

    and then you don’t have the boundary problem of where endDate equals the startDate. :-)

    but have to wonder why not do the aggregation inside the query that f is using?

    btw, you misspelled ‘praCtical’ in your blog header.

  2. brainyoga Says:

    btw, using underscores in variable names is generally frowned upon as _ is an operator and hence makes for harder reading of code.

  3. streamstar Says:

    Thanks! Your solution is better. I updated them. Thanks for the spelling check too:)

    Good point on aggregation in the query in function. I would do that for most queries. In actual usage, I actually have a more complicated function which takes many parameters and wouldn’t want incur the expensive aggregation on all of them. Also, I want the flexibility of the basic function to take any combination of parameters.

Leave a Reply