KX Community

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

Home Forums kdb+ K code in functional query 2

  • K code in functional query 2

    Posted by AAronD27 on April 15, 2025 at 8:18 am
    1. Give functional form for:

      select sum size by ticker:((string[id],:”.”),’string[ex])from trade_usq where any not null(size;price)

    2. After doing 

      parse”select sum size by ticker:((string[id],’\”.\”),’string[ex])from trade_usq where any not null(size;price)”

      I get;

      ?
      `trade_usq
      ,,(max$["b"];(~:;(^:;(enlist;`size;`price))))
      (,`ticker)!,((';,);((';,);($:;`id);".");($:;`ex))
      (,`size)!,(sum;`size)

      I have then wrote out;

      ?[`trade_usq;enlist(max$[“b”];(~:;(^:;(enlist;`size;`price))));(enlist`ticker)!enlist((‘;enlist);((‘;enlist);($:;`id);”.”);($:;`ex));(enlist`size)!enlist(sum;`size)]

      But this doesn’t seem to work? What is wrong with this?

    • This discussion was modified 3 days, 10 hours ago by  AAronD27.
    • This discussion was modified 3 days, 10 hours ago by  AAronD27.
    mwoods replied 3 days, 8 hours ago 3 Members · 2 Replies
  • 2 Replies
  • pgyorok

    Member
    April 15, 2025 at 9:38 am

    Note that you never need to use `each` with `string`. `string` already implicitly expands over lists.

    When using `parse` on a q expression, any functions in the `.q` namespace are replaced by their definition. You can type `.q` at the prompt to see these definitions, and if you work in q enough, you will learn to recognize them.

    `k){x/:y}` stands for `sv`

    `k){x’y}` stands for `each`, which is redundant as mentioned above

    So the full query would look like

    `</span><span style=”font-family: inherit; font-size: inherit;”>“</span></p><p>![t;();0b;enlist[`ric]!enlist(`$;(“.”sv/:;(string;(flip;(enlist;`sym;`exch)))))]</p><p>“`

  • mwoods

    Administrator
    April 15, 2025 at 9:41 am

    [Reposting answer above as plain text for readability]
    Note that you never need to use each with string. string already implicitly expands over lists.

    When using parse on a q expression, any functions in the .q namespace are replaced by their definition. You can type .q at the prompt to see these definitions, and if you work in q enough, you will learn to recognize them.

    k){x/:y} stands for sv

    k){x’y} stands for each, which is redundant as mentioned above

    So the full query would look like

    ![t;();0b;enlist[`ric]!enlist(`$;(“.”sv/:;(string;(flip;(enlist;`sym;`exch)))))]

    • This reply was modified 3 days, 8 hours ago by  mwoods.

Log in to reply.