Search code examples
kdb

compare values of two string columns of a table in q kdb


We have a table:

q)t:([] a:("abc";"def";"ghi";"lmn"); b:("abc";"xyz";"ghi";"def"); c:1 2 3 4)
q)t
a     b     c
-------------
"abc" "abc" 1
"def" "xyz" 2
"ghi" "ghi" 3
"lmn" "def" 4

Expected output: Match column a and column b row wise and update mu column accordingly

a     b     c mu
---------------------
"abc" "abc" 1 match
"def" "xyz" 2 unmatch
"ghi" "ghi" 3 match
"lmn" "def" 4 unmatch

When I run below query it's failing, output is

q)select a,b,c, mu:?[any a like/: b; `match; `unmatch] from t
a     b     c mu
---------------------
"abc" "abc" 1 match
"def" "xyz" 2 match // Issue here, since match a value of column a in all value of b
"ghi" "ghi" 3 match
"lmn" "def" 4 unmatch

Solution

  • If you are looking to do row-wise match then you can use match operator (~) and each-both operator(').

     q) update  mu:?[a~'b;`match;`unmatch] from t