简体   繁体   English

如何在 AWS 和 boto3 中将 f-Literal 与 PartiQL 一起使用以及排序键的条件

[英]How to use f-Literal with PartiQL in AWS and boto3 and a Condition on the sort key

This is my current Code这是我目前的代码

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'])

But i get this error message:但我收到此错误消息:

NameError: name 'sk' is not defined

Anyone has an idea what could be wrong?任何人都知道什么可能是错的?

Well, 'sk' is not defined.嗯,'sk' 没有定义。 You try like this你这样试试

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM