Search code examples
kdb

Pass a table as condition with where clause in kdb


I have a table t:

t:([] sym:`GOOG`AMZN; px:10 20; vol:100 200);

Is it possible to pass a sub-table as a where clause condition to the table?
Below query throws type error:

select from t where ([] sym:enlist `GOOG; px:enlist 10)

Solution

  • Yes, it is possible:

    q)select from t where([]sym;px) in ([] sym:enlist `GOOG; px:enlist 10)
    sym  px vol
    -----------
    GOOG 10 100
    

    Update: however, if t is large this should be much faster:

    q)([] sym:enlist `GOOG; px:enlist 10)#2!t
    sym  px| vol
    -------| ---
    GOOG 10| 100