We are trying to run this code in Postgres 18.6:
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA pg_catalog CASCADE;
and getting the error
postgres=# CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA pg_catalog CASCADE;
ERROR: function "gen_random_uuid" already exists with same argument types
CONTEXT: SQL statement "CREATE FUNCTION gen_random_uuid()
RETURNS uuid
AS '$libdir/pgcrypto', 'pg_random_uuid'
LANGUAGE C VOLATILE PARALLEL SAFE"
extension script file "pgcrypto--1.3.sql", near line 66
That’s because pgcrypto—1.3.sql has the following 4 lines starting at line 66:
CREATE FUNCTION gen_random_uuid()
RETURNS uuid
AS 'MODULE_PATHNAME', 'pg_random_uuid'
LANGUAGE C VOLATILE PARALLEL SAFE;
which try to create the gen_random_uuid() function but since it already exists it throws an error.
1) Should pgcrytpo—1.3.sql be trying to create gen_random_uuid() if/when it already exists?
The pgcrypto.control file contains:
# pgcrypto extension
comment = 'cryptographic functions'
default_version = '1.4'
module_pathname = '$libdir/pgcrypto'
relocatable = true
trusted = true
2) given what’s in pgcrypto.control should there be a pgcrypto—1.4.sql file?
NOTE: If I comment lines 66-69 in pgcrypto—1.3.sql the
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA pg_catalog CASCADE;
code completes successfully.
I’m hesitant to alter pgcrypto—1.3.sql. Thoughts?
Thanks, Mark