LET multiple variables

Hello. Is it possible to have a variable referencing another variable inside the LET clause?

I’ve tried the following:

SELECT a,b
FROM default
LET a=1, b=a+1

but b is not printed, as a is not recognized in b's assignment. Thanks!

Hi @manusyone,

In the LET expression, RHS can have constant expressions or references to data from the projected document. In this case, this is treated as:

SELECT a,b
FROM default
LET a=1, b= default.a+1

Since default.a is missing, b goes missing in the projection.

2 Likes

So there is no way to achieve the functionality I mentioned above? I ask this because I have quite an extensive operation going on in the first part of the LET statement that I would like to reuse on the second part, and the only way I am seeing that we can solve this is to duplicate all of the code again…

There is feature request for this https://issues.couchbase.com/browse/MB-19772

1 Like