Use a list as variable in SQL Query
![Sv3n-Sk4](https://us.v-cdn.net/6038231/uploads/Dataiku/nAvatar18.png)
Hello everyone,
I need your help in using a list as project variable in a SQL query.
I have a dataset with a list on numbers, with a custom python recipe, I stored the numbers as list in my variable project. It's looking like this :
{
"liste": [
12265378,
9122915,
12292085,
12514810001,
12241211,
12262172,
4624440]
}
I now would like to use this list in my SQL recipe in my where condition as :
SELECT *
FROM TABLE
WHERE NUMBERS IN ('${liste}')
But it seems Dataiku is reading it as a long string.
If anyone could help please (it will help me a lot for this project and a lot of others).
Thanks!
Operating system used: Windows
Answers
-
Hui Xiang Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 5 Dataiker
There is a related thread here: https://community.dataiku.com/t5/Using-Dataiku/Reuse-Dataiku-variables-list-in-SQL/td-p/3247.
-
Hui Xiang Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 5 Dataiker
You can also create your variable looking like this "liste": "(12265378,
9122915, 12292085, 12514810001, 12241211, 12262172, 4624440)". Instead of using the square brackets, use the curve brackets, so they appear as a string and your sql query will look like this SELECT *FROM "TABLE" WHERE "NUMBERS" IN ${liste}