Terry
Terry

Reputation: 519

Pass string parameter to remote process in kdb

I am trying to pass a variable that is string to the ipc query. This does not work for me.

Example:

[`EDD.RDB; "?[`tab;enlist(like;`OrderId;",("string Number),");();(?:;`Actions)]"]

I am trying to query this RDB where OrderId like Number(string) Number is a parameter but when I passed as string to the remote process, Number is not string any more. I tried to put string in front but still get the same result.

What I want to pass to remote process is this:

Number:"abc"
"?[`tab;enlist(like;`OrderId;"abc");();(?:;`Actions)]"

Upvotes: 0

Views: 564

Answers (2)

Matt Moore
Matt Moore

Reputation: 2775

Does the IPC query have to be string? Passing parameters would be cleaner using (func;params) syntax for IPC.

handleToRdb ({[number] ?[`tab;enlist(like;`OrderId;number);();(?:;`Actions)]};"abc")

Upvotes: 3

SeanHehir
SeanHehir

Reputation: 1593

EDIT as you have updated your question.

It's hard to give a solid answer here as your example is lacking information.

What you have posted is not a valid IPC call in KDB+. I suspect what you may be trying to run is something like:

h(`EDD.RDB; "?[`tab;enlist(like;`OrderId;",("string Number),");();(?:;`Actions)]"])

Assuming Number is an int (e.g. Number:123) then in that case you could rewrite it as:

h(`EDD.RDB;"select distinct Actions from t where orderID like \"",string[Number],"\"")

Which is easier to read and work with. Assuming Number is defined on the client side then the above should return an answer.

If you do want to use functional form then you could try something like:

"?[`tab;enlist (like;`orderID;string[",string[Number],"]);1b;(enlist`Actions)!enlist`Actions]"

As your query string.

If Number is already a string on your process, e.g Number:"123" then you should be able to either:

h(`EDD.RDB;"select distinct Actions from t where orderID like \"",Number,"\"")
OR
h(`EDD.RDB;"?[`tab;enlist (like;`orderID;string[",Number,"]);1b;(enlist`Actions)!enlist`Actions]")

Upvotes: 3

Related Questions