Search code examples
kdb

Remove entry in KDB column table with regex matching?


How can i remove a row in a KDB table matching a certain regex?

For example:

Initial Table

index | value  | number
  0   |  a_fo  |  999
  1   |  b_fo  |  999
  2   |  c_fo  |  999
  3   |  c_ba  |  999

The query should remove all entries in the value column that matches the regex c_*, where the value starts with c_ and any length of characters afterwards.

Resultant Table

index | value  | number
  0   |  a_fo  |  999
  1   |  b_fo  |  999

Solution

  • Alternatively you can index in to avoid using the delete template for something a bit quicker

    t where not t[`value] like "c*"
    

    Or else use a functional delete

    ![t;enlist(like;`value;"c_*");0b;`$()]
    

    Regarding naming the column value which is a reserved keyword in q you can use .Q.id which will rename badly named variables to avoid any issues for example :

    .Q.id t
    results in the columns `index`value1`number