首页 > 解决方案 > 如何使用 python SDK couchbase 将 n1ql 的结果插入存储桶

问题描述

我想使用 python 将 n1ql 的结果插入到存储桶“测试”中,但我不知道该怎么做,我是新手。

我使用 couchbase 搜索了文档 python SDK,但没有找到我正在努力解决的问题的答案。我不知道如何使用 upsert() 来解决这个问题。

from couchbase.cluster import Cluster
from couchbase.cluster import PasswordAuthenticator
from couchbase.n1ql import N1QLQuery
cluster = Cluster('couchbase://localhost:8091')
authenticator = PasswordAuthenticator('Administrator', 'root123')
cluster.authenticate(authenticator)
cb = cluster.open_bucket('test')
cb = cluster.open_bucket('pth')
cb.operationTimeout = 5000;
#N1QL Simple Query#
query = N1QLQuery("SELECT usr_id,score FROM pth ")

我想将结果放入存储桶“测试”中。

标签: pythoncouchbasebucket

解决方案


使用 INSERT INTO SELECT 语句。示例 8, 13-15 在 https://docs.couchbase.com/server/6.0/n1ql/n1ql-language-reference/insert.html


推荐阅读