https://learninghub.kx.com/forums/topic/how-to-insert-a-boolean-list-into-a-table
I have a table on a remote process with 3 column. Each one should take a boolean value. I've tried inserting a list of booleans into this table but I keep getting errors.
If I try doing this, it works:
h" `emulation insert (1b;0b;0b)"
and everything inserts correctly into the 3 columns. But if I store the list into variables and then insert it stops working.
h" `emulation insert (resultCol1;resultCol2;resultCol3)"
this gives me a b"resultCol3" error and I'm not sure why. The values are the exact same. Any help would be appreciated.
This is because the standard definition of .z.pg (the handle for synchronous messages) is value. value evaluates a string using variables that are defined locally. Because the values you use in the string query aren't defined on the process you send the query to, you're getting an error. You can send your query as a parse tree and it will use the local definition of the variables (from the client side)
// server
q)emulation:([] a:`boolean$(); b:`boolean$(); c:`boolean$())
q)a:1b;b:1b;c:1b;
q)a
1b
q)b
1b
q)c
1b
// client
q)value "2+2"
4
// You get the same error if you try to use value with variables that are not defined
q)value "g+h"
'g
[1] g+h
^
q)h "`emulation insert (1b;1b;1b)"
,0
q)h "emulation"
a b c
-----
1 1 1
q)h(insert;`emulation;(1b;1b;1b))
,1
q)h "emulation"
a b c
-----
1 1 1
1 1 1
// Note a,b,c is defined on the server
q)h"`emulation insert (a;b;c)"
,2
q)h"emulation"
a b c
-----
1 1 1
1 1 1
1 1 1
q)a:4
q)b:5
// a and b defined in local process (no boolean)
q)value "a+b"
9
// defining variables locally that can be send via a parse tree
q)x:1b;y:1b;z:1b
q)h(insert;`emulation;(x;y;z))
,3
q)h"emulation"
a b c
-----
1 1 1
1 1 1
1 1 1
1 1 1
You can read more about IPC here https://code.kx.com/q/basics/ipc/#send-messages
I was actually sending the query as a parse tree but after seeing your response, I saw I was adding quotations to my handle query! Removed them and it's working now. Thank you!
Hi Jonathan, great, glad it worked. Just remember, you can send queries via parse trees like
handle(function;argument1;...;argumentN)
q)h(insert;`emulation;(1b;1b;1b))
,1
q)h "emulation"
a b c
-----
1 1 1
1 1 1