KX Community

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

Home Forums kdb+ Concatenation issue for atomic values

  • Concatenation issue for atomic values

    Posted by denakaran on October 6, 2021 at 12:00 am

    Hi guys,

    When i’m doing `$(“1″;”0”) it is automatically showing as “10”. Is there any way i can make it as `1`0 

    denakaran replied 8 months ago 2 Members · 6 Replies
  • 6 Replies
  • rocuinneagain

    Member
    October 6, 2021 at 12:00 am

    You can use each-right to cast each character one at a time:

    https://code.kx.com/q/ref/maps/#each-left-and-each-right

    q) `$”10″

    `10

    q) `$/:”10″

    `1`0

     

  • denakaran

    Member
    October 6, 2021 at 12:00 am

    Hey, thanks for your input here  but to be more clear

    if i’m having a table like this

    t:([]Vals:`$(“1″;”0″;”10”))

    if i’m passing the parameters as 1 and 0 means it should return 1 and 0 from table t. Also if i’m passing as 10 it should return as 10

     

    Currently it is showing the results as 1 and 0 for both 1,0 and 10. Please check the attached screenshot

     

  • rocuinneagain

    Member
    October 6, 2021 at 12:00 am

    All of these items are equivalent:

     

    q)"10" 
    "10" 
    q)("1";"0") 
    "10" 
    q)("10") 
    "10"

     

    They all resolve to 2 item lists containing characters

    https://code.kx.com/q/basics/datatypes/

    Here are some more example queries which may help:

     

    q)select from t where Vals in `$/:("1";"10") 
    Vals 
    ---- 
    1 10 
    
    q)select from t where Vals in `$/:("1";"0") 
    Vals 
    ---- 
    1 0 
    
    q)select from t where Vals in `$"10" 
    Vals 
    ---- 
    10 
    
    q)select from t where Vals in `$"1" 
    Vals 
    ---- 
    1

     

    You can use ‘=’ rather than ‘in’ if you are searching for only one value:

    q)select from t where Vals=`$"1" 
    Vals 
    ---- 
    1

    You can input your symbols directly rather than casting:

    q)`0`1`10 `0`1`10

     

  • rocuinneagain

    Member
    October 7, 2021 at 12:00 am

    A single character .i.e “1” is a type -10h
    A list of characters .i.e “10” is a type 10h
    You can create a single character list using ‘enlist’ .i.e

    q)type each ("1";"0";"11-15") /Some are lists some are not 
    -10 -10 10h 
    q)type each (enlist "1";enlist "0";"11-15") /All are lists 
    10 10 10h 
    q)("1";"0") 
    "10" 
    q)type each ("1";"0") 
    -10 -10h 
    q)(enlist "1";enlist "0") //Using enlist to make single character lists 
    ,"1" ,"0" 
    q)type each (enlist "1";enlist "0") 
    10 10h

    Using ‘enlist’ will help prevent unwanted concatenation for you.
    https://code.kx.com/q/ref/enlist/

  • denakaran

    Member
    October 7, 2021 at 12:00 am

    Hi , in my case i’m giving a multiselect option which may pass 1 or 0 or 10 or 11-15 or Above 15 etc.. So that i’m facing this issue

    `q))`$(“1″;”0″;”11-15”)
    `1`0`11-15
    q))`$(“1″;”0”)
    `10
    q))`$(“10”)
    `10

    So user may select anything from the list together.

  • denakaran

    Member
    October 7, 2021 at 12:00 am

    Hey , this really helps. I used the type to see when the user selects multiple values.

    q))type (“1″;”0”)
    10h
    q))type (“1″;”10”)
    0h

    So based on that i added the condition now which works fine for my scenario. Thanks a lot !!

Log in to reply.