0

I have a table with one column whose values need updating from a column in another table. Table 1 has 0 rows. I came up with an anonymous function but I get length error. I even enlisted the value. What am I missing here?

q)t1:([]a:();b:();c:())
q)t1
a b c
-----


q)t2:([]d:(1;2;3);e:("trade";"quote";"price"))
q)t2
d e
---------
1 "trade"
2 "quote"
3 "price"


q)eTab:exec distinct e from t2
q)eTab
"trade"
"quote"
"price"


{[eTab]
  update a:enlist "KDB", b:enlist eTab, c:enlist "KDB" from `t1
  } each eTab;

I looked at this question: kdb Update entire column with data from another table Here the original table has values in already whereas my table is empty.

Alternately, is there a better way of doing this where t1 gets updated every time there is a change in column e of t2? I looked at views here: https://code.kx.com/q/learn/views/ It is not entirely clear how this can be implemented in my case.

Thanks!

CleanSock
  • 363
  • 2
  • 4
  • 15

1 Answers1

2

insert would be a better option for what you're trying to do:

{[eTab]`t1 insert(enlist"KDB";enlist eTab;enlist"KDB")}each eTab

As for doing it on every change to t2, the best way to do that is to hijack the function which is making the changes/inserts into t2. Within that function have an additional re-calc for t1

terrylynch
  • 11,844
  • 13
  • 21