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

Ans*_*tia 5 sql amazon-redshift

我在 Redshift 中有一个表,它有一个时间戳类型的 UpdatedDate 列。该列定义为

UpdatedDate timestamp DEFAULT getdate()
Run Code Online (Sandbox Code Playgroud)

因此,每当插入新记录时,日期都会正确存储在此列中。问题出在更新案例中。在更新中,此列未更新。我需要的是 UpdatedDate 列在行中的数据更改时自动更新。

我知道我们可以在更新查询中指定列,但我无法控制查询并且无法在那里添加列。

我尝试使用Triggers但 Redshift 似乎不支持它们。谢谢你的时间。如果需要任何其他信息,请告诉我。

小智 0

为此目的创建临时表。请参阅 Redshift 中的更新插入: https://docs.aws.amazon.com/redshift/latest/dg/merge-specify-a-column-list.html

在更新语句期间,设置 update_ts = sysdate。