Search code examples
kdb

kdb: filter table match symbol column: ~ vs =


For a where clause to filter on symbol columns, = works fine, but why does the match operator ~ not work?

q)t:([sym:`aa`bb]qty:20 30)

q)t
sym| qty
---| ---
aa | 20
bb | 30

q)select from t where sym=`aa
sym| qty
---| ---
aa | 20

q)select from t where sym~`aa
sym| qty
---| ---

Solution

  • Match is comparing `aa to the entire symbol column, where equals is comparing to each element

    q)`a=`a`b`c
    100b
    q)`a~`a`b`c
    0b
    

    You could do

    q)select from t where sym~\:`aa
    sym| qty
    ---| ---
    aa | 20