Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Space character within symbol literals

Tags:

kdb

I need to query a database which contains names of companies. I have list of around 50 names, for which i have to get the data. But I am unable to write a query using in command as there spaces in a name which are not being recognized. ex

select from sales where name in (`Coca Cola, `Pepsi)

This is giving me an error as 'Cola' is not being recognized. Is there a way to write such a query?

like image 884
Mancunia89 Avatar asked Oct 22 '22 13:10

Mancunia89


1 Answers

The spaces between the strings cause the interpreter to get confused. The `$() casts the list of characters to symbols.

q)t:([] a:1 2 3; name:`$("coca cola";"pepsi";"milk"))

q)select from t where name in `$("coca cola";"pepsi")
a name
-----------
1 coca cola
2 pepsi

You may also want to be careful of casing and either use consistently lower or upper case else that would cause unexpected empty results:

q)select from t where name in `$("Coca Cola";"Pepsi")
a name
------

q)select from t where upper[name] in upper `$("Coca Cola";"Pepsi")
a name
-----------
1 coca cola
2 pepsi
like image 68
John at TimeStored Avatar answered Dec 07 '22 20:12

John at TimeStored