【发布时间】:2018-06-25 07:00:08
【问题描述】:
我初始化 app_auth 数据库,使用 app_auth 架构创建扩展 pgcrypto,但测试显示我在公共架构中创建了扩展,为什么?
-- 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"
【问题讨论】:
-
PostgreSQL 10.0 版,由大象sql 提供
-
看起来扩展已经存在。用 psql 试试
\dx。 -
谢谢,你是对的~,我发现这个扩展已经公开存在了,有没有一种安全的方法来初始化数据库架构
app_auth,让测试SELECT app_auth.gen_random_bytes(10);总是通过?
标签: sql postgresql schema