Home › Forums › kdb+ › parse tree not working for simple select › Re: parse tree not working for simple select
-
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
You can read more about parse here and parse trees here
*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.