简体   繁体   English

如何更新特定行的aws redshift

[英]How to update specific row of aws redshift

I'm using lambda function to handle update of redshift table row using boto3.我正在使用 lambda function 来处理使用 boto3 的 redshift 表行的更新。 Scenario is frontend will send data via api gateway that includes primary key and complete row that needs to updated in redshift, api gateway initiate lambda for update.场景是前端将通过 api 网关发送数据,其中包括需要在 redshift 中更新的主键和完整行,api 网关启动 lambda 进行更新。 Issue is I'm not able to find a solution using which I can update complete row of matching primary key.问题是我无法找到可以用来更新匹配主键的完整行的解决方案。 as per AWS doc.根据 AWS 文档。 Update command can be used but in Set column I have to pass each attribute and it's value like:可以使用更新命令,但在设置列中我必须传递每个属性,它的值如下:

eg:例如:

Update test_table
Set col1 = "test1", col2 = "test3" ....

as frontend use lots of table I'll not be able to do this way.由于前端使用大量表格,我将无法这样做。

api gateway sample response for lambda: api lambda 的网关示例响应:

'attribute':['col1', 'col2', 'col3', 'col4', ....], 'value':['test1', 'test2', 'test3', 'test4', ....]

Any solution how to do it will be great help.任何解决方案如何做都会有很大的帮助。

Redshift, internally, doesn't update data - it deletes and replaces the row(s). Redshift 在内部不会更新数据 - 它会删除并替换行。 I'd recommend that you just follow this pattern and delete the row based on the PK and then insert the replacement row.我建议您只遵循此模式并删除基于 PK 的行,然后插入替换行。 You will need to do this within a transaction block so no 3rd party can see the row "missing", only old value or new value.您将需要在交易块内执行此操作,因此没有第 3 方可以看到“丢失”的行,只能看到旧值或新值。

Your delete code pattern is consistent as is you insert pattern.您的删除代码模式与插入模式一致。 This should make coding this up in the lambda much simpler.这应该会使 lambda 中的编码变得更加简单。

Also, please remember that Redshift doesn't ensure uniqueness of PKs and that ensuring the PK are unique is up to the user (you or your ETL processes).另外,请记住,Redshift 不能确保 PK 的唯一性,确保 PK 的唯一性取决于用户(您或您的 ETL 流程)。 This has nothing to do with implementing the above solution, it is just a common mistake when using Redshift with PKs.这与实施上述解决方案无关,这只是将 Redshift 与 PK 一起使用时的常见错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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