PartiQL INSERT语句将值附加到列表属性



我正在尝试使用PartiQL语法将值附加到DynamoDB中现有的列表属性。

该项的主键包含:

pk = userId
sk = happeningId
table_name = test_table
userId = "user09hfh47egd53tgd"
happeningId = "happ09hdg2536dget7354tdg"
contactId = "C0003"
decision = "accept"
if decision == "accept":
stmt = f"UPDATE "{table_name}" SET accept = list_append(accept, :'{contactId}') WHERE pk='{userId}' AND sk='{happeningId}'"
print(stmt)
resp = dynamodb_client.execute_statement( Statement=stmt )
else:
stmt = f"UPDATE "{table_name}" SET cancel = list_append(cancel, :'{contactId}') WHERE pk='{userId}' AND sk='{happeningId}'"
print(stmt)
resp = dynamodb_client.execute_statement( Statement=stmt )

最后的字符串看起来像这样

UPDATE "test_table" SET accept = list_append(accept, :'C0003') WHERE pk='user09hfh47egd53tgd' AND sk='happ09hdg2536dget7354tdg'

当我尝试运行我的代码时,我得到以下错误消息:

ClientError: An error occurred (ValidationException) when calling the ExecuteStatement operation: Statement wasn't well formed, can't be processed: Unexpected term

谁知道我做错了什么?

试着这样写你的语句:

contactId = ["C0003"]

stmt = f"UPDATE "{table_name}" SET accept = list_append(accept, {contactId}) WHERE pk='{userId}' AND sk='{happeningId}'"

解释:你想要附加到列表的值,也需要以列表类型出现。此外,双点不是必需的,'{contactId}'中的引号需要删除,因为它们将插入的值转换为字符串。就像我说的,Value也需要和List Type一样

希望对你有帮助。

相关内容

  • 没有找到相关文章

最新更新