I need a query that will encode a TEXT column w SHA1. It is not for passwords, but used as a simple changed status check. I truncate at 40chars as it is a loose check.
This query part works in MS SQL SERVER:
RIGHT( CONVERT([varchar](45), HASHBYTES('SHA1', CAST(MY_XML as varchar(max))), 1) ,40) as HASH
A customer needs this to work in PostgreSQL.
I have looked at the ENCODE
, DIGEST
and other functions, but I can't seem to get the proper syntax.
These don't work:
DIGEST(CAST(MY_XML as varchar(max)),'SHA1')::varchar(40) as HASH
CAST(DIGEST(CAST(MY_XML as varchar),'SHA1') as varchar) as HASH
ENCODE(DIGEST(CAST(MY_XML as varchar(max)),'SHA1'),'hex') as HASH
ENCODE(DIGEST(MY_XML::text::bytea, 'sha1'), 'hex') as HASH
(last one sourced from How to calculate the real SHA1 of a text?)
I feel I'm close, but as the saying goes..