3

I have the following query with the aws sdk in nodejs and running in aws lamdba that doesn't work when using the parameters array:

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

the same query with the parameter directly inline works

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

it's probably the syntax with '?' that is wrong but I couldn't find any sample with an other syntax.

does any one knows how to write the statement so that it uses the parameter?

fred_
  • 1,486
  • 1
  • 19
  • 31

1 Answers1

3

It seems that, at least in a SELECT statement, one needs to omit the single-quotes around the ?, e.g. foobar = ? rather than foobar = '?'.

So your query would be:

executeStatement({ 
  Statement: `select * from "myTable"."myIndex" where "pk" = ? and "sortKey5" >= 50 ORDER BY "sortKey5" DESC`,
  Parameters: [{"S": pk}]
})
Marco Lüthy
  • 1,279
  • 1
  • 11
  • 21