2021.10.06 08:53 AM - edited 2021.10.06 08:54 AM
2021.10.07 05:42 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/
2021.10.06 09: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
2021.10.06 09:31 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
2021.10.06 09:42 AM - edited 2021.10.07 01:16 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
2021.10.07 03:07 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.
2021.10.07 05:42 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/
2021.10.07 09:21 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 !!
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.