https://learninghub.kx.com/forums/topic/why-sv-needs-here
I have the below trades table in my q session:
q)meta trades
c | t f a
-----| -----
time | p
sym | s g
src | s g
price| f
size | i
Then, why does it need each both for the sv function when x and y are joined already and then passed into sv:
q)update symsrc:{` sv'(x,'y)}[sym;src] from 1#trades
time sym src price size symsrc
--------------------------------------------------------
2023.06.04D08:00:49.248000000 ORCL L 40.67 3984 ORCL.L
q)update symsrc:{-1 .Q.s1 x,y; ` sv'(x,'y)}[sym;src] from 1#trades `ORCL`L
time sym src price size symsrc
--------------------------------------------------------
2023.06.04D08:00:49.248000000 ORCL L 40.67 3984 ORCL.L
You’ll get a type error without the each, because you need to create a scalar from each vector (i.e. each pair of symbols)
q)t:([]sym:`ORCL`APPL;src:`L`R) t
sym src
--------
ORCL L
APPL R
q) update symsrc:` sv (sym,'src) from t
'type [0]
update symsrc:` sv (sym,'src) from t ^
q) update symsrc:` sv'(sym,'src) from t
sym src symsrc
---------------
ORCL L ORCL.L
APPL R APPL.R
Bonus tip - as shown above, you can avoid using a lambda by using parenthesis so the parser doesn’t interpret the comma as a new column statement.
David has already answered the question here, but it’s worth noting that you can do this operation very succinctly using .Q.dd:
q)update symsrc:.Q.dd'[sym;src]from trades
time sym src price size symsrc
--------------------------------------------------------
2023.06.04D10:22:20.088377000 ORCL L 40.67 3984 ORCL.L