Reputation: 211
I am trying to modify the entry in the factor column that corresponds to the provided date.
I cannot find any good documentation for KDB's upsert function and I have zero idea what I am doing wrong here..
query: {[table;dates;factors] table upsert (date:dates factor:factors);}
table: `test
dates: (2016.01.04T01:30:00.000; 2016.01.04T01:31:00.000)
factors: (0.9340078471263533; 0.9340078471263533)
query[table; dates; factors]
date price original factor askVol bidVol
-----------------------------------------------------------------------
....
2017.04.19T07:28:00.000 6.105 6.105 1 2.176407e+07 1.907746e+07
2017.04.19T07:29:00.000 6.105 6.105 1 2.274138e+07 1.893807e+07
2017.04.19T07:30:00.000 6.105 6.105 1 2.629207e+07 2.030017e+07
....
An error occurred during execution of the query.
The server sent the response:
type
Studio Hint: Possibly this error refers to wrong type, e.g `a+1
Upvotes: 0
Views: 1014
Reputation: 461
q)show table:([] dates:.z.D+til 3;factors:3?.1; something:3?`2)
dates factors something
-------------------------------
2017.04.20 0.09441671 hj
2017.04.21 0.07833686 lh
2017.04.22 0.04099561 mg
q)show factormap:(.z.D,.z.D+2)!10000.1 20000.2
2017.04.20| 10000.1
2017.04.22| 20000.2
q)update factors:factors^factormap[dates]from table
dates factors something
-------------------------------
2017.04.20 10000.1 hj
2017.04.21 0.07833686 lh
2017.04.22 20000.2 mg
q)
Upvotes: 0
Reputation: 1996
You have a small syntax error in the function query
, when you define the table from the input arguments -
query: {[table;dates;factors] table upsert (date:dates factor:factors);}
Should be:
query:{[table;dates;factors] table upsert ([] date:dates; factor:factors);}
Note the additional []
after the opening (
for a table definition. Moreover, column values need to be delimited with ;
Upvotes: 1