KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ How to insert a boolean list into a table

  • How to insert a boolean list into a table

    Posted by Jonathan on December 16, 2024 at 4:50 pm

    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)” </p><p>and everything inserts correctly into the 3 columns. But if I store the list into variables and then insert it stops working. </p><p><br></p><p>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.

    unterrainer_ale replied 3 days, 4 hours ago 2 Members · 3 Replies
  • 3 Replies
  • unterrainer_ale

    Member
    December 16, 2024 at 9:59 pm

    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$())<br>q)a:1b;b:1b;c:1b;<br>q)a<br>1b<br>q)b<br>1b<br>q)c<br>1b<br>// client<br>q)value "2+2"<br>4<br>// You get the same error if you try to use value with variables that are not defined<br>q)value "g+h"<br>'g<br> [1] g+h<br> ^<br>q)h "`emulation insert (1b;1b;1b)"
    ,0
    q)h "emulation"
    a b c
    -----
    1 1 1
    q)h(insert;`emulation;(1b;1b;1b))<br>,1<br>q)h "emulation"<br>a b c<br>-----<br>1 1 1<br>1 1 1<br>// Note a,b,c is defined on the server<br>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

    • Jonathan

      Member
      December 17, 2024 at 1:56 pm

      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!

  • unterrainer_ale

    Member
    December 18, 2024 at 11:47 am

    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

Log in to reply.