Array-Select with Placeholders in Go

n1ql

#1

Hi,

I have a array select with placeholders.

query := gocb.NewN1qlQuery(“SELECT content.content.id FROM content WHERE content.type=“metadata” AND ANY v IN content.content.tenantIDs SATISFIES v=$1 END AND content.content.publishStatus=“published” ORDER by content.date DESC LIMIT 50;”)

tenant := 1
var params interface{}
params = append(params,tenant)

rows, err := bucket.ExecuteN1qlQuery(query, params)

This returns correct results, but does fetch every document, so query is very slow. If I do it without placeholders it works completly with index, without any document fetch:

query := gocb.NewN1qlQuery(“SELECT content.content.id FROM content WHERE content.type=“metadata” AND ANY v IN content.content.tenantIDs SATISFIES v=1 END AND content.content.publishStatus=“published” ORDER by content.date DESC LIMIT 50;”)
rows, err := bucket.ExecuteN1qlQuery(query, nil)

Do I something wrong? I notice this only in array select, normal wheres are working this way.

I’ doing it now by manually concat the string:
query := gocb.NewN1qlQuery(“SELECT content.content.id FROM content WHERE content.type=“metadata” AND ANY v IN content.content.tenantIDs SATISFIES v=” + fmt.Sprintf("%d", tenant) + " END AND content.content.publishStatus=“published” ORDER by content.date DESC LIMIT 50;")
rows, err := bucket.ExecuteN1qlQuery(query, nil)

That works perfectly, but is a bit ugly.

Thanks, Pascal


#2

Found the solution: it works with .AdHoc(false)