Finding the hash value of a row in postgresql

Arun P Johny picture Arun P Johny · Oct 7, 2010 · Viewed 18.7k times · Source

Is there a way to get the hash code of a row in 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?

Thank you

Answer

Frank Heikens picture Frank Heikens · Oct 7, 2010

Cast the row to text and use md5 to make a hash:

SELECT
    md5(CAST((f.*)AS text))
FROM
    foo f;