sam jenkens
sam jenkens

Reputation: 23

how to efficiiently select first or last rows from a KDB table stored on disk

For an in-memory table, I can use sublist or take syntax to retrieve first x, last x elements.

How to do this efficiently for an on-disk table which may be very large? The constraint is that I don't want to cache all the data from table to memory to run the query.

Upvotes: 2

Views: 5646

Answers (2)

daveonhols
daveonhols

Reputation: 19

I suppose you can use the i column which is the row number (per partition!) on a historical.

So the first row would be select from trade where date=first date, i = 0
The last row would I guess be select from trade where date=last date, i=max i

This assumes normal partitioned by date stuff. If you have just a non-partitioned tables, probably select from trade where i=0 would be fine

Upvotes: 1

Ryan Hamilton
Ryan Hamilton

Reputation: 2605

.Q.ind - it takes a table and (long!) indices into the table - and returns the appropriate rows http://code.kx.com/q/ref/dotq/#qind-partitioned-index

Upvotes: 1

Related Questions