5

How can I delete the first 10 rows from a kdb table? I want to delete specifically the first 10 rows returned from:

select [10] from mytable

I tried to use delete with the i index but the count of rows does not decrease:

count mytable
2201784
delete from mytable where i < 10
count mytable
2201784

Also the delete statement returns a number of rows to my Q console, not sure what that is.

Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91

3 Answers3

9

If you want to delete in-place from the table, you should reference it by name.

delete from `mytable where i < 10

Alternatively, reassign:

mytable:delete from mytable where i<10

When you run delete from mytable where i<10, it returns the table with the changes applied but does not apply them to mytable stored in memory.

http://code.kx.com/q/cookbook/faq/#how-do-i-delete-rows-from-a-table

The resources at http://code.kx.com answer many questions regarding day-to-day use of kdb.

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
skeevey
  • 611
  • 4
  • 11
4

you can use the drop operator _ on the table, and have 10 as your LHS argument mytable:10 _mytable

JPC
  • 1,891
  • 13
  • 29
0
delete from mytable where i<10
mnestor
  • 319
  • 1
  • 3
  • Are you sure? `count md (2201784i); delete from md where i < 100; count md (2201784i)`. Also the delete statement using the `where i<100` condition returns rows on my q console. It seems to work like a select statement. – Robert Kubrick Jun 04 '13 at 12:35