Search code examples
kdb+

KDB+/Q: How to upsert to a table with a column of non conforming lists?


given a table x

q)show meta x;
c     | t f a
------| -----
time  | z
datum |

q)show first x;
time  | 2020.07.27T20:28:18.925
datum | (`FOO;1084300i;1.5f) // Non conforming type

Whereby the datum is a column of non type conforming (non uniform) lists, how does one correctly modify an upsert containing a datum of uniform type i.e.

q)show meta y;
c     | t f a
------| -----
time  | z
datum | I

q)show first y;
time  | 2020.07.26T23:51:10.790
datum | 993150 2543823 15100i

q)`x upsert y
'type

I have tried to use enlist;

q) y[`datum]:enlist each y[`datum];
q) show meta y;

c     | t f a
------| -----
time  | z 
datum |

and yet it still throws the same error:

 q)`x upsert y
    'type

Some advice on how to achieve this would be great, Thanks.


Solution

  • Can you double check your code that you aren't using insert?

    q)x insert y
    'type
      [0]  x insert y
             ^
    q)x upsert y
    time                    datum
    ------------------------------------------
    2020.07.27T20:28:18.925 `FOO 1084300i 1.5
    2020.07.28T20:28:18.925 `FOO 1084300i 1.5
    2020.07.29T23:51:10.790 725  1369     663
    2020.07.30T23:51:10.790 9478 1588     8660