0

I have a list of strings like this

q)select id from temp
id                               
---------------------------------
,"_"                             
"01coin"                         
"0chain"                         
"0dog"                           
"0-knowledge-network"            
"0-mee"                          
"0vix-protocol"                  
"0x"                             
"0x0-ai-ai-smart-contract"       
"0x678-landwolf-1933"            
"0xanon"                         
"0xcoco"                         
"0xdao"                          
"0xgasless-2"                    
"0xgen"
...                  

I need it to look like this

"_,01coin,0chain,0dog,0-knowledge-network,0-mee,0vix-protocol,...etc..."                  

What is the best approach to concatenate such a list into a single string in kdb ? Should I turn my "strings" into `symbols and then vs :/ them ??? I got this far but I don't know how to turn this list of "strings"; into a single "string,..."

("_,";"01coin,";"0chain,";"0dog,";"0-knowledge-network,";"0-mee,";"0vix-protocol,"; ...)

1 Answer 1

3

This should work.

exec”,”sv id from temp
exec((”,”sv id),”,”)from temp / with a trailing ,

sv converts vector into a scalar. In this case a list of string into a string.

See: https://code.kx.com/q/ref/sv/

vs is the opposite.

Sign up to request clarification or add additional context in comments.

6 Comments

If you want to join the list of strings that you have, you can simply raze (flatten) them. But based on your desired output, the answer I provided should work.
omg thank you x10 i forgot about raze , this did the trick: raze (exec (id,\:",") from temp)
You’re welcome. Do note that your approach will have a , at the end of the string. If that is what you want. My answer does not, although using my method you can simply add the , at the end too.
If you are using the list as a qsql filter. You don’t really need to manipulate it like that. You can simply use the list and use some of keywords like in <list of ids> for the filter.
Avoid creating large string queries, instead pass data across .e.g h({select from tab where id in x}; exec id from temp)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.