0

我对 nodejs 中的 aws sdk 进行了以下查询,并在 aws lamdba 中运行,使用参数数组时该查询不起作用:

executeStatement({ 
  Statement: `select * from "myTable"."myIndex" where "pk" = '?' and "sortKey5" >= 50 ORDER BY "sortKey5" DESC`,
  Parameters: [{"S": pk}] })

使用参数直接内联的相同查询有效

executeStatement({ 
 Statement: `select * from "myTable"."myIndex" where "pk" = 'xxx' and "sortKey5" >= 50 ORDER BY "sortKey5" DESC` })

这可能是'?'的语法 这是错误的,但我找不到任何具有其他语法的示例。

有谁知道如何编写语句以便它使用参数?

4

1 回答 1

1

看来,至少在 SELECT 语句中,需要省略 , 周围的单引号?foobar = ?而不是foobar = '?'.

所以你的查询是:

executeStatement({ 
  Statement: `select * from "myTable"."myIndex" where "pk" = ? and "sortKey5" >= 50 ORDER BY "sortKey5" DESC`,
  Parameters: [{"S": pk}]
})
于 2021-08-31T07:53:01.860 回答