Forum Replies Created

Page 2 of 2
  • unterrainer_ale

    Member
    June 10, 2024 at 10:29 am in reply to: need help on a query

    This should do

    129200

    q)t:([] timestamp:1 2 3;timeWin:(1 2 3;1 2 4 5;3 1 1 3 5))

    q)update timeWin:timeWin except’timestamp from t

    timestamp timeWin

    —————–

    1 2 3

    2 1 4 5

    3 1 1 5

  • unterrainer_ale

    Member
    May 30, 2024 at 8:09 am in reply to: help understanding a function

    Hey fav_pa,

    I believe there are a few more mistakes in the code you posted, can you share the source where you have it from?

    First, the part to create the path to save down is missing some code

    q) ` sv (`$":path/toTable";`tableName;`)
    `:path/toTable/tableName/

    Then you also miss the `p in

    @[;pvar;`p#]

    Other than that, the second code you posted makes sense

    `(` sv (tabPath;; table; )) set @[; pvar;`p#] pvar xasc .Q.en[tabPath] get table

     

  • unterrainer_ale

    Member
    March 28, 2024 at 10:56 am in reply to: how to parse functional select in q

    Well it really depends what you actually want to do. they keyword parse (parse | Reference | kdb+ and q documentation – Kdb+ and q documentation (kx.com)) simply parses an expression into a parse tree, in this case it parses a q-sql statement into a functional select. The output you got, is what your qsql looks like in form of a functional select.

    q)parse "select time,sym,bid,ask from t"
    
    ?
    t
    ()
    0b
    time
    sym
    bid
    ask!
    time
    sym
    bid
    ask
    q)t:([] time:5?.z.p; sym:5?
    3; bid:5?10.0; ask:5?10.0)
    q)t
    time sym bid ask
    ---------------------------------------------------
    2014.11.16D17:25:17.686664320 enf 3.017723 3.927524
    2012.10.31D16:48:20.456221120 plh 7.85033 5.170911
    2016.10.06D02:12:56.529433024 nni 5.347096 5.159796
    2005.07.26D06:48:01.359027808 glc 7.111716 4.066642
    2016.10.09D03:08:41.154352640 gkp 4.11597 1.780839
    q)eval parse "select time,sym,bid,ask from t"
    
    time sym bid ask
    ---------------------------------------------------
    2014.11.16D17:25:17.686664320 enf 3.017723 3.927524
    2012.10.31D16:48:20.456221120 plh 7.85033 5.170911
    2016.10.06D02:12:56.529433024 nni 5.347096 5.159796
    2005.07.26D06:48:01.359027808 glc 7.111716 4.066642
    2016.10.09D03:08:41.154352640 gkp 4.11597 1.780839

    However, you don’t actually need to parse/transform your qsql to a functional select inside your function if you don’t really “want” (I recommend using functional selects only if you really need to, i.e. if you need to parameterise your queries)

    Here you have a function that takes a table as input and then selects from it using qsql

    q){select time,sym,bid,ask from x}[t]
    
    time sym bid ask
    ---------------------------------------------------
    2014.11.16D17:25:17.686664320 enf 3.017723 3.927524
    2012.10.31D16:48:20.456221120 plh 7.85033 5.170911
    2016.10.06D02:12:56.529433024 nni 5.347096 5.159796
    2005.07.26D06:48:01.359027808 glc 7.111716 4.066642
    2016.10.09D03:08:41.154352640 gkp 4.11597 1.780839

    A very helpful read about functional selects is the Whitepaper about parse trees.

    Parse trees and functional forms | White Paper | kdb+ and q documentation – Kdb+ and q documentation (kx.com)

    Hope this helps

    Alex

  • unterrainer_ale

    Member
    March 19, 2024 at 11:01 am in reply to: Whats the best toolset for developing in kdb+?

    I use kdb studio to test, debug and develop code and IntelliJ as an editor. I like IntelliJ because you can easily search for function usage, jump to definitions etc. It’s great when reading code. It also has a kdb analyst and q plugin so you can actually run code in IntelliJ (similar to studio you connect to a q process) and display results but I never really tried it.

  • unterrainer_ale

    Member
    January 17, 2024 at 12:00 am in reply to: Selecting date from table

    I would avoid using ChatGPT for KDB/Q. It’s often very far off. Read Q for Mortals, it’s a good start to learn Q

  • unterrainer_ale

    Member
    July 12, 2023 at 12:00 am in reply to: Navigating a nested object using apply.

    Hi Simon,

    is there any chance you could provide an example of bigNestedThing? or an extract? In the meantime, try to have a look at cross-section and how it works with apply.

  • unterrainer_ale

    Member
    May 30, 2023 at 12:00 am in reply to: select with combinational conditions

    Something worth adding to the previous answers: If you can transform your filter into a table then the select is much easier. To illustrate

    q)t:flip `date`data!(2023.05.20 2023.05.20 2023.05.20 2023.05.19 2023.05.19 2023.05.19;`a`c`b`b`b`c) 
    q)t 
    date      data 
    --------------- 
    2023.05.20 a 
    2023.05.20 c 
    2023.05.20 b 
    2023.05.19 b 
    2023.05.19 b 
    2023.05.19 c 
    
    q)select from t where ([] date;data) in ([] date:2023.05.20 2023.05.20 2023.05.19;data:`a`b`b) 
    date      data 
    --------------- 
    2023.05.20 a 
    2023.05.20 b 
    2023.05.19 b 
    2023.05.19 b 
    
    q)filter:([] date:2023.05.20 2023.05.19 2023.05.18 2023.05.17; data:(`a`b;enlist `b;`c`d`a;`d`a)) 
    q)filter 
    date        data 
    ----------------- 
    2023.05.20 `a`b 
    2023.05.19 ,`b 
    2023.05.18 `c`d`a 
    2023.05.17 `d`a 
    
    q)ungroup filter 
    date      data 
    --------------- 
    2023.05.20 a 
    2023.05.20 b 
    2023.05.19 b 
    2023.05.18 c 
    2023.05.18 d 
    2023.05.18 a 
    2023.05.17 d 
    2023.05.17 a 
    
    q)t1:ungroup filter 
    q)select from t where ([] date;data) in t1 
    date      data 
    --------------- 
    2023.05.20 a 
    2023.05.20 b 
    2023.05.19 b 
    2023.05.19 b
Page 2 of 2