Skip to content

Commit f94979f

Browse files
committed
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.
1 parent dc12e47 commit f94979f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/backend/commands/extension.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,12 +1393,16 @@ CreateExtension(CreateExtensionStmt *stmt)
13931393
*/
13941394
List *search_path = fetch_search_path(false);
13951395

1396-
if (search_path == NIL) /* probably can't happen */
1397-
elog(ERROR, "there is no default creation target");
1396+
if (search_path == NIL) /* nothing valid in search_path? */
1397+
ereport(ERROR,
1398+
(errcode(ERRCODE_UNDEFINED_SCHEMA),
1399+
errmsg("no schema has been selected to create in")));
13981400
schemaOid = linitial_oid(search_path);
13991401
schemaName = get_namespace_name(schemaOid);
14001402
if (schemaName == NULL) /* recently-deleted namespace? */
1401-
elog(ERROR, "there is no default creation target");
1403+
ereport(ERROR,
1404+
(errcode(ERRCODE_UNDEFINED_SCHEMA),
1405+
errmsg("no schema has been selected to create in")));
14021406

14031407
list_free(search_path);
14041408
}

0 commit comments

Comments
 (0)