diff --git a/src/gausskernel/optimizer/commands/functioncmds.cpp b/src/gausskernel/optimizer/commands/functioncmds.cpp index d715dcdba..d69de2aa5 100644 --- a/src/gausskernel/optimizer/commands/functioncmds.cpp +++ b/src/gausskernel/optimizer/commands/functioncmds.cpp @@ -1080,6 +1080,13 @@ ObjectAddress CreateFunction(CreateFunctionStmt* stmt, const char* queryString, if (HeapTupleIsValid(tuple)) { Form_gs_package pkgform = (Form_gs_package)GETSTRUCT(tuple); namespaceId = pkgform->pkgnamespace; + if (schemaname != NULL) { + Oid func_namespaceid = get_namespace_oid(schemaname, true); + if (namespaceId != func_namespaceid) { + ereport(ERROR, (errcode(ERRCODE_INVALID_SCHEMA_NAME), + errmsg("The namespace of functions or procedures within a package needs to be consistent with the package it belongs."))); + } + } } else { ereport(ERROR, (errcode(ERRCODE_UNDEFINED_PACKAGE), errmsg("package not found"))); } diff --git a/src/test/regress/expected/hw_package.out b/src/test/regress/expected/hw_package.out index 9315c63cc..4f8fdf738 100644 --- a/src/test/regress/expected/hw_package.out +++ b/src/test/regress/expected/hw_package.out @@ -2745,6 +2745,56 @@ end pck3; / create user package_user password 'gauss@123'; alter package pck3 owner to package_user; +-- test methods schema not consistent with object +create schema multi_schema_001; +-- failed +create or replace package public.multi_shema_package is +var1 int:=1; --公有变量 +var2 int:=2; +procedure multi_schema_001.testpro1(var3 int); --公有存储过程,可以被外部调用 +end multi_shema_package; +/ +ERROR: The namespace of functions or procedures within a package needs to be consistent with the package it belongs. +-- failed +create or replace package multi_schema_001.multi_shema_package is +var1 int:=1; --公有变量 +var2 int:=2; +procedure public.testpro1(var3 int); --公有存储过程,可以被外部调用 +end multi_shema_package; +/ +ERROR: The namespace of functions or procedures within a package needs to be consistent with the package it belongs. +-- succeed +create or replace package multi_schema_001.multi_shema_package is +var1 int:=1; --公有变量 +var2 int:=2; +procedure multi_schema_001.testpro1(var3 int); --公有存储过程,可以被外部调用 +end multi_shema_package; +/ +-- failed +create or replace package body multi_schema_001.multi_shema_package is +var3 int:=3; +var4 int:=4; +procedure public.testpro1(var3 int) +is +begin +end; +end multi_shema_package; +/ +ERROR: The namespace of functions or procedures within a package needs to be consistent with the package it belongs. +-- succeed +create or replace package body multi_schema_001.multi_shema_package is +var3 int:=3; +var4 int:=4; +procedure multi_schema_001.testpro1(var3 int) +is +begin +end; +end multi_shema_package; +/ +-- clean +drop package multi_schema_001.multi_shema_package; +NOTICE: drop cascades to function multi_schema_001.testpro1(integer) +drop schema multi_schema_001; drop package pck1; NOTICE: drop cascades to function pkgsch059.f1(integer,test_tb) drop package pck2; diff --git a/src/test/regress/sql/hw_package.sql b/src/test/regress/sql/hw_package.sql index 34da3c4cf..7dd49bcfe 100644 --- a/src/test/regress/sql/hw_package.sql +++ b/src/test/regress/sql/hw_package.sql @@ -2303,6 +2303,53 @@ end pck3; create user package_user password 'gauss@123'; alter package pck3 owner to package_user; +-- test methods schema not consistent with object +create schema multi_schema_001; +-- failed +create or replace package public.multi_shema_package is +var1 int:=1; --公有变量 +var2 int:=2; +procedure multi_schema_001.testpro1(var3 int); --公有存储过程,可以被外部调用 +end multi_shema_package; +/ +-- failed +create or replace package multi_schema_001.multi_shema_package is +var1 int:=1; --公有变量 +var2 int:=2; +procedure public.testpro1(var3 int); --公有存储过程,可以被外部调用 +end multi_shema_package; +/ +-- succeed +create or replace package multi_schema_001.multi_shema_package is +var1 int:=1; --公有变量 +var2 int:=2; +procedure multi_schema_001.testpro1(var3 int); --公有存储过程,可以被外部调用 +end multi_shema_package; +/ +-- failed +create or replace package body multi_schema_001.multi_shema_package is +var3 int:=3; +var4 int:=4; +procedure public.testpro1(var3 int) +is +begin +end; +end multi_shema_package; +/ +-- succeed +create or replace package body multi_schema_001.multi_shema_package is +var3 int:=3; +var4 int:=4; +procedure multi_schema_001.testpro1(var3 int) +is +begin +end; +end multi_shema_package; +/ +-- clean +drop package multi_schema_001.multi_shema_package; +drop schema multi_schema_001; + drop package pck1; drop package pck2; drop package pck3;