I know this question is old, but for those who have the same problem.
Step 1: first check if prcrypto is installed or not
select e.extname, n.nspname from pg_catalog.pg_extension e left join pg_catalog.pg_namespace n on n.oid = e.extnamespace;
Step 2: if it is not installed, create an extension
CREATE EXTENSION IF NOT EXISTS pgcrypto;
Step 3: Computes the binary hash of the given data.
CREATE OR REPLACE FUNCTION sha1(bytea) returns text AS $$ SELECT encode(digest($1, 'sha1'), 'hex') $$ LANGUAGE SQL STRICT IMMUTABLE;
Last step:
Also use the encoding function if you want a digest as a hexadecimal string
SELECT encode(digest('blue', 'sha1'), 'hex');
or
directly sha('blue')
Piyush sharma
source share