如何在 Python 中使用 Couchbase 函数创建索引?
How to use Couchbase function in index creation in Python?
我正在尝试创建 。它适用于 Couchbase 管理控制台,但我在 Python 代码中遇到错误。我显然在使用 python 时做错了,但是我在 Python 中找不到任何关于使用函数创建索引的示例。这是一个有效的 N1QL:
CREATE INDEX `mytabenter code herele_date` ON `mytable`(-TONUMBER(`date`));
这是一个损坏的 Python 代码:
cb = Bucket('couchbase://localhost/mytable', password='passw0rd')
cb.bucket_manager().create_n1ql_index('mytable_date_desc', fields=[-TONUMBER('date_desc')], defer=True, ignore_exists=True)
函数 -TONUMBER 生成错误 "Unresolved reference"/"NameError: name 'TONUMBER' is not defined".
使用函数创建此类索引的正确方法是什么?
您需要转义 TONUMBER
,因为它是 N1QL 定义的函数,而不是直接在 Python SDK 中;以下示例应该有效:
manager.create_n1ql_index(
'mytable_date_desc',
fields=['(-TONUMBER(`date`))'],
defer=True,
ignore_exists=True)
.create_n1ql_index()
是为了方便,并不一定 API 完整。它允许您处理最简单的情况,但更复杂的情况最好通过查询 API.
由字符串处理
我正在尝试创建
CREATE INDEX `mytabenter code herele_date` ON `mytable`(-TONUMBER(`date`));
这是一个损坏的 Python 代码:
cb = Bucket('couchbase://localhost/mytable', password='passw0rd')
cb.bucket_manager().create_n1ql_index('mytable_date_desc', fields=[-TONUMBER('date_desc')], defer=True, ignore_exists=True)
函数 -TONUMBER 生成错误 "Unresolved reference"/"NameError: name 'TONUMBER' is not defined".
使用函数创建此类索引的正确方法是什么?
您需要转义 TONUMBER
,因为它是 N1QL 定义的函数,而不是直接在 Python SDK 中;以下示例应该有效:
manager.create_n1ql_index(
'mytable_date_desc',
fields=['(-TONUMBER(`date`))'],
defer=True,
ignore_exists=True)
.create_n1ql_index()
是为了方便,并不一定 API 完整。它允许您处理最简单的情况,但更复杂的情况最好通过查询 API.