postgresql 在postgresql中查找行的哈希值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3878499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Finding the hash value of a row in postgresql
提问by Arun P Johny
Is there a way to get the hash code of a row in postgresql?
有没有办法在 postgresql 中获取一行的哈希码?
I need to export some data only if there is some changes in the data after the last export, the last exported data rows can be stored in a table, the when the again I need to export the data I can get the hash values of all the data and export only those rows who has a different hash value than the last export.
我只需要在上次导出后数据有一些变化时才需要导出一些数据,最后导出的数据行可以存储在一个表中,当我再次需要导出数据时我可以得到所有的哈希值数据并仅导出与上次导出具有不同哈希值的那些行。
Is it possible to achieve using postgresql?
是否可以使用 postgresql 实现?
Thank you
谢谢
回答by Frank Heikens
Cast the row to text and use md5 to make a hash:
将行转换为文本并使用 md5 进行散列:
SELECT
md5(CAST((f.*)AS text))
FROM
foo f;
回答by matt b
An alternative approach would be to set an ON INSERT OR UPDATE
triggerwhich would insert the current timestamp into a last_modified
column, and then simply querying based on this column when your import process runs.
另一种方法是设置一个ON INSERT OR UPDATE
触发器,将当前时间戳插入到last_modified
列中,然后在导入过程运行时简单地基于此列进行查询。