It's not entirely clear what you are trying to achieve when you only supply two broken queries.
Adding where to your query was a suggestion based on the return type being a list of booleans. Using where with your query returns the indexes of tab where c2>16. This could then be fed back into the table to return the desired data.
q)tab where ?[tab;til 10;(>;`c2;16)] c1 c2 ----- 7 17 8 18 9 19
You'll need to use semicolons to form a valid parse tree as shown here https://code.kx.com/q/wp/parse-trees/#eval-and-value like you have used in your first query but not your second.
This was all based off the assumption that you were attempting to use simple execs in functional form https://code.kx.com/q/basics/funsql/#simple-exec
In response to @cillianreilly and @mchbrn-q
It seems, simple exec parse tree has a dual nature : It can act as a "c" and an "a" in ?[t;c;b;a] .
It seems like a "c" here:
?[tab;til 10;(where;(>;`c2;16))] /Equivalent ?[tab;til 10;((&:);(>;`c2;16))]
It seems like an "a" here:
Yeah that's interesting. And since "a", the select phrase, can take a parse tree, you could translate the functional simple exec
q)?[tab;til 10;(last;`c2)] 19
to the functional exec
q)exec last c2 from tab 19 q)parse "exec last c2 from tab" ? `tab () () ,(last;`c2) q)?[tab;();();(last;`c2)] 19
I can't find any examples online of standard qSQL simple execs though? I don't know if it exists because https://code.kx.com/q/ref/exec/#syntax doesn't reference any phrases that allows for indexes . . .
As you've mentioned parse trees in your post title, I'll limit the scope of the following examples here using parse on a select statement*;
If you want to carry out of a functional select for both of the queries above, I suggest using the parse keyword to determine the components of the phrase:
// c2>16 example q)parse "select from tab where c2>16" ? `tab ,,(>;`c2;16) 0b () q)?[tab;enlist (>;`c2;16);0b;()] c1 c2 ----- 7 17 8 18 9 19 // last c2 example q)parse "select last c2 from tab" ? `tab () 0b (,`c2)!,(last;`c2) q)?[tab;();0b;enlist[`c2]!enlist (last;`c2)] c2 -- 19
*There are other ways of retrieving specific values for the queries you've listed. For example, you could also write last tab[`c2] to fetch the last value in the c2 column
Hope this helps.
Tel: +44 (0)28 3025 2242
Tel: +1 (212) 447 6700
Tel: +61 (0)2 9236 5700