Will schema-prefixing a stored procedure also limit the scope of all the procedures called inside it to that schema?
Take the following scenerio in consideration:
Say I have a stored procedure parentProc
that calls proc childA
childB
and childC
. This procedure is available in all schemas SchemaA
, public
and SchemaB
like this:
create or replace procedure parentProc(){
CALL childA;
CALL childB;
CALL childC;
}
SchemaA
|_parentProc
|_childA
|_childB
|_ChildC
SchemaB
|_parentProc
|_childA
|_childB
|_ChildC
public
|_parentProc
|_childA
|_childB
|_ChildC
the default search path is public, so when I call dbo.parentProc
will the procedure in the same schema(dbo) be called or from the public
?
If childA, childB and childC are views instead, what will happen in that scenerio? Will the parentproc being prefixed scope the views to that schema?
2
Answers
From the manual:
That means that any call to a procedure without a schema qualification, will only find (or not) the procedure that is in the public schema. Because public is in your default search path.
I always use just public for the default, the rest is using a schema qualification.
If you reference one object using the schema, that doesn’t change the fact that all unqualified references use the
search_path
to determine the schema. So if youbut
search_path
isschemab
, the procedure will still call the procedures fromschemab
.The same holds for views or all other objects, but note that the objects referenced inside a view do not depend on the setting of
search_path
when the view is used, but on the setting ofsearch_path
when the view was defined. That is because the defining query is parsed at view creation time and stored in parsed form.