简体   繁体   English

如何在 RedShift 中自动更新更新行的更新日期列?

[英]How to automatically update the updated date column on updating row in RedShift?

I have a table in Redshift which has an UpdatedDate column of type timestamp.我在 Redshift 中有一个表,它有一个时间戳类型的 UpdatedDate 列。 The column is defined as该列定义为

UpdatedDate timestamp DEFAULT getdate()

So when ever a new record is inserted the date is stored correctly in this column.因此,每当插入新记录时,日期都会正确存储在此列中。 The issue is in the update case.问题出在更新案例中。 In update this column is not updated.在更新中,此列未更新。 What I need is for UpdatedDate column to update automatically when the data in the row is changed.我需要的是 UpdatedDate 列在行中的数据更改时自动更新。

I know we can specify the column in the update query, but I do not have control over the query and cannot add the column there.我知道我们可以在更新查询中指定列,但我无法控制查询并且无法在其中添加列。

I tried using Triggers but Redshift does not seem to support them.我尝试使用Triggers ,但 Redshift 似乎不支持它们。 Thanks for your time.谢谢你的时间。 Let me know if any other information is needed.让我知道是否需要任何其他信息。

Create Staging table for this purpose.为此目的创建登台表。 Refer Upsert in Redshift: https://docs.aws.amazon.com/redshift/latest/dg/merge-specify-a-column-list.html请参阅 Redshift 中的 Upsert: https://docs.aws.amazon.com/redshift/latest/dg/merge-specify-a-column-list.html

During update statement, set update_ts = sysdate.在更新语句期间,设置 update_ts = sysdate。

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

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