Carrein
Carrein

Reputation: 3361

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

Upvotes: 0

Views: 184

Answers (2)

Phil
Phil

Reputation: 111

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

Upvotes: 3

Enda Burke
Enda Burke

Reputation: 21

Firstly, I wouldn't name the column as value. This will lead to errors.

index val  number
-----------------
0     a_fo 999
1     b_fo 999
2     c_fo 999
3     c_ba 999

Using delete should do i

t:delete from t where val like "c_*"

You need to redefine t if you want the table to update.

Upvotes: 2

Related Questions