Search code examples
kdb

q/KDB Selecting multiple symbols using functional select


I am trying to select multiple symbols using function select but it is throwing an error :

d:([] s:5#`v`b ; p:5?10)
?[d;enlist (in;`s;(),`v`b);0b;()]
'b

however, when I select a single symbol, it returns correct data

?[d;enlist (in;`s;(),`v);0b;()]
s p
---
v 8
v 4
v 2

what exactly is wrong with my query?


Solution

  • If you run parse on the equivalent q-sql expression you will see , in parse tree:

    q)parse"select from d where s in`v`b"
    ?
    `d
    ,,(in;`s;,`v`b)
    0b
    ()
    

    This means enlist, so if you sub that in instead the query should work:

    q)?[d;enlist(in;`s;enlist`v`b);0b;()]
    s p
    ---
    v 8
    b 1
    v 9
    b 5
    v 4
    q)?[d;enlist(in;`s;enlist`v);0b;()]
    s p
    ---
    v 8
    v 9
    v 4