0

I want to execute the following in an RDB or any other proc:

?[(10;#;`trade);();0b;()] (1)

I have a parser that converts string qsql queries to functional form and then send them from the gw to the correct process to be resolved. All well with more complex queries , but now someone wants to run 10#trade.

In order for my parser to work I need to convert it to the functional form of select from 10#trade. The only problem is that when I do that I get a Mismatched error on the process.

I cannot seem to run (1) even directly on the process.

2 Answers 2

1

Your example is trying to mix a parse tree with a functional select which is not going to work.

You can limit from within a select/functional-select:

parse"select[5] from trade"
?
`trade
()
0b
()
5
?[`trade;();0b;();5]
a
-
1
1
1
1
1

To do exactly what you asked would be:

?[eval  (#;5;`trade);();0b;()]
a
-
1
1
1
1
1
Sign up to request clarification or add additional context in comments.

1 Comment

thank you. This is what I was looking for. I completely forgot about select[5]from table
1

Couple of things here. Firstly your parse tree of 10#trade is in the wrong order in the expression labeled (1). It should read (#;10;`trade)

q)value(#;10;`trade)
`trade`trade`trade`trade`trade`trade`trade`trade`trade`trade
q)value(10;#;`trade)
'length
  [0]  value(10;#;`trade)

Secondly, as you can see, evaluating that parse tree gives you a list of symbols, which breaks the functional select, since it expects a table or table name as the first parameter.

What you can do is run eval on that parse tree inside your functional select, which will give you your result. But this actually does more work than you need, as the result of eval is what you're looking for, without running the functional select. But running an eval on user supplied code is generally a bad idea, as it's subject to code injection.

q)?[eval(#;10;`trade);();0b;()]

What might work better for you instead is to consider the 5th parameter of a functional select: https://code.kx.com/q/basics/funsql/#rank-5. This behaves just like the # operator:

q)(10#trade)~select[10]from trade
1b
q)// functional form:
q)(10#trade)~?[`trade;();0b;();10]
1b

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.