Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB parameterized PartiQL query with executeStatement

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?

like image 838
fred_ Avatar asked Dec 18 '25 14:12

fred_


1 Answers

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}]
})
like image 172
Marco Lüthy Avatar answered Dec 20 '25 05:12

Marco Lüthy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!