0

I have a table with one of columns keyname being int and another column keylist being list of int. I am trying to create another column which is position of keyname in keylist in my table in following manner:

update keypos:{y?x} . (keyname;keylist) from tableName

OR

update keypos:{{x?1}(y=x)} . (keyname;keylist) from tableName

Both of these result in keypos with value=size of table.

Any insights much appreciated.

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
Rahul
  • 755
  • 4
  • 8
  • 16
  • The reason it's returning "size of table" is because you're performing a single lookup of the whole keyname list into the list of lists. But the whole keyname list isn't in the list of lists and so it's returning the out-of-bounds index (which so happens to be equal to the count of the table). Kdb then converts this single atom into a vector to make it a valid column. I think what you're trying to do is do a lookup of *each* keyname into *each* list. Which explains why an each-both is needed – terrylynch Feb 02 '17 at 14:30
  • Thanks @terrylynch – Rahul Feb 05 '17 at 21:45

1 Answers1

2
update keypos:keylist?'keyname from tableName
Akash
  • 131
  • 7
  • Thanks Akash. This works. Can you shed some light why each both is needed when this works in non- table settings. – Rahul Feb 02 '17 at 09:24
  • 1
    It's because table columns are implemented as lists, making each-both appropriate. In non-table usage keypos is a scalar. So keypos is actually a list of ints and keylist is a list of lists of ints – James Little Feb 02 '17 at 18:41
  • Thanks @JamesLittle – Rahul Feb 05 '17 at 21:45