Equivalent of WHERE .... IN


I’m trying to make a N1QL query with the Python SDK.
I have a Python list including all the id of the documents I need to retrieve from my Couchbase database.

My Python list is cluster0_id.
And my query is:

query = 'SELECT f1.date_record, \
                f1.id_cycle, \
                f1.train, \
                f1.vehicule, \
                f1.dcu, \
                datas.Time, \
                datas.PPOR, \
                datas.IPOR, \
                datas.TPOR, \
                datas.FDCF, \
                datas.FDCV \
        FROM R2N_door_system.opening.f1 UNNEST datas \
        WHERE f1.id_cycle IN cluster0_id'

I tried with ANY … SATISFIED too but without succes.
I tried to modify the list cluster0_id to an Array to satisfy the documentation but without success.

Do you have an idea ?



Ref: N1QL Queries from the SDK | Couchbase Docs

I’m not particularly familiar with Python but that looks like you’re including the text of the variable name in your string, rather than the contents. Perhaps could use:

result = cluster.query("...WHERE f1.id_cycle IN $1", cluster0_id)



1 Like


Thanks for your reply. It’s the solution !!!

For Python, $1 has to be a list and not an array.

All done.