Forum

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

Kog Scripts: How do I use Lua functions within SQL

by MikeAtkinson » Tue Jul 16, 2013 8:41 am

I'm running a Kog Script and want to factor out similar code from a sequence of SQL statements. I think I should be able to use Lua variables or functions to do this, but I'm not sure how.
Reply with quote Top
Contributor
Offline
Posts: 184
Joined: Wed May 29, 2013 2:10 pm
Location: Bracknell

Re: Kog Scripts: How do I use Lua functions within SQL

by MikeAtkinson » Wed Jul 17, 2013 5:00 pm

Lua functions may be used in a similar way to Lua variables within SQL statements. So for example the following Kog Script queries the SYS.IPE_USER table.

Code: Select all

function x() return "sys.ipe_user" end;
select * from $x();
Functions may also be used in expressions, like:

Code: Select all

function z() return 2; end;
select $(1+z());
Functions may also take parameters, as in the following example:

Code: Select all

a = { "sys.ipe_user", "sys.ipe_schema"}
function x(v) return a[v]; end;
for i = 1,2 do
    select * from $(x(i));
end
Reply with quote Top

Who is online

Users browsing this forum: No registered users and 1 guest

cron