提交 530acda4 编写于 作者: T Tom Lane

Provide better message when CREATE EXTENSION can't find a target schema.

The new message (and SQLSTATE) matches the corresponding error cases in
namespace.c.

This was thought to be a "can't happen" case when extension.c was written,
so we didn't think hard about how to report it.  But it definitely can
happen in 9.2 and later, since we no longer require search_path to contain
any valid schema names.  It's probably also possible in 9.1 if search_path
came from a noninteractive source.  So, back-patch to all releases
containing this code.

Per report from Sean Chittenden, though this isn't exactly his patch.
上级 5c7603c3
...@@ -1394,12 +1394,16 @@ CreateExtension(CreateExtensionStmt *stmt) ...@@ -1394,12 +1394,16 @@ CreateExtension(CreateExtensionStmt *stmt)
*/ */
List *search_path = fetch_search_path(false); List *search_path = fetch_search_path(false);
if (search_path == NIL) /* probably can't happen */ if (search_path == NIL) /* nothing valid in search_path? */
elog(ERROR, "there is no default creation target"); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("no schema has been selected to create in")));
schemaOid = linitial_oid(search_path); schemaOid = linitial_oid(search_path);
schemaName = get_namespace_name(schemaOid); schemaName = get_namespace_name(schemaOid);
if (schemaName == NULL) /* recently-deleted namespace? */ if (schemaName == NULL) /* recently-deleted namespace? */
elog(ERROR, "there is no default creation target"); ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("no schema has been selected to create in")));
list_free(search_path); list_free(search_path);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册