KX Community

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

Home Forums kdb+ SQL query to Functional query[Parse Tree] Re: SQL query to Functional query[Parse Tree]

  • dcrossey

    Member
    September 24, 2021 at 12:00 am

    You could update the type of each time column for each table in your dictionary as follows:

     

    q)t1:([]c1:`a`b`c;c2:1 2 3;c3:("10:00";"10:30";"11:00")) 
    q)t2:([]c1:`d`e`f;c2:4 5 6;c4:("09:00";"10:30";"11:30")) 
    q)d:`t1`t2!(t1;t2) 
    q)d[`t1] 
    c1 c2 c3 
    ------------- 
    a 1 "10:00" 
    b 2 "10:30" 
    c 3 "11:00" 
    
    q)d2:{![x;();0b;enlist[y]!enlist ($;"T";y)]}'[d;`c3`c4] 
    q)d2[`t1] 
    c1 c2 c3 
    ------------------ 
    a 1 10:00:00.000 
    b 2 10:30:00.000 
    c 3 11:00:00.000

     

    This is an example of using binary each (also known as each both), passing in one key/value of the dictionary and one column per iteration into the lambda.

    Note – I’ve used time only “T” as a brief example here. I noticed you were using lower case “p” – if your time/date column is a string column, you’ll need to use upper case “P” to cast correctly.

    Cheers,

    David