0

For a normal table, we can select one row using select[1] from t. How can I do this for HDB?


I tried select[1] from t where date=2021.02.25 but it gives error

Not yet implemented: it probably makes sense, but it’s not defined nor implemented, and needs more thinking about as the language evolves

kgf3JfUtW
  • 13,702
  • 10
  • 57
  • 80

3 Answers3

2

select[n] syntax works only if table is already loaded in memory. The easiest way to get 1st row of HDB table is:

1#select from t where date=2021.02.25

select[n] will work if applied on already loaded data, e.g.

select[1] from select from t where date=2021.02.25
Anton Dovzhenko
  • 2,399
  • 11
  • 16
0

I've done this before for ad-hoc queries by using the virtual index i, which should avoid the cost of pulling all data into memory just to select a couple of rows. If your query needs to map constraints in first before pulling a subset, this is a reasonable solution.

It will however pull N rows for each date partition selected due to the way that q queries work under the covers. So YMMV and this might not be the best solution if it was behind an API for example.

/ 5 rows (i[5] is the 6th row)
select from t where date=2021.02.25, sum=`abcd, price=1234.5, i<i[5]
user20349
  • 509
  • 2
  • 9
0

If your table is date partitioned, you can simply run

select col1,col2 from t where date=2021.02.25,i=0

That will get the first record from 2021.02.25's partition, and avoid loading every record into memory.

Per your first request (which is different to above) select[1] from t, you can achieve that with

.Q.ind[t;enlist 0]
Sean O'Hagan
  • 1,681
  • 8
  • 14