Home › Forums › kdb+ › how to parse functional select in q › Reply To: how to parse functional select in q
-
EDIT: sorry for the illegible code blocks, there seem to be serious issues with this forum software.
Can you make it more clear what you are trying to achieve?
“How to parse functional select” – this would be something like
q)parse"?[quote;();0b;time,sym,bid,ask!time,sym,bid,ask]" ? ,quote () 0b (!;,time,sym,bid,ask;,time,sym,bid,ask)
However this is no different from “how to parse any expression in q”, there is nothing special in the expression being parsed is a functional select.
If the question was “how to convert a functional select into a regular select” then your code is exactly doing that:
q)table:"quote" q)parse "select time, sym, bid, ask from ",table ? quote () 0b time,sym,bid,ask!time,sym,bid,ask
“How to get data from the functional select” is a different question. You might want to check Functional qSQL | Basics | kdb+ and q documentation – Kdb+ and q documentation (kx.com) which has plenty of examples. In this particular example you would simply write down the result of the parse expression in function call form:
?[$table;();0b;time,sym,bid,ask!time,sym,bid,ask]
Note that here we are casting the string to a symbol, but that’s only because that’s what conforms to your function’s signature. You might want to consider changing it such that it takes a symbol for the table name instead, in which case you wouldn’t need a cast:
?[table;();0b;time,sym,bid,ask!time,sym,bid,ask]