KX Community

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

Home Forums kdb+ If conditions $ vs ?

  • If conditions $ vs ?

    Posted by denakaran on July 30, 2022 at 12:00 am

    Sometimes i wonder how the $ differs with ? since most of the times both of them  returning the same results. Not sure when to use $ and ?.  Help me to understand this guys!

    q)$[1b;`true;`false]
    `true
    q)?[1b;`true;`false]
    `true
    q)t:([]name:enlist `hi)
    q)t
    name
    —-
    hi
    q)$[(count t)>0;`values;`novalues]
    `values
    q)?[(count t)>0;`values;`novalues]
    `values

    denakaran replied 2 months ago 3 Members · 2 Replies
  • 2 Replies
  • baichen

    Member
    July 30, 2022 at 12:00 am

    ? can be used in vector-based condition . For example:

    ?[101b;`a;`b]
    `a`b`a

    $ is used in single condition :
    $[1b;`a;`b]
    `a

     


  • sujoy

    Member
    August 3, 2022 at 12:00 am

    Apart from vector-based condition mentioned above, ? Will always run the fail condition unlike $.

    $[1;2;err]
    2
    
    ?[1;2;err]
    'err
    [0] ?[1;2;err]

Log in to reply.