« I want to keep kdb rdb super fast and prevent users from introducing large latencies by using a timeout argument of 2 seconds. is this a good idea? | Main | How can I have kdb automatically load q code at startup in every session? »

How do I efficiently retrieve the first n rows of a query result?

select[n]. The first example below retrieves the first 10 rows, whereas the second example retrieves the last 10 rows:

select [10] from table where date=2011.02.27
select [-10] from table where date=2011.02.27

If the table is in memory, you can use the virtual column i to retrieve a specific range of rows:

select from table where i within (begin; end)

If you want to retrieve specific rows by index from a partitioned table, use .Q.ind.

C.f. # (take) and sublist

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Textile formatting is allowed.