0

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
Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
jono
  • 171
  • 1
  • 1
  • 9

2 Answers2

1

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 ;

MdSalih
  • 1,978
  • 10
  • 16
  • This works. Thank you! But I do not fully understand the reasoning. Would it be possible to link me a reference?? – jono Apr 20 '17 at 07:41
  • See syntax for creating a table [here](http://code.kx.com/wiki/Reference/Table#Creating_Tables) and [here](http://code.kx.com/wiki/Startingkdbplus/tables#4.2_Creating_Tables) – MdSalih Apr 20 '17 at 11:46
0
    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)
Chromozorz
  • 451
  • 2
  • 6