1

I init app_auth database, create extension pgcrypto with app_auth schema, but tests show i create the extension into the public schema, why?

-- init
DROP SCHEMA IF EXISTS app_auth CASCADE;
CREATE SCHEMA app_auth;
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA app_auth;

-- test1: without schema
SET search_path = app_auth;
SELECT gen_random_bytes(10); -- "ERROR: function gen_random_bytes(integer) does not exist"

-- test2: with schema app_auth
SET search_path = app_auth;
SELECT app_auth.gen_random_bytes(10); -- "ERROR: function gen_random_bytes(integer) does not exist"

-- test3: with schema public
SET search_path = app_auth;
SELECT public.gen_random_bytes(10); -- "it works"
3
  • PostgreSQL version 10.0 by elephantsql Commented Jan 16, 2018 at 14:35
  • 2
    Looks like the extension already existed. Try \dx with psql. Commented Jan 16, 2018 at 14:37
  • Thanks, you are right~, I've found the extension already existed in public, is there a safe way to init the database schema app_auth to make the test SELECT app_auth.gen_random_bytes(10); always pass? Commented Jan 16, 2018 at 14:43

1 Answer 1

3

You can move the extension to a different schema:

alter extension pgcrypto set schema app_auth;

is there a safe way to init the database schema app_auth to make the test ... pass?

Another option is to first drop the extension

DROP SCHEMA IF EXISTS app_auth CASCADE;
DROP EXTENSION IF EXISTS pgcrypto;
CREATE SCHEMA app_auth;
CREATE EXTENSION pgcrypto WITH SCHEMA app_auth;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.