Couchbase N1QL基本选择带有命名参数

时间:2017-08-14 11:36:48

标签: python couchbase

尝试基本的N1QL选择(由official docs给出的查询的简化版本)似乎只适用于有序参数,并且至少对我来说不起作用命名参数(返回空集):

from couchbase.n1ql import N1QLQuery
from couchbase.bucket import Bucket
bucket = Bucket('couchbase://127.0.0.1/travel-sample')

# ordered param - works
query = N1QLQuery('SELECT airportname, city, country FROM `travel-sample` WHERE city=$1', "London")

# named param - does not work
query = N1QLQuery('SELECT airportname, city, country FROM `travel-sample` WHERE city=my_city', my_city="London")

for row in bucket.n1ql_query(query):
    print(row)

命名参数查询我做错了什么?

1 个答案:

答案 0 :(得分:0)

vsr的答案几乎是正确的,你的查询应该是: Started DELETE "/tasks/1" for ::1 at 2017-08-14 12:59:40 -0700 Processing by TasksController#destroy as JS Parameters: {"id"=>"1"} Task Load (0.1ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = ? LIMIT 1 [["id", 1]] User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]] (0.1ms) begin transaction SQL (0.4ms) DELETE FROM "tasks" WHERE "tasks"."id" = ? [["id", 1]] (0.6ms) commit transaction Completed 500 Internal Server Error in 15ms (ActiveRecord: 1.3ms) ActionView::MissingTemplate - Missing template tasks/destroy, application/destroy with {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee]}. Searched in: * "/Users/lizbayardelle/Dropbox/Code/FAM/app/views" * "/Users/lizbayardelle/.rvm/gems/ruby-2.3.3/gems/ckeditor-4.2.2/app/views" * "/Users/lizbayardelle/.rvm/gems/ruby-2.3.3/gems/devise-4.2.0/app/views" :

语句文本中的命名变量需要$前缀,但您不需要为命名参数本身添加前缀。

我将为您引用的页面提交文档错误以解决此问题。

感谢。