简体   繁体   中英

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. 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"])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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