Ho to install SHA-1 support for PostgreSQL

by Wolfram Saringer  (2012-01-17)
last change: 2012-01-17


In the PostgreSQL source directory:
cd contrib/pgcrypto
make; make install

start psql and create a utility function:

psql -Upostgres template1

-- for Postgres < 9.1:
template1=# \i contrib/pgcrypto/pgcrypto.sql
-- for Postgres >= 9.1:
template1=# CREATE EXTENSION pgcrypto;

-- common part:
template1=# CREATE OR REPLACE FUNCTION sha1(varchar) returns text AS '
SELECT encode(digest($1::bytea, ''sha1''), ''hex'')
' LANGUAGE SQL STRICT IMMUTABLE;



all articles represent the sole opinion of their respective author. all content comes without any warranty for correctnes, despite due diligence.