James
James

Reputation: 1260

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.

Upvotes: 0

Views: 782

Answers (2)

Matt Moore
Matt Moore

Reputation: 2800

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

Upvotes: 2

Elliot Tennison
Elliot Tennison

Reputation: 91

I believe what youre trying to do should work, not sure why its not working for you:

q)x:([] time:enlist .z.z; datum:enlist (`FOO;1084300i;1.5f))
q)y:([] time:enlist .z.z; datum:enlist (993150 2543823 15100i))
q)meta x
c    | t f a
-----| -----
time | z
datum|
q)meta y
c    | t f a
-----| -----
time | z
datum| I
q)x upsert y
time                    datum
---------------------------------------------
2020.07.30T15:51:13.333 `FOO   1084300i 1.5
2020.07.30T15:51:16.710 993150 2543823  15100
q)meta x upsert y
c    | t f a
-----| -----
time | z
datum|
q)

Upvotes: 3

Related Questions