【问题标题】:Why do I have "message": "Expected 1 bindings, saw 0" when using array_agg with knex?为什么我有 \"message\": \"Expected 1 bindings, saw 0\" when using array_agg with knex 时?
【发布时间】:2022-11-25 21:54:42
【问题描述】:

我正在使用 postgres 并尝试在 knex 中使用 array_agg 发出请求,但出现错误:
“消息”:“预期 1 个绑定,看到 0”

有谁知道这个错误可能来自哪里?我该如何解决?

我的请求:

knex('user')
.leftJoin('user_has_restaurant','user_has_restaurant.user_id','user.id')
.leftJoin('restaurant','user_has_restaurant.restaurant_id', 
'restaurant.id')
.select([
'user.id AS user_id',
'user.name AS user_name',
 knex.raw(
  'ARRAY_AGG(restaurant.id) as id',
  'ARRAY_AGG(restaurant.name) as name',
  'ARRAY_AGG(restaurant.description) as description',
  'ARRAY_AGG(restaurant.website) as website',
  'ARRAY_AGG(restaurant.created_at) as created_at',
  'ARRAY_AGG(restaurant.updated_at) as updated_at')
])
.groupBy('user.id')
.whereIn('user.id',`${userId}`)

当然,我的 userId 是一个动态数组,例如 [1 , 2 , 3 ... ]

【问题讨论】:

    标签: javascript node.js postgresql knex.js array-agg


    【解决方案1】:

    尝试像这样传递它.whereIn('user.id',userId)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-30
      • 2017-06-19
      • 1970-01-01
      • 2020-08-04
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      相关资源
      最近更新 更多