cancel
Showing results for 
Search instead for 
Did you mean: 

Using namespace variable in q-sql

Flying
New Contributor III
Hi,

I noticed that namespace variables behaviour very differently when used within q-sql. For an illustration, please refer to the code below.

\d .namespace

HELLO:`World
DATA:([]S:`Hello`World;V:2?100f)

fun1:{show HELLO;show DATA}
fun2:{show select from DATA where V=HELLO}

\d .

.namespace.fun1[] /ok
.namespace.fun2[] /error!

Calling .namespace.fun1 yields that designed output with .namespace.HELLO and .namespace.DATA shown.

But calling .namespace.fun2 yeilds 'HELLO error (but not 'DATA error).

After going through the explanations about namespace usage in Wiki, I'm still not very sure if there is a special scoping rule being applied only to q-sql.

Could anyone with the knowledge help to shed some light on this behaviour?

Best regards,
Flying
3 REPLIES 3

rahul_asati04
Contributor
Value on function shows that table comes in context section which means it is read from context in which the function is defined (and not the one function belongs to)  whereas query filters comes in constant section which means they are read from context from in which function is being called.

So when you call this function from global namespace , it tries to find HELLO variable in that namespace and gives the error.

q)value .namespace.fun2
0x0ba0a181a20a04a3520005
,`x
`symbol$()
`namespace`DATA
0b
,(=;`V;`HELLO)
?
k){1 .Q.s x;}
"{show select from DATA where V=HELLO}"

Flying
New Contributor III
Thanks, Rahul. This explanation is clear as crystal. 

May I know where I can find the exact scoping rule of constants? I know the variable scoping rule well in Q4M, but I don't recall reading about constant scoping rules anywhere.

rahul_asati04
Contributor
Hi,
I am not sure if its explicitly mentioned in any doc.