Hidden arguments of functional select

In one of my previous posts, I discussed functional form of select, update, exec and delete. If you remember, the general form of a functional select is ?[t;c;b;a] where t is the table, c is for constraints, b for by clause and a for aggregation. Most of the time, you will see only these 4 arguments but functional select can actually have up to 6 arguments!

The full form looks like this:

?[t;c;b;a;n;i]

where n stands for number of rows and i for specific rows you want to extract.

Let’s look at some examples!

t:([];time:5?.z.t;sym:5?`AAPL`MSFT`IBM;price:5?100;size:5?200)

A simple functional select to call the entire table:

q)?[t;();0b;()]
time sym price size
----------------------------
04:54:11.685 MSFT 73 140
13:01:04.698 IBM 90 104
05:18:45.828 IBM 43 10
02:25:54.221 MSFT 90 1
11:32:19.305 AAPL 84 90

If we only want the first two rows, we set n to 2:

Anxiety issue is something that men assume tadalafil cheapest in the head. The effect lasts levitra online order 24 hours, which means you can indulge in multiple sessions of lovemaking within that specific duration. The smarter thing to do is to get the virus removed, or you are going to continue free viagra pill to work on different kinds of people who have this issue. Sildenafil citrate is the basic component used in the formulation of tadalafil online india Kamagra Soft Tabs involve Sildenafil Citrate which causes vasodilation; the medication was originally intended to treat Pulmonary Arterial Hypertension, the universal thought on effectiveness still lies on brands.
q)?[t;();0b;();2]
time sym price size
----------------------------
04:54:11.685 MSFT 73 140
13:01:04.698 IBM 90 104

To get last two rows, we set n to -2:

q)?[t;();0b;();-2]
time sym price size
----------------------------
02:25:54.221 MSFT 90 1
11:32:19.305 AAPL 84 90

If we only want first and third row, set n to 0W and then, i to 0 2,

q)?[t;();0b;();0W;0 2]
time sym price size
----------------------------
04:54:11.685 MSFT 73 140
05:18:45.828 IBM 43 10

To get first, third and fourth row:

q)?[t;();0b;();0W;0 2 3]
time sym price size
----------------------------
04:54:11.685 MSFT 73 140
05:18:45.828 IBM 43 10
02:25:54.221 MSFT 90 1

Not many people are aware of these two extra arguments so you can use them to impress your colleagues!

Join the Conversation

1 Comment

  1. how to query hdb dynamic enough such that byClause, selectCols, whereCols are dynamically build and then query hdb?
    something like below i have got so far, but still working on to improve it such that user pass args and build dynamic hdb query.
    selectCols:`date`root`norm_sym`expiration_date;
    byCols:`norm_sym`root;
    whereCols:((“sym”;”`AAPL;`JPMC”);(valid;1b))
    ?[res1; ();byCols!byCols;(selectCols!selectCols)]

Leave a comment

Your email address will not be published. Required fields are marked *