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 variables in SQL statements?

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

I'm running a Kog Script and I want to use the results of one query to alter another query. For example I want to find the default schema for a user, then use that schema to access a table.
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 variables in SQL statements?

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

Variables are introduced into SQL statements within Kog Scripts using a $.

Code: Select all

a = "sys.ipe_user"
select * from $a;
If the character following the variable name is not an alphanumeric character then the variable should be enclosed by ().

Code: Select all

a = "sys.ipe_"
select * from $(a)user;
variables may be used in expressions as long as the expression may be evaluated to a Lua string or number. For example

Code: Select all

quote = "'"
a = "aaa"
select $(quote .. (a .. "bbb") .. quote); /* returns 'aaabbb' */

x = 1
y = 2;
select $(x+y+3);  /* returns 6 */
Reply with quote Top

Who is online

Users browsing this forum: No registered users and 1 guest

cron