Space character within symbol literals
Asked Answered
V

2

6

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?

Veinule answered 2/4, 2013 at 16:45 Comment(0)
H
4

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
Harijan answered 2/4, 2013 at 17:46 Comment(0)
R
0

You need to do something like the following:

select from sales where name in `$("Coca Cola";"Pepsi")
Reverential answered 2/4, 2013 at 16:54 Comment(2)
Thanks for the suggestion, I tried using this, it doesn't give any error, but the query is returning zero results, whereas I know there are entries in the database.Veinule
what type is the name column?Reverential

© 2022 - 2024 — McMap. All rights reserved.