2

I have a table, which is :

t:([alpha:`a`b`c`d`e`f];beta:10 20 30 40 50 60)

I also have two variable:

chgkey:`b`c
chgvalue:2000 -1000

I want to do something like:

t:update beta:2000 from t where alpha=`b;
t:update beta:-1000 from t where alpha=`c;

My question is how to combine these two lines of code. Because I am working on a table which is far bigger than this simple example and it will take me a lot of rows of codes to do all the updates, which is too long.

It would be nice something like

t[chgkey]`beta:chgvalue;
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
sxzhangzsx
  • 65
  • 9

2 Answers2

3

It would be nice something like t[chgkey]`beta:chgvalue

A working solution is only slightly more complicated:

t[([]alpha:chgkey);`beta]:chgvalue
Alexander Belopolsky
  • 2,228
  • 10
  • 26
2

I would try to use the next query. But note that it may be slow in case if your dict is really huge

dict: `b`c ! 1000 2000;
t: update beta: ?[alpha in key dict; dict alpha;beta] from t;

In case if table t is global it can be updated with functional update:

{![`t;enlist (=;`alpha;enlist x);0b; enlist[`beta]!enlist y];}'[`b`c; 1000 2000]
Anton Dovzhenko
  • 2,399
  • 11
  • 16