How to write nested N1QL batch read?


#1

I have stored below data in couchbase:

When I am reading I will have key in second row i.e. 0001410005……………sku1 as input and based on this key I’ll retrieve guid; value of which is the key for first row i.e. <PriceInvRspRow1 .toString()>

Note that the value in first row is serializedDocument data not JSONDocument.

I have written below query to retrieve this data:
Statement fluentStatement =
Select.select("*")
//Expression.i escapes an expression with backticks
.from(i(dsBucket.name()))
//Expression.x creates an expression token that can be manipulated
//Expression.s creates a string literal
.where(x(“META(default).id”).eq(x( Select.select(“guid”)
//Expression.i escapes an expression with backticks
.from(i(dsBucket.name()))
//Expression.x creates an expression token that can be manipulated
//Expression.s creates a string literal
.where(x(“META(default).id”).eq("$1"))

            )));

But I am getting error:
[{“msg”:“Duplicate subquery alias default”,“code”:4020}]

Can you plz tell me where I am doing wrong and what is the best way to achieve this.

Thanks in advance.


#2

Hi,

You need to use AS with your keyspace names. Each AS should supply a different alias.


#3

Thanks Gerald,

Can you plz rewrite above query using AS. I am not getting any example code.

Thanks in advance.


#4

For example with AS.

SELECT *
FROM mybucket AS doc1
JOIN mybucket AS doc2...