[英]Using query IndexName, GSI in DynamoDB and not available begins_with in python
我正在關注文檔,我看到“begins_with”可用於 python 3.7,但如果我想使用 GSI“createdAt-index”查詢表,則會出現下一個錯誤。
所以這是不起作用的代碼:
def query_pharmaorders(date):
table = dynamodb.Table('users')
response = table.query(
IndexName="createdAt-index",
KeyConditionExpression=Key('createdAt').begins_with("2020"),
)
return (response['Items'])
這是錯誤:
Response
{
"errorMessage": "Syntax error in module 'lambda_function': invalid syntax (lambda_function.py, line 19)",
"errorType": "Runtime.UserCodeSyntaxError",
"stackTrace": [
" File \"/var/task/lambda_function.py\" Line 19\n \t\tKeyConditionExpression=Key('createdAt').begins_with(\"2020\")\n"
]
}
我的分區鍵是在哪里創建的。
有任何想法嗎?
您沒有說錯誤是什么,但對可能出現的問題有一些想法。
根據查詢操作的文檔
請注意,如果您使用 IndexName 參數,您還必須提供 TableName。
使用query
操作時,需要進行分區鍵相等性測試,必須按以下格式指定:
partitionKeyName =:partitionkeyval
雖然您可以在排序鍵上使用begins_with
條件,但不能使用分區鍵這樣做。 使用query
操作時,您需要指定確切的分區鍵。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.