Forum

Kognitio Console issues, advice, etc.
Contributor
Offline
Posts: 184
Joined: Wed May 29, 2013 2:10 pm
Location: Bracknell

Why does $tab[1] fail to compile

by MikeAtkinson » Wed Aug 31, 2016 2:27 pm

I was trying to use a value from a Lua table in an SQL predicate but it errors, complaining about concatenating a table value. I made a small example here of what doesn’t work:

Code: Select all

tab = {5,6}
select value from values between 1 and 10
where value < $tab[1];
Reply with quote Top
Contributor
Offline
Posts: 184
Joined: Wed May 29, 2013 2:10 pm
Location: Bracknell

Re: Why does $tab[1] fail to compile

by MikeAtkinson » Wed Aug 31, 2016 2:28 pm

This is because Kog script interprets the select statement as:

Code: Select all

sql("select value from values between 1 and 10 where value < "  .. tab .. "[1]");
It should be:

Code: Select all

tab = {5,6}
select value from values between 1 and 10 where value < $(tab[1]);
Anything within $( ) is interpreted as a Lua expression, so it is now interpreted as:

Code: Select all

sql("select value from values between 1 and 10 where value < " .. tab[1] );
Reply with quote Top

Who is online

Users browsing this forum: No registered users and 1 guest

cron