条件expression attribute_not_exists()
在数据库上插入项目时,我正在尝试使用条件表达,但是在PutItem()函数运行时,PHP脚本不起作用。
如果他不存在,我想插入物品。
$response = $client->putItem(array(
'TableName' => 'tablename',
'Item' => array(
'serialNumber' => array('S' => 'test123'),
'deviceType' => array('S' => '1')
),
'ConditionExpression' => 'attribute_not_exists(serialNumber)'
));
我试图将$响应var_dump var_dump上面的函数折断。
SerialNumber它的分区密钥,应该按预期工作。
下面的代码正常运行,但他用新值代替了现有项目,这是我不想发生的。
$response = $client->putItem(array(
'TableName' => 'tablename',
'Item' => array(
'serialNumber' => array('S' => 'test123'),
'deviceType' => array('S' => '1')
)
));
I am trying to use ConditionExpression when inserting an item on the database, but it dont work, the php script breaks when the Putitem() function runs.
I want to insert the item if he dont exist.
$response = $client->putItem(array(
'TableName' => 'tablename',
'Item' => array(
'serialNumber' => array('S' => 'test123'),
'deviceType' => array('S' => '1')
),
'ConditionExpression' => 'attribute_not_exists(serialNumber)'
));
I tried to var_dump the $response but the code breaks on the function above.
serialNumber its a Partition Key which should work as intended.
The code below works fine, but he replaces the existing item with new values, which its what i dont want to happen.
$response = $client->putItem(array(
'TableName' => 'tablename',
'Item' => array(
'serialNumber' => array('S' => 'test123'),
'deviceType' => array('S' => '1')
)
));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
预计您将返回
condidtioncheckfailedexception
当您设置为false的条件时。尝试将代码包装在尝试/捕获
块中以查看它是否可以按预期工作?It is expected that you are returned a
CondidtionCheckFailedException
when the condition you set evaluates to false. Try wrapping your code in atry/catch
block to see if it works as expected?