Search code examples
kdb

Searching a string having *


I have a table with symbols containing *.

q)sl:([] s:(`$"g*g";`$"b*l";`$"bx"))
q)sl
s
---
g*g
b*l
bx

How to escape the * (wild-card char) while searching, I want to search all the symbols containing * as a normal character ?

e.g. this one returns both rows containing 'b' , I just want it to return 'b*l'

q)select from sl where s like "b*"
s
---
b*l
bx

Solution

  • You can do this by using square brackets around the special character, as mentioned here.

    So in this case:

    q)select from sl where s like "b[*]*"
    s  
    ---
    b*l
    

    Or to match anything with a * in it:

    q)select from sl where s like "*[*]*"
    s  
    ---
    g*g
    b*l