[英]How to use f-Literal with PartiQL in AWS and boto3 and a Condition on the sort key
這是我目前的代碼
table_name = 'TableName'
pk = "CID-73665"
Condition = "begins_with(sk,'CUS#')"
# get item
stmt = f"SELECT * FROM {table_name} WHERE pk=? and {Condition}"
pmt =[{
"S": pk
},
{
"S": sk
}]
resp = dynamodb_client.execute_statement(
Statement=stmt , Parameters= pmt
)
pp.pprint(resp['Items'])
但我收到此錯誤消息:
NameError: name 'sk' is not defined
任何人都知道什么可能是錯的?
嗯,'sk' 沒有定義。 你這樣試試
table_name = "TableName"
pk = "CID-73665"
sk = "CUS#"
# get item
stmt = f"SELECT * FROM {table_name} WHERE pk=? and begins_with('sk', ?)"
pmt = [{"S": pk}, {"S": sk}]
resp = dynamodb_client.execute_statement(Statement=stmt, Parameters=pmt)
pp.pprint(resp["Items"])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.